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; }