CF1408F Two Different
題面傳送門
一道好題。
首先有一個操作:如果有
n
n
n個
a
a
a,
n
n
n個
b
b
b,那麼可以通過
n
n
n次變成
2
n
2n
2n個
c
c
c
那麼考慮倍增,每次選取兩塊拿來合併。
然後對於前一部分和後一部分分別倍增就好了。
程式碼實現:
#include<cstdio>
using namespace std;
int n,m,k,z,a[100039],s,head,x[1000039],y[1000039];
int main(){
// freopen("1.in","r",stdin);
register int i,j;
scanf("%d",&n);
for(i=0;i<=30;i++) if(n<=(1<<i)) {k=i;break;}
k--;
for(i=1;i<=k;i++){
for(j=1;j<=(1<<k);j++) if(!((j-1)&(1<<i-1))) x[++head]=j,y[head]=j+(1<<i-1);
}
for(i=1;i<=k;i++){
for(j=1;j<=(1<<k);j++) if(!((j-1)&(1<<i-1))) x[++head]=n-j+1,y[head]=n-j+1-(1<<i-1);
}
printf("%d\n",head);
for(i=1;i<=head;i++) printf("%d %d\n",x[i],y[i]);
}
相關文章
- 11.23 Two Different Worlds
- 3.5 Different
- different random numbers generatorrandom
- 2.3.3.3.2 Applications at Different VersionsAPP
- coca after two months vs in two months
- Script of Narrative Writing from different point of viewView
- [20190706]Same dog, different leash – functions in SQL.txtFunctionSQL
- Two Pirates - 2
- Two Pointer Method
- [ERROR] InnoDB: ibdata1 different size (rounded down to MB)Error
- LeetCode | 1 Two SumLeetCode
- Tokitsukaze and Two Colorful Tapes
- F - Two Sequence Queries
- Merge Two Sorted List
- Leetcode 231 Power of TwoLeetCode
- Leetcode 1 two sumLeetCode
- 手把手教你做閱讀理解題-初中中考閱讀理解解題技巧009-There are many different parts that have different jobs
- No way to dispatch this command to Redis Cluster because keys have different slots.Redis
- The Network Program Log Two (Scapy)
- LeetCode | 349 Intersection Of Two ArraysLeetCode
- H-Two Convex PolygonsGo
- B. Two Out of Three
- Study for Go ! Chapter two - ExpressionGoAPTExpress
- LeetCode-1 Two SumLeetCode
- Two useful scenarios of git stashiOSGit
- Compare two or more repo directories
- E. Two Round Dances
- python: leetcode - 1 Two SumPythonLeetCode
- Leetcode 231. Power of TwoLeetCode
- Leetcode 29 Divide Two IntegersLeetCodeIDE
- TWO NODES(HDU-4587)
- [LeetCode]1.Two SumLeetCode
- LeetCode 2 Add Two NumbersLeetCode
- [ARC177F] Two AirlinesAI
- C#的筆記~TWOC#筆記
- 【Leetcode】1029. Two City SchedulingLeetCode
- Systematic index design consists of two processesIndex
- CodeForces 1417B Two Arrays