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("%s", G[i]);
     int ans , i , j;
     ans = 0;
     for(i = 0 ; i < 8 ; i++){
        for(j = 0 ; j < 8 ; j++){
           if(G[i][j] == 'W')
              break;
        }
        if(j == 8)
          ans++;
        for(j = 0 ; j < 8 ; j++){
          if(G[j][i] == 'W')
            break;
        }
        if(j == 8)
          ans++;
     }
     printf("%d\n" , ans == 16 ? 8 : ans);
  }
  return 0;
}

B

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

#define MAXN 110

int t , m , pos;
int vis[MAXN];
int mark[MAXN];

bool judge(int x){
   int i , j;
   for(i = 1 ; i <= m ; i++){
     if(!vis[i]){
       for(j = i ; j < i+x && j <= m ; j++){
          if(vis[j])
            break;
       }
       if(j == i+x){
         for(j = i ; j < i+x ; j++)
            vis[j] = pos;
         return true;
       }
     }
  }
  return false;
}

void solve_erase(int x){
   for(int i = 1 ; i <= m ; i++){
     if(vis[i] == x){
       vis[i] = 0;
     }
   }
}

void solve_defragment(){
   int i , j;
   i = 1 , j = 1;
   for(; i <= m ; i++){
     if(vis[i])
       vis[j++] = vis[i];
   }
   for(; j <= m ; j++)
      vis[j] = 0;
}

int main(){
  char words[MAXN];
  int num;
  while(scanf("%d%d" , &t , &m) != EOF){
     memset(vis , 0 , sizeof(vis));
     memset(mark , 0 , sizeof(mark));
     pos = 1;
     for(int i = 0 ; i < t ; i++){
        scanf("%s" , words);
        if(strcmp(words , "defragment") != 0)
           scanf("%d" , &num);
        if(!strcmp(words , "alloc")){
           if(judge(num)){
              mark[pos] = 1;
              printf("%d\n" , pos++);
           }
           else
              printf("NULL\n");
        }
        if(!strcmp(words , "erase")){
           if(num >= pos || num <= 0 || !mark[num]){
             printf("ILLEGAL_ERASE_ARGUMENT\n");
           }
           else{
             solve_erase(num);
             mark[num] = 0;
           }
        }
        if(!strcmp(words , "defragment"))
           solve_defragment();
     }
  }
  return 0;
}

C

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

typedef long long int64;

void gcd(int64 a , int64 b , int64 &d , int64 &x , int64 &y){
    if(!b){
      d = a;
      x = 1;
      y = 0;
    }
    else{
      gcd(b , a%b , d , y , x);
      y -= x*(a/b);
    }
}

int main(){
   int64 a , b , c , d , x , y;
   while(cin>>a>>b>>c){
        gcd(a , b , d , x , y);
        if(c%d != 0)
          printf("-1\n");
        else{
          int64 tmp = (-c)/d;
          x *= tmp , y *= tmp;
          cout<<x<<" "<<y<<endl;
        }
   }
   return 0;
}
时间: 2024-09-18 06:56:43

Codeforces Beta Round #7的相关文章

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 #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 #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 #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]) r

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 #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 #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

Codeforces Beta Round #2

点击打开链接 A /* 思路:模拟 分析: 1 题目要求的在游戏结束后最大的点的值的玩家,或者具有相同点值的情况下最早出现 */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> using namespace std; #define MAXN 1010 #define N 50 int n , pos; int vis