小C的倍数问题
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
思路:找出P-1的因子个数,对于P进制来说,P-1是满足条件的,然后一个数如果是P-1的因子,你动动手就会发现同样也是满足条件的;
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define LL long long #define pi (4*atan(1.0)) #define eps 1e-14 #define bug(x) cout<<"bug"<<x<<endl; const int N=1e4+110,M=1e6+10,inf=2147483647; const LL INF=1e18+10,mod=1e9+7; int main() { int T; scanf("%d",&T); while(T--) { int n,ans=0; scanf("%d",&n); for(int i=1;i*i<=n;i++) if((n-1)%i==0) { ans+=2; if(i*i==n-1)ans--; } printf("%d ",ans); } return 0; }
今夕何夕
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
思路:模拟题没什么好说的,注意2月29即可;
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define LL long long #define pi (4*atan(1.0)) #define eps 1e-14 #define bug(x) cout<<"bug"<<x<<endl; const int N=1e4+110,M=1e6+10,inf=2147483647; const LL INF=1e18+10,mod=1e9+7; int mouth[15]={0,31,29,31,30,31,30,31,31,30,31,30,31}; int yyyy(int x) { if(x%400==0||(x%4==0&&x%100!=0)) return 1; return 0; } int much(int y,int m,int d) { int flag=yyyy(y); int ans=0; for(int i=1;i<m;i++) { if(i==2) { if(flag)ans+=29; else ans+=28; } else ans+=mouth[i]; } return ans+d; } int fuck(int yy,int mm,int dd,int y,int m,int d) { int ans=0; for(int i=yy;i<y;i++) { if(yyyy(i))ans+=366; else ans+=365; } return ans; } int main() { int T; scanf("%d",&T); while(T--) { int y,m,d; scanf("%d-%d-%d",&y,&m,&d); if(m==2&&d==29) { int pre=y,ans=0; for(int i=y+4;;i+=4) { if(yyyy(i)==0)continue; ans+=fuck(pre,m,d,i,m,d); if(ans%7==0) { printf("%d ",i); break; } pre=i; } } else { int ans=0; for(int i=y+1;;i++) { int d1=much(i-1,m,d); int d2=much(i-1,12,31); int d3=much(i,m,d); ans+=d2-d1+d3; if(ans%7==0) { printf("%d ",i); break; } } } } return 0; }
度度熊的01世界
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
思路:把与外围相连的0的联通块去掉,剩下的就是被1包围的,你只需要判断1,0联通块的个数即可;
并查集判联通;
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> #include<bitset> #include<time.h> using namespace std; #define LL long long #define pi (4*atan(1.0)) #define eps 1e-4 #define bug(x) cout<<"bug"<<x<<endl; const int N=2e4+10,M=1e6+10,inf=1e9+7,MOD=1e9+7; const LL INF=1e18+10,mod=1e9+7; int fa[N]; int vis[N],flag[N]; int Find(int x) { return x==fa[x]?x:fa[x]=Find(fa[x]); } void update(int x,int y) { int u=Find(x); int v=Find(y); if(u!=v)fa[u]=v; } int n,m; char a[110][110]; int check(int x,int y) { if(x<=0|x>n||y<=0||y>m) return 0; return 1; } int xx[5]={1,0,-1,0}; int yy[5]={0,-1,0,1}; int pos(int x,int y) { return (x-1)*m+y; } void xjhz() { memset(vis,0,sizeof(vis)); memset(flag,0,sizeof(flag)); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { for(int k=0;k<4;k++) { int x=i+xx[k]; int y=j+yy[k]; if(check(x,y)&&a[x][y]==a[i][j]) { update(pos(x,y),pos(i,j)); } } } } int zero=0,one=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { int XX=Find(pos(i,j)); for(int k=0;k<4;k++) { int x=i+xx[k]; int y=j+yy[k]; if(check(x,y)==0) vis[XX]=1; } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { int XX=Find(pos(i,j)); if(a[i][j]=='1') { if(!flag[XX])one++; flag[XX]=1; } else { if(!vis[XX]&&!flag[XX])zero++; flag[XX]=1; } } } if(one!=1)printf("-1 "); else { if(zero==1)printf("0 "); else if(zero==0)printf("1 "); else printf("-1 "); } } int main() { while(~scanf("%d%d",&n,&m)) { for(int i=0;i<=15000;i++) fa[i]=i; for(int i=1;i<=n;i++) scanf("%s",a[i]+1); xjhz(); } return 0; }