1001 小C的倍数问题
Accepts: 1990
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
3
P-1的因子个数
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; ll kk(ll n) { int ans=0; int o=sqrt(n); for(int i=1;i<=o;i++) { if(n%i==0) ans+=2; } if(o*o==n) ans--; return ans; } int main() { ll t,k; scanf("%lld",&t); while(t--) { scanf("%lld",&k); printf("%lld ",kk(k-1)); } return 0; }
1002 数据分割
Accepts: 102
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
1005 今夕何夕
Accepts: 1345
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
2023 2023 2024
分情况讨论月份小于2、月份大于2、月份等于2,天数等于29.
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int t,n,y,d; char ch; int leap(int x) { if(x%400==0) return 1; if(x%4==0 && x%100) return 1; return 0; } int main() { scanf("%d",&t); while(t--) { scanf("%d%c%d%c%d",&n,&ch,&y,&ch,&d); int pos=0; if(y==2 && d==29) { for(int i=1;;i++) { if(leap(n+i)) pos+=2; else pos+=1; if(pos%7==0 && leap(n+i)) { printf("%d ",n+i); break; } } } else if(y<=2) { for(int i=0;;i++) { if(leap(n+i)) pos+=2; else pos+=1; if(pos%7==0) { printf("%d ",n+i+1); break; } } } else { for(int i=1;;i++) { if(leap(n+i)) pos+=2; else pos+=1; if(pos%7==0) { printf("%d ",n+i); break; } } } } return 0; }
1006 度度熊的01世界
Accepts: 967
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
0 1 -1
BFS求连通块个数,注意0 1的定义
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; char a[101][101]; int vis[101][101],n,m; char ch; int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; struct node { int x,y; }pos,q; queue<node>ans; int bfs(int x,int y,char c) { int xx,yy; pos.x=x;pos.y=y; vis[x][y]=1; ans.push(pos); int ok=1; while(!ans.empty()) { pos=ans.front(); ans.pop(); for(int i=0;i<4;i++) { xx=dir[i][0]+pos.x; yy=dir[i][1]+pos.y; if((xx>=0 && xx<n) && (yy>=0 && yy<m)) { if(a[xx][yy]==c && !vis[xx][yy]) { q.x=xx; q.y=yy; vis[xx][yy]=1; ans.push(q); } } else ok=0; } } return ok; } int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<n;i++) { scanf("%s",a[i]); } int pos=0,ans=0,cnt=0; int la=0,lb=0; memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(!vis[i][j]) { if(a[i][j]=='0') { la++; pos+=bfs(i,j,'0'); } else { lb++; ans+=bfs(i,j,'1'); } } } } if(lb==1 && pos==0) printf("1 "); else if(pos==1 && lb==1) printf("0 "); else printf("-1 "); } return 0; } /* 16 32 00000000111110000001111100000000 00000000111110000000111110000000 00000001111110000000111110000000 00000001111110000000011111000000 00000001111110000000001111000000 00000001111110000000001111100000 00000001111100000000001111000000 00000001111000000000001111000000 00000001111000000000001111000000 00000001111000000000000111000000 00000000111100000000000111000000 00000000111100000000000111000000 00000000111100000000000111000000 00000001111000000000011110000000 00000001111000000000011110000000 00000000111000000000011110000000 -1 */ /* 3 4 1111 1101 1011 0 */