标签:namespace ret inpu 条件 程序 div bottom panel printf
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <string.h> 5 #include <queue> 6 #include <vector> 7 #include <cmath> 8 #define ll long long 9 #define INF = 0x3f3f3f3f 10 using namespace std; 11 const int N = 1010; 12 const int M = 1010; 13 int solve(int p) { 14 int ans = 0; 15 for(int i = 1; i <= sqrt(p); i ++) { 16 if(p % i == 0) { 17 ans += 2; 18 } 19 } 20 int x = sqrt(p); 21 if(x*x == p) ans--; 22 return ans; 23 } 24 int main() { 25 int t, p; 26 cin >> t; 27 while(t--) { 28 cin >> p; 29 printf("%d\n",solve(p-1)); 30 } 31 return 0; 32 }
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <string.h> 5 #include <queue> 6 #include <vector> 7 #define ll long long 8 #define INF = 0x3f3f3f3f 9 using namespace std; 10 const int N = 1010; 11 const int M = 1010; 12 int day(int y, int m, int d) { 13 if(m == 1 || m == 2) { 14 m += 12; 15 y --; 16 } 17 int w = (d + 2*m + 3*(m+1)/5 + y + y/4 - y/100 + y/400) % 7; 18 return w; 19 } 20 bool check(int y) { 21 if(y % 4 == 0 && y % 100 != 0 || y % 400 == 0) return true; 22 else return false; 23 } 24 int main() { 25 int t, y, m, d; 26 scanf("%d", &t); 27 while(t--) { 28 scanf("%d-%d-%d", &y, &m, &d); 29 int x = day(y, m, d); 30 bool flag = 0; 31 if(m == 2 && d == 29) flag = 1; 32 for(int i = y+1; ; i ++) { 33 if(flag) { 34 if(check(i) && day(i, m, d) == x) { 35 printf("%d\n",i); 36 break; 37 } 38 }else { 39 if(day(i, m, d) == x) { 40 printf("%d\n",i); 41 break; 42 } 43 } 44 } 45 } 46 return 0; 47 }
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <string.h> 5 #include <queue> 6 #include <vector> 7 #define ll long long 8 #define INF = 0x3f3f3f3f 9 using namespace std; 10 const int N = 110; 11 const int M = 1010; 12 char str[N][N]; 13 bool vis[N][N]; 14 int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; 15 int n, m; 16 void dfs(int x, int y, char c) { 17 vis[x][y] = true; 18 for(int i = 0; i < 4; i ++) { 19 int nx = x + dx[i], ny = y + dy[i]; 20 if(0 <= nx && nx <= n+1 && 0 <= ny && ny <= m+1 && !vis[nx][ny] && str[nx][ny] == c) dfs(nx, ny, c); 21 } 22 } 23 int main() { 24 while(scanf("%d %d", &n, &m) != EOF) { 25 memset(vis, 0, sizeof(vis)); 26 memset(str, 0, sizeof(str)); 27 for(int i = 1; i <= n; i ++) scanf("%s", str[i]+1); 28 for(int i = 0; i <= m+1; i ++) str[0][i] = str[n+1][i] = ‘0‘; 29 for(int i = 0; i <= n+1; i ++) str[i][0] = str[i][m+1] = ‘0‘; 30 int ans = 0, ans1 = 0; 31 for(int i = 0; i <= n+1; i ++) { 32 for(int j = 0; j <= m+1; j ++) { 33 if(!vis[i][j]) { 34 if(str[i][j] == ‘1‘) { 35 ans ++; 36 dfs(i, j, ‘1‘); 37 } else if(str[i][j] == ‘0‘) { 38 ans1 ++; 39 dfs(i, j, ‘0‘); 40 } 41 } 42 } 43 } 44 if(ans == 1 && ans1 == 2) { 45 printf("0\n"); 46 } else if(ans == 1 && ans1 == 1) { 47 printf("1\n"); 48 } else printf("-1\n"); 49 } 50 return 0; 51 }
标签:namespace ret inpu 条件 程序 div bottom panel printf
原文地址:http://www.cnblogs.com/xingkongyihao/p/7352438.html