标签:最大 .com ble 一个人 uri lin ges 技术分享 puts
2.6
Problem A Quasi Binary
题意:给出 n ,输出n至少由k个只含 01的数组成
简析:按照 n 的位数如果相应的一位不是0的话,就填 1 ,再减去,直到减到 n 为0
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 8 int n; 9 int b[1005],a[15],pm[10]; 10 11 void solve(){ 12 pm[0]=1; 13 for(int i = 1;i <= 7;i++) pm[i] = pm[i-1]*10; 14 int x = n; 15 vector<int> res; 16 while(n){ 17 int c = 0,l = 0; 18 while(x){ 19 int tmp = x%10; 20 x = x/10; 21 // printf("x = %d tmp = %d\n",x,tmp); 22 if(tmp){ 23 l += pm[c]; 24 // printf("--l = %d\n",l); 25 } 26 c++; 27 } 28 // printf("l = %d\n",l); 29 res.push_back(l); 30 n -= l; 31 x = n; 32 } 33 printf("%d\n",res.size()); 34 for(int i = 0;i < res.size();i++) printf("%d ",res[i]); 35 printf("\n"); 36 } 37 38 int main(){ 39 while(scanf("%d",&n) != EOF){ 40 solve(); 41 } 42 return 0; 43 }
Problem B Tourist‘s Notes
题意:一个人登山 n 天,给出 m 天的di,hi (表示在第di天登山的高度为hi),且 abs(h[i]-h[i-1]) <= 1,问这n天登山的最高高度
简析:假设第 di天的登山高度 为 x,di+1天的登山高度 为 y,这两个日期的时间间隔为 day,假设这两个日期之间能够到达的最大高度为 maxx
如果 x == y,
(maxx-x) + (maxx-x) = day
所以 maxx = day/2+x
如果 x > y 或者 x < y
(maxx-x)+(maxx-y) = day
所以 maxx = (day+x+y)/2
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 8 const int maxn = 5e5+5; 9 int n,m; 10 11 struct node{ 12 int d,h; 13 }a[maxn]; 14 15 void solve(){ 16 int maxx = -1; 17 for(int i = 1;i <= m+1;i++){ 18 if(i == 1){ 19 maxx = max(a[i].h+(a[i].d-1),maxx); 20 continue; 21 } 22 if(i == m+1){ 23 maxx = max(a[i-1].h+(n-a[i-1].d),maxx); 24 continue; 25 } 26 int x = a[i].h,y = a[i-1].h; 27 int day = a[i].d-a[i-1].d; 28 if(x == y){ 29 maxx = max(max(x,maxx),day/2+x); 30 continue; 31 } 32 if(abs(x-y) > day){ 33 puts("IMPOSSIBLE"); 34 return; 35 } 36 maxx = max(max(x,y),maxx); 37 maxx = max(maxx,(day+x+y)/2); 38 } 39 printf("%d\n",maxx); 40 } 41 42 int main(){ 43 while(scanf("%d %d",&n,&m) != EOF){ 44 for(int i = 1;i <= m;i++) scanf("%d %d",&a[i].d,&a[i].h); 45 solve(); 46 } 47 return 0; 48 }
标签:最大 .com ble 一个人 uri lin ges 技术分享 puts
原文地址:http://www.cnblogs.com/chdacm/p/6372921.html