#include<iostream>#include<set>#include<utility>#include<algorithm>#include<algorithm>#include<vector>usingnamespace std;constint MAX =1010;int n;int a[MAX];int b[MAX];intmain(){scanf("%d",&n);for(int i =1; i <=n; i++)scanf("%d",&a[i]);
b[1]=(a[1]+ a[2])/2;
b[n]=(a[n-1]+ a[n])/2;printf("%d",b[1]);for(int i =2; i <=n-1; i++){
b[i]=(a[i-1]+a[i]+a[i+1])/3;printf(" %d",b[i]);}printf(" %d",b[n]);return0;}
#include<iostream>#include<set>#include<utility>#include<algorithm>#include<algorithm>#include<vector>usingnamespace std;constint MAX =1000010;int n;int a,b;int record[MAX];int sum =0;intmain(){scanf("%d",&n);for(int i =1; i <=2*n;i++){scanf("%d%d",&a,&b);for(int j = a;j < b ; j++){
record[j]++;}}for(int i =1;i <= MAX-1;i++){if(record[i]==2) sum++;}printf("%d",sum);return0;}
小明放学 (一开始只有60分,把sum类型改成long long即得到100分)
#include<iostream>#include<set>#include<utility>#include<algorithm>#include<algorithm>#include<vector>usingnamespace std;constint MAX =100010;int n;int r,y,g;int rec;int k,t;longlong sum=0;int temp;intmain(){scanf("%d%d%d",&r,&y,&g);scanf("%d",&n);
rec = r + y + g;for(int i =1; i <= n;i++){scanf("%d%d",&k,&t);
temp = sum % rec;switch(k){case0:
sum+=t;break;case1:if(temp <= t) sum += t - temp;else{if(temp > t && temp <= t + g) sum = sum;elseif(temp > t + g && temp <= t + g +y)
sum += t + g +y - temp + r;else
sum += r -(temp -(t+g+y));}break;case2:if(temp <= t) sum += t - temp + r ;else{if(temp > t && temp <= t + r) sum += t + r - temp;elseif(temp > t + r && temp <= t + r +g)
sum = sum;else
sum += y -(temp -(t+r+g))+ r;}break;case3:if(temp <= t) sum = sum;else{if(temp > t && temp <= t + y) sum += t + y - temp + r;elseif(temp > t + y && temp <= t + y + r)
sum += t + y + r - temp;else
sum = sum ;}break;}}printf("%lld",sum);return0;}