您的位置:首页 > 其它

BZOJ4725: [POI2017]Reprezentacje ró?nicowe

2018-05-24 21:55 183 查看

1 #include<stdio.h>
2 #include<string.h>
3 //#include<iostream>
4 #include<algorithm>
5 using namespace std;
6
7 #define LL long long
8 int qread()
9 {
10     char c; int s=0,t=1; while ((c=getchar())<'0' || c>'9') (c=='-') && (t=-1);
11     do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*t;
12 }
13
14 //
15
16 int tot;
17 #define maxn 233333
18 int a[maxn];
19 struct Node
20 {
21     int x,y,v;
22     bool operator < (const Node &b) const {return v<b.v;}
23 }b[maxn]; int lb;
24
25 int main()
26 {
27     int Max=1100000000,n=2;
28     a[1]=1; a[2]=2;
29     b[++lb]=(Node){2,1,1};
30     for (n=3;;n++)
31     {
32         if (n&1) a
=a[n-1]<<1; else
33         {
34             for (int k=2;k<=lb;k++) if (b[k].v!=b[k-1].v+1) {a
=b[k-1].v+1; break;}
35             if (!a
) a
=b[lb].v+1;
36             a
+=a[n-1];
37         }
38         for (int i=1;i<n;i++) b[++lb]=(Node){n,i,a
-a[i]};
39         sort(b+1,b+1+lb);
40         if (a
>Max) break;
41     }
42     int m=qread();
43     while (m--)
44     {
45         int x=qread(),y;
46         if (b[y=lower_bound(b+1,b+1+lb,(Node){0,0,x})-b].v==x) printf("%d %d\n",b[y].x,b[y].y);
47         else
48         {
49             int p=x-(y-1);
50             printf("%d %d\n",n+p*2-1,n+p*2-2);
51         }
52     }
53     return 0;
54 }
View Code  

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: