Codeforces Round #262 (Div. 2)

A

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 100000
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 int n,m;
18 int main()
19 {
20     int n,m,i,j;
21     cin>>n>>m;
22     if(m>n)
23     cout<<n<<endl;
24     else
25     {
26         int o = 0;
27         while(n)
28         {
29             n--;
30             o++;
31             if(o%m==0) n++;
32         }
33         cout<<o<<endl;
34     }
35     return 0;
36 }
View Code

B

枚举和值

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 100000
12 #define LL long long
13 #define INF 0xfffffff
14 #define M 1000000000
15 const double eps = 1e-8;
16 const double pi = acos(-1.0);
17 const double inf = ~0u>>2;
18 int o[N];
19 int judge(LL x)
20 {
21     int ans = 0;
22     while(x)
23     {
24         ans+=x%10;
25         x/=10;
26     }
27     return ans;
28 }
29 int main()
30 {
31     int a,b,c,i,j;
32     cin>>a>>b>>c;
33     int g = 0;
34     for(i = 1; i <= 100 ; i++)
35     {
36         LL k = (LL)b*pow(i*1.0,a)+c;
37         if(judge(k)==i&&k>0&&k<M)
38         o[++g] = k;
39     }
40     cout<<g<<endl;
41     if(g)
42     {
43 
44 
45     sort(o+1,o+g+1);
46     for(i = 1; i < g ; i ++)
47     cout<<o[i]<<" ";
48     cout<<o[i]<<endl;
49     }
50     return 0;
51 }
View Code

C

二分高度,之后用高度减去原有高度,就可以知道每株花被浇了多少水,用线段树维护一下就可以得到最少浇水的次数。

  1 #include <iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<stdlib.h>
  6 #include<vector>
  7 #include<cmath>
  8 #include<queue>
  9 #include<set>
 10 using namespace std;
 11 #define N 100010
 12 #define LL long long
 13 #define INF 0xfffffff
 14 #define M 1000200000
 15 const double eps = 1e-8;
 16 const double pi = acos(-1.0);
 17 const double inf = ~0u>>2;
 18 int a[N],o[N];
 19 LL s[N<<2];
 20 int n,m,w;
 21 void build(int l,int r,int w)
 22 {
 23     s[w] = 0;
 24     if(l==r)
 25     {
 26         s[w] = o[l];
 27         return ;
 28     }
 29     int m = (l+r)>>1;
 30     build(l,m,w<<1);
 31     build(m+1,r,w<<1|1);
 32 }
 33 void down(int w,int m)
 34 {
 35     if(s[w])
 36     {
 37         s[w<<1] += s[w];
 38         s[w<<1|1] += s[w];
 39         s[w] = 0;
 40     }
 41 }
 42 void update(int a,int b,int d,int l,int r,int w)
 43 {
 44     if(a<=l&&b>=r)
 45     {
 46         s[w]+=d;
 47         return ;
 48     }
 49     down(w,r-l+1);
 50     int m = (l+r)>>1;
 51     if(a<=m) update(a,b,d,l,m,w<<1);
 52     if(b>m) update(a,b,d,m+1,r,w<<1|1);
 53 }
 54 LL query(int p,int l,int r,int w)
 55 {
 56     if(l==r)
 57         return s[w];
 58     down(w,r-l+1);
 59     int m = (l+r)>>1;
 60     if(p<=m) return query(p,l,m,w<<1);
 61     else return query(p,m+1,r,w<<1|1);
 62 }
 63 int cal(int k)
 64 {
 65     int i,j;
 66     for(i = 1; i <= n; i++)
 67         if(k>a[i]) o[i] = k-a[i];
 68         else o[i] = 0;
 69     build(1,n,1);
 70     LL num = 0;
 71     for(i = 1; i <= n; i++)
 72     {
 73         int pp = query(i,1,n,1);
 74         
 75        
 76         if(pp>0) {update(i,min(n,i+w-1),-pp,1,n,1);num+=pp;} if(num>m) return 0;
 77     }
 78     if(num<=m) return 1;
 79     return 0;
 80 }
 81 int main()
 82 {
 83     int i,j;
 84     cin>>n>>m>>w;
 85     for(i = 1; i <= n; i++)
 86         scanf("%d",&a[i]);
 87     int low = 1,high = M,mid;
 88     int ans = 1;
 89     while(low<=high)
 90     {
 91         mid = (low+high)>>1;
 92         if(cal(mid)==0)
 93             high = mid-1;
 94         else
 95         {
 96             low = mid+1;
 97             ans = max(ans,mid);
 98         }
 99     }
100     cout<<ans<<endl;
101     return 0;
102 }
View Code

D

对于

k=1 ,ans = L。

连续偶奇异或是为1的 比如10 11    12 13等 ,而奇偶则是不一定的

k= 2, 如果l%2==0,ans = L^(L+1)=1 ,否则要根据R-L+1的取值决定

k= 4 ,如果L%2=0,ans = L^(L+1)^(L+2)^(L+3)  = 0,否则如果R-L+1>4 也是为偶奇偶奇=0的,若R-L+1=4 就可转化为3的时候做。

k=3 ,有可能为1也有可能为0 ,假设L-R范围内的三个数x,y,z异或为0,x,y,z不同,就设x>y>z,那么x,y已确定,那么就是尽可能让z大,

比如 

x  100110001111   那么y值的第一位一定为1,不然z就为1就不符合假设y>z了,因为y<x,所以之后遇到x为0的位,y,z也是为0的,一旦再遇到一位1,就可以把y置为0,z置为1,再之后z就可以一直为1,而y的变化可以依据x,z而定。

x  100110001111...1

y  100001110000...0

z  000111111111...1

这样z将获得<R的最大值,再与L相比较就可以知道结果了。

  1 #include <iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<stdlib.h>
  6 #include<vector>
  7 #include<cmath>
  8 #include<queue>
  9 #include<set>
 10 using namespace std;
 11 #define N 100000
 12 #define LL long long
 13 #define INF 0xfffffff
 14 const double eps = 1e-8;
 15 const double pi = acos(-1.0);
 16 const double inf = ~0u>>2;
 17 LL a[10];
 18 int di[50];
 19 void judge(LL l,LL r)
 20 {
 21     LL x = r;
 22     LL i;
 23     int g = 0;
 24     while(x)
 25     {
 26         di[g++] = x%2;
 27         x/=2;
 28     }
 29     LL y = 0;
 30     LL z = 0;
 31     int flag = 0;
 32     y+=((LL)1<<(g-1));
 33     for(i = g-2 ; i >= 0 ; i--)
 34     {
 35         if(di[i])
 36         {
 37             flag = 1;
 38             z += ((LL)1<<i);
 39         }
 40         else if(flag)
 41         {
 42             z+=((LL)1<<i);
 43             y+=((LL)1<<i);
 44         }
 45     }
 46     if(z>=l)
 47     {
 48         cout<<"0
";
 49         cout<<"3
";
 50         cout<<r<<" "<<y<<" "<<z<<endl;
 51     }
 52     else
 53     {
 54         cout<<"1
";
 55         cout<<"2
";
 56         if(l%2)
 57         cout<<l+1<<" "<<l+2<<endl;
 58         else
 59         cout<<l<<" "<<l+1<<endl;
 60     }
 61 }
 62 int main()
 63 {
 64     LL l,r,i,k;
 65     cin>>l>>r>>k;
 66     if(r==l)
 67     {
 68         cout<<l<<endl;
 69         cout<<"1
";
 70         cout<<l<<endl;
 71         return 0;
 72     }
 73     if(l%2==0)
 74     {
 75         if(r-l+1==2||k<=2)
 76         {
 77             if(k==1)
 78             {
 79                 cout<<l<<endl;
 80                 cout<<"1
";
 81                 cout<<l<<endl;
 82             }
 83             else
 84             {
 85                 cout<<"1
";
 86                 cout<<"2
";
 87                 cout<<l<<" "<<l+1<<endl;
 88             }
 89         }
 90         else if(r-l+1==3||k==3)
 91         {
 92             judge(l,r);
 93         }
 94         else
 95         {
 96             cout<<"0
";
 97             cout<<"4
";
 98             for(i = l  ; i < l + 4 ; i++)
 99                 cout<<i<<" ";
100             puts("");
101         }
102     }
103     else
104     {
105         if(r-l+1==2||k<=2)
106         {
107             if(k==1||(r-l+1==2&&(l^(l+1))>l))
108             {
109                 cout<<l<<endl;
110                 cout<<"1
";
111                 cout<<l<<endl;
112             }
113             else
114             {
115                 if(r-l+1==2)
116                 {
117                     cout<<(l^(l+1))<<endl;
118                     cout<<"2
";
119                     cout<<l<<" "<<l+1<<endl;
120                 }
121                 else
122                 {
123                     cout<<"1
";
124                     cout<<"2
";
125                     cout<<l+1<<" "<<l+2<<endl;
126                 }
127             }
128         }
129         else if(r-l+1==3||k==3)
130         {
131             judge(l,r);
132         }
133         else if(r-l+1==4)
134         {
135             int flag = 0;
136             judge(l,r);
137         }
138         else
139         {
140             cout<<"0
";
141             cout<<"4
";
142             for(i = l+1 ; i < l+5 ; i++)
143                 cout<<i<<" ";
144             puts("");
145         }
146 
147     }
148     return 0;
149 }
View Code
原文地址:https://www.cnblogs.com/shangyu/p/3929364.html