Codeforces Beta Round #12 (Div 2 Only)

点击打开链接

A

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

char str[3][3];

bool isOk(){
    for(int i = 0 ; i < 3 ; i++){
       for(int j = 0 ; j < 3 ; j++){
          if(str[i][j] != str[2-i][2-j])
             return false;
       }
    }
    return true;
}

int main(){
    while(gets(str[0])){
        for(int i = 1 ; i < 3 ; i++)
           gets(str[i]);
        printf("%s\n" , isOk() ? "YES" : "NO");
    }
    return 0;
}

B

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    const int MAXN = 1000;
    bool ans;
    char nStr[MAXN] , mStr[MAXN];
    while(gets(nStr)){
        gets(mStr);
        int len = strlen(nStr);
        sort(nStr , nStr+len);
        int pos = 0;
        for(int i = 0 ; i < len ; i++){
           if(nStr[i] != '0'){
              pos = i;
              break;
           }
        }
        swap(nStr[pos] , nStr[0]);
        printf("%s\n" , !strcmp(nStr , mStr) ? "OK" : "WRONG_ANSWER");
    }
    return 0;
}

C

#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 110;
map<string , int>mp;
int n , m , pos , num[N] , price[N];

bool cmp(int a , int b){
    return a > b;
}

int main(){
    char str[N];
    while(scanf("%d%d" , &n , &m) != EOF){
         for(int i = 0 ; i < n ; i++)
             scanf("%d" , &price[i]);
         mp.clear();
         pos = 1;
         for(int i = 0 ; i < m ; i++){
             scanf("%s" , str);
             if(!mp[str])
                mp[str] = pos++;
             num[mp[str]]++;
         }
         sort(price , price+n);
         sort(num+1 , num+1+pos , cmp);

         int minPrice , maxPrice;
         minPrice = maxPrice = 0;
         int k = 0;
         for(int i = 1 ; i <= pos ; i++)
             minPrice += price[k++]*num[i];
         k = n-1;
         for(int i = 1 ; i <= pos ; i++)
             maxPrice += price[k--]*num[i];
         printf("%d %d\n" , minPrice , maxPrice);
    }
    return 0;
}

E

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int MAXN = 1010;
int mat[MAXN][MAXN];

int main(){
    int n;
    while(scanf("%d" , &n) != EOF){
         memset(mat , 0 , sizeof(mat));
         for(int i  = 0 ; i < n-1 ; i++){
             for(int j = 0 ; j < n-1 ; j++)
                 mat[i][j] = (i+j)%(n-1)+1;
         }
         //替换
         for(int i = 0 ; i < n ; i++){
             mat[i][n-1] = mat[i][i];
             mat[n-1][i] = mat[i][i];
             mat[i][i] = 0;
         }
         //输出
         for(int i = 0 ; i < n ; i++){
             printf("%d" , mat[i][0]);
             for(int j = 1 ; j < n ; j++)
                 printf(" %d" , mat[i][j]);
             printf("\n");
         }
    }
    return 0;
}
时间: 2024-10-24 22:27:31

Codeforces Beta Round #12 (Div 2 Only)的相关文章

Codeforces Beta Round #9 (Div. 2 Only)

点击打开链接cf#9 A 思路:求gcd然后化简 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int gcd(int a ,int b){ return b == 0 ? a : gcd(b , a%b); } int main(){ int a , b; while(scanf("%d%d"

Codeforces Beta Round #6 (Div. 2 Only)

点击打开链接 A #include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int l[4]; int main(){ while(scanf("%d%d%d%d" , &l[0] , &l[1] , &l[2] , &l[3])

Codeforces Beta Round #4 (Div. 2 Only)

点击打开链接 A #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; int main(){ int n; while(scanf("%d" , &n) != EOF){ if(n < 4) printf("NO\n"); else{ if(n%2 == 0) prin

Codeforces Beta Round #10

点击打开链接cf#10 A 思路:模拟 分析: 1 题目要求找到总共的电脑的消耗.题目明确指出在n个时间段之内电脑都是属于第一种状态,并且如果不是第一种状态只要移动鼠标或按键盘马上变为第一种状态. 2 题目还指出每一组输入都保证L<R,并且Ri-1<Li.那么我们只要每输入一个就处理一个即可. 代码: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>

Codeforces Beta Round #11

点击打开链接 A #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int MAXN = 2010; int n , d; int num[MAXN]; int main(){ while(scanf("%d%d" , &n , &d) != EOF){ for(int i

Codeforces Beta Round #8

点击打开链接 A 思路:正反字符串各自判断一次是否有对应的两个子串 分析: 1 题目给定一个字符串str,然后给定两个不同时间段内看到的子串s1 , s2,判断是哪一种情况. 2 我们知道两个时间段内那么看到的字符串是有间隔的,那么如果我们怎么知道是否是"向前""向后""都有""没有"这四种答案中的哪一种呢?其实我们知道如果给定的两个子串都是给定的字符串str的子串,那么我们就必须正反都判断是否都能按照顺序看到s1 和 s2.

Codeforces Beta Round #3

点击打开链接 A #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<map> using namespace std; #define MAXN 500010 #define N 10 int ans , end; int sx , sy , ex , ey; int vis[N][N]; int dir[8][2] = {{0,1

Codeforces Beta Round #7

点击打开链接 A #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 8 char G[N][N]; int main(){ while(scanf("%s" , G[0]) != EOF){ for(int i = 1 ; i < 8 ; i++) scanf("%

Codeforces Beta Round #1

点击打开链接 A #include<iostream> #include<cstdio> using namespace std; long long n , m , a; int main(){ long long sum; while(cin>>n>>m>>a){ long long x , y; x = n%a == 0 ? n/a : n/a+1; y = m%a == 0 ? m/a : m/a+1; sum = x*y; cout&l