ICPC North Central NA Contest 2017 HG
链接: https://www.jisuanke.com/contest/7331?view=challenges
H Zebras and Ocelots



题意:每当动物园钟声响起时,堆中最低的豹猫都会变成斑马,而该生物下方的所有斑马(如果有的话)也会同时变成豹猫。如果在钟声响起时堆里没有豹猫,那么什么也不会发生。
代码如下:
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 typedef unsigned long long ull; 5 6 ull cal(unsigned int n) 7 { 8 ull sum = 0LLU; 9 ull step = 1LLU << (n-1); 10 while(n--) 11 { 12 char s[2]; 13 scanf("%s", s); 14 if (s[0] == 'O') sum += step; 15 step >>= 1U; 16 } 17 return sum; 18 } 19 20 int main() 21 { 22 unsigned int n = 0; 23 scanf("%u", &n); 24 cout<<cal(n)<<endl; 25 return 0; 26 }
G Sheba's Amoebas



题意:找环的个数
思路:dfs
这么简单一题不知道为啥改了一下午……佛了
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <cmath> 6 using namespace std; 7 const int N = 105; 8 char g[N][N]; 9 bool st[N][N]; 10 int dep[N][N]; 11 int m, n, cnt,ans; 12 int dx[8] = {0,0,-1,-1,-1,1,1,1}; 13 int dy[8] = {1,-1,0,1,-1,0,-1,1}; 14 15 // bool check(int x, int y){ 16 // return x < n && x >= 0 && y >= 0 && y < m; 17 // } 18 19 void dfs(int x, int y){ 20 cnt ++ ; 21 dep[x][y] = cnt; 22 for(int i = 0; i < 8; i ++ ){ 23 int xx = x + dx[i]; 24 int yy = y + dy[i]; 25 if(dep[xx][yy] == 1){ 26 ans ++; 27 //return; 28 } 29 // if(st[xx][yy] || (g[xx][yy] == '.') || xx < 0 || xx >= n || yy < 0 || yy >= m){ 30 // st[xx][yy] = true; 31 // dfs(xx, yy); 32 // } 33 if(st[xx][yy] || g[xx][yy] == '.' || xx < 1 || xx > n || yy < 1 || yy > m) 34 continue; 35 st[xx][yy] = true; 36 dfs(xx,yy); 37 } 38 } 39 40 int main(){ 41 while(~scanf("%d %d", &n, &m)){ 42 ans = 0; 43 memset(st,false,sizeof(st)); 44 memset(dep,0,sizeof(dep)); 45 for(int i = 1; i <= n; i ++ ){ 46 scanf("%s", g[i]+1); 47 } 48 for(int i = 1; i <= n; i++){ 49 for(int j = 1; j <= m; j ++ ){ 50 cnt = 0; 51 if(g[i][j] == '#' && !st[i][j]) 52 dfs(i, j); 53 } 54 } 55 printf("%d\n", ans); 56 } 57 return 0; 58 }
一以贯之的努力 不得懈怠的人生 每天的微小积累会决定最终结果 ————————裴之
欢迎加我QQ:1136244161一起讨论,共同进步

浙公网安备 33010602011771号