Codeforces Round #332 (Div. 2)

颓得不行,于是没打,第二天早上爬起来码代码

  • A
 1 #include<stdio.h>
 2 #include<algorithm>
 3 using namespace std;
 4 int main(){
 5     int a,b,c;
 6     scanf("%d%d%d",&a,&b,&c);
 7     int q=a+b+c;
 8     int w=(min(a,b)+c)*2;
 9     int e=(a+b)*2;
10     printf("%d\n",min(q,min(w,e)));
11     return 0;
12 }
View Code
  • B
 1 #include<stdio.h>
 2 #define maxn 100005
 3 int n,m,f[maxn],b[maxn],Map[maxn],tong[maxn],a[maxn];
 4 int main(){
 5     scanf("%d%d",&n,&m);
 6     for(int i=1;i<=n;i++){
 7         scanf("%d",&f[i]);
 8         Map[f[i]]=i;
 9         tong[f[i]]++;    
10     }
11     bool amb=false,imp=false;
12     for(int i=1;i<=m;i++){
13         scanf("%d",&b[i]);
14         if(!tong[b[i]])imp=true;
15         if(tong[b[i]]>1)amb=true;
16         a[i]=Map[b[i]];
17     }
18     if(!imp&&!amb){
19         printf("Possible\n");
20         for(int i=1;i<=m;i++)
21             printf("%d ",a[i]);
22         printf("\n");
23     }
24     else if(imp)printf("Impossible\n");
25     else printf("Ambiguity\n");
26     return 0;
27 }
View Code
  • C
 1 #include<stdio.h>
 2 #include<algorithm>
 3 using namespace std;
 4 
 5 #define maxn 100005
 6 int n,yooo[maxn],Maxyooo[maxn],Minyooo[maxn];
 7 
 8 int main(){
 9     //freopen("1.in","r",stdin);
10     scanf("%d",&n);
11     for(int i=1;i<=n;i++){
12         scanf("%d",&yooo[i]);
13         Maxyooo[i]=max(Maxyooo[i-1],yooo[i]);
14     }
15     Minyooo[n-1]=yooo[n];
16     for(int i=n-2;i>=1;i--)
17         Minyooo[i]=min(Minyooo[i+1],yooo[i+1]);
18     int ans=1;
19     for(int i=1;i<=n;i++)
20         if(Maxyooo[i]<=Minyooo[i])ans++;
21     printf("%d\n",ans);
22     return 0;
23 }
View Code

前三题做完发现,打cf还是不要想太多,因为每次只有前【两个】想法是对的。。。

  • D
 1 #include<stdio.h>
 2 #include<algorithm>
 3 using namespace std;
 4 
 5 typedef long long i64;
 6 #define fir first
 7 #define sec second
 8 #define mp make_pair
 9 #define maxn 1000005
10 i64 x,squ,res,cnt;
11 pair<i64,i64>ans[maxn];
12 int main(){
13     //freopen("1.in","r",stdin);
14     scanf("%I64d",&x);
15     for(i64 n=1;squ=n*(n+1)*(2*n+1)/6,squ<=x;n++){
16         i64 res=n*(n+1)/2;
17         if((x-squ)%res==0)ans[++cnt]=mp(n,n+(x-squ)/res);
18     }
19     bool flag=false;
20     if(ans[cnt].fir==ans[cnt].sec)flag=true;
21     printf("%I64d\n",flag?cnt*2-1:cnt*2);
22     for(i64 i=1;i<=cnt;i++)
23         printf("%I64d %I64d\n",ans[i].fir,ans[i].sec);
24     for(i64 i=cnt;i>=1;i--){
25         if(flag&&i==cnt)continue;
26         else printf("%I64d %I64d\n",ans[i].sec,ans[i].fir);
27     }
28     return 0;
29 }
View Code

略美,然而并不知道1^2+2^2+...+n^2=n*(n+1)*(2*n+1)/6,在这里跪谢wh大爷

  • E South Africa  
posted @ 2015-11-21 16:48  Ngshily  阅读(147)  评论(0编辑  收藏  举报