2017"百度之星"程序设计大赛 - 初赛(A)
Posted 掉血菜鸡煮熟中
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017"百度之星"程序设计大赛 - 初赛(A)相关的知识,希望对你有一定的参考价值。
hdu6108 求出 n-1 的因子个数即可
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define MP make_pair #define PB push_back #define fi first #define se second typedef long long ll; const int N = 200005; int main() { int T; scanf("%d", &T); int n; while(T--) { scanf("%d", &n); int ans=0; for(int i=1; i<(int)sqrt(n-1); ++i) if((n-1)%i==0) ans += 2; if((n-1)%(int)sqrt(n-1)==0) ++ans; printf("%d\n", ans); } return 0; }
hdu6112 暴力模拟
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define MP make_pair #define PB push_back #define fi first #define se second typedef long long ll; const int N = 200005; int num[15][35]; int m[15]={0,31,28,31,30,31,30,31,31,30,31,30,31}; void getnum() { int sum=0; rep(i,1,12) rep(j,1,m[i]) { ++sum, num[i][j]=sum; } num[2][29]=num[2][28]; } int is(int year) { return ( year%400==0 || (year%4==0 && year%100!=0) ); } int isday(int year, int mon, int day) { return num[mon][day] + (is(year) && (mon>2 || (mon==2 && day==29))); } int main() { getnum(); int T; scanf("%d", &T); while(T--) { int year, mon, day; scanf("%d-%d-%d", &year, &mon, &day); ll cnt=0, cnt1; rep(i,2001,year-1) cnt += 365+is(i); cnt1 = cnt; cnt += isday(year,mon,day); int dat = cnt%7, ans; rep(i,year,10000) { cnt1 += 365+is(i); if(!(mon==2 && day==29) || is(i+1)) { cnt1 += isday(i+1,mon,day); if(cnt1%7==dat) { ans=i+1; break; } cnt1 -= isday(i+1,mon,day); } } printf("%d\n", ans); } return 0; }
hdu6113 并查集,找出连通快判断即可
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define MP make_pair #define PB push_back #define fi first #define se second typedef long long ll; const int N = 110; int id[N][N], fa[N*N], n, m, num0[N*N]; char s[N][N]; bool is(int x, int y) { return x>0 && y>0 && x<=n && y<=m; } int Find(int x) { return fa[x]==x ? x : fa[x]=Find(fa[x]); } void Unite(int a, int b) { int faa=Find(a), fab=Find(b); if(faa!=fab) fa[faa]=fa[fab]; } int main() { while(~scanf("%d%d", &n, &m)) { int tot=0; rep(i,1,n) { scanf("%s", s[i]+1); rep(j,1,m) id[i][j]=++tot; } rep(i,1,tot) fa[i] = i; rep(i,1,n) rep(j,1,m) { if(is(i-1,j) && s[i-1][j]==s[i][j]) Unite(id[i-1][j], id[i][j]); if(is(i+1,j) && s[i+1][j]==s[i][j]) Unite(id[i+1][j], id[i][j]); if(is(i,j+1) && s[i][j+1]==s[i][j]) Unite(id[i][j+1], id[i][j]); if(is(i,j-1) && s[i][j-1]==s[i][j]) Unite(id[i][j-1], id[i][j]); } int cnt=0; mes(num0, 0); int cnt1=0; rep(i,1,n) rep(j,1,m) { if(s[i][j]==‘1‘ && fa[id[i][j]]==id[i][j]) ++cnt; if(s[i][j]==‘0‘ && fa[id[i][j]]==id[i][j]) ++num0[fa[id[i][j]]], ++cnt1; } if(cnt!=1) { puts("-1"); continue; } cnt=0; rep(ca,1,tot) if(num0[ca]) { bool flag=0; rep(i,1,n) { rep(j,1,m) if(s[i][j]==‘0‘ && fa[id[i][j]]==ca) { if(i==1 || i==n || j==1 || j==m) { flag=1; break; } } if(flag) break; } if(flag==0) ++cnt; } if(cnt==1) puts("0"); else if(cnt==0) puts("1"); else puts("-1"); } return 0; }
以上是关于2017"百度之星"程序设计大赛 - 初赛(A)的主要内容,如果未能解决你的问题,请参考以下文章
2017"百度之星"程序设计大赛 - 资格赛-度度熊与邪恶大魔王(dp+后缀最小值)