Codeforces Round #263 (Div. 2)

A. Appleman and Easy Task http://codeforces.com/contest/462/problem/A

 1 #include<cstdio>
 2 const int M=128;
 3 char a[M][M];
 4 int dx[]={0,0,1,-1};
 5 int dy[]={1,-1,0,0};
 6 int main(){
 7     int n;
 8     while(~scanf("%d",&n)){
 9         for(int i=0;i<n;i++){
10             scanf("%s",a[i]);
11         }
12         bool flag=true;
13         for(int i=0;i<n;i++){
14             for(int j=0;j<n;j++){
15                 int sum=0;
16                 for(int k=0;k<4;k++){
17                     int tx=i+dx[k];
18                     int ty=j+dy[k];
19                     if(tx>=0&&tx<n&&ty>=0&&ty<n){
20                         if(a[tx][ty]=='o') sum++;
21                     }
22                 }
23                 if(sum&1){
24                     flag=false;
25                     break;
26                 }
27             }
28             if(!flag) break;
29         }
30         if(flag){
31             puts("YES");
32         }
33         else{
34             puts("NO");
35         }
36     }
37     return 0;
38 }
View Code

B. Appleman and Card Game http://codeforces.com/contest/462/problem/B

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define mt(a,b) memset(a,b,sizeof(a))
 5 using namespace std;
 6 typedef __int64 LL;
 7 const int M=100010;
 8 LL val[32];
 9 char a[M];
10 int main(){
11     int n,k;
12     while(~scanf("%d%d%s",&n,&k,a)){
13         mt(val,0);
14         for(int i=0;a[i];i++){
15             val[a[i]-'A']++;
16         }
17         sort(val,val+26);
18         LL ans=0;
19         for(int i=25;i>=0;i--){
20             if(k>=val[i]){
21                 ans+=(LL)val[i]*val[i];
22                 k-=val[i];
23             }
24             else{
25                 ans+=(LL)k*k;
26                 break;
27             }
28         }
29         printf("%I64d
",ans);
30     }
31     return 0;
32 }
View Code

C. Appleman and Toastman http://codeforces.com/contest/462/problem/C

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 typedef __int64 LL;
 5 const int M=300010;
 6 int a[M];
 7 int main(){
 8     int n;
 9     while(~scanf("%d",&n)){
10         LL ans=0;
11         for(int i=0;i<n;i++){
12             scanf("%d",&a[i]);
13             ans+=a[i];
14         }
15         sort(a,a+n);
16         for(int i=0;i<n-1;i++){
17             ans+=(LL)(i+1)*a[i];
18         }
19         ans+=(LL)(n-1)*a[n-1];
20         printf("%I64d
",ans);
21     }
22     return 0;
23 }
View Code
原文地址:https://www.cnblogs.com/gaolzzxin/p/3938849.html