2017百毒之星第一场
来源:互联网 发布:网络高弹丝 编辑:程序博客网 时间:2024/04/29 00:00
A题
答案为p^n mod b = 1的个数,就是d(p-1)
#include <iostream>#include <bits/stdc++.h>#define ll long longusing namespace std;int main(){ int T; scanf("%d",&T); ll n; while (T--) { scanf("%lld",&n); n--; ll res=0; for (int i=1;i*i<=n;i++) if (n % i == 0 ) { res++; if (i * i !=n) res++; } printf("%lld\n",res); } return 0;}
E题
随便暴一下
#include <iostream>#include <bits/stdc++.h>#define ll long longusing namespace std;int calc(int y, int m,int d){ if (!( ((y % 4== 0) && (y % 100!=0)) | y % 400==0 ) && (m==2 && d==29)) return -1; if(m==1||m==2) m+=12,y--; int iWeek = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7; return iWeek;}int y,m,d;void solve(){ scanf("%d-%d-%d",&y,&m,&d); int wk=calc(y,m,d); int res=y+1; while ( calc(res,m,d) !=wk ) res++; printf("%d\n",res);}int main(){ int T; scanf("%d",&T); while (T--) solve(); return 0;}
F题
先搜1,再从(0,0)开始把外围的0填充为1,再搜一下0有几块
#include <iostream>#include <bits/stdc++.h>#include <queue>#define clr(x,y) memset(x,y,sizeof x)using namespace std;int mp[110][110],vis[110][110];char s[123];int n,m;struct Node{ int x,y; Node (int _x,int _y) { x=_x; y=_y; }};const int dir[4][2]= {0,1,0,-1,1,0,-1,0};void bfs(Node st,int type){ queue<Node> q; q.push(st); vis[st.x][st.y]=1; while (!q.empty()) { Node now=q.front(); q.pop(); for (int i=0; i<4; i++) { int tx=now.x+dir[i][0]; int ty=now.y+dir[i][1]; if (tx<0 || ty<0 || tx>n+1 || ty>m+1 ) continue; if (mp[tx][ty] == type && vis[tx][ty]==0) { vis[tx][ty] = 1; if (type == 0) mp[tx][ty] = 1; q.push(Node(tx,ty)); } } }}int main(){ while (scanf("%d%d",&n,&m)!=EOF) { clr(mp,0); clr(vis,0); int tot=0; for (int i=1; i<=n; i++) { scanf("%s",s+1); for (int j=1; j<=m; j++) mp[i][j]=s[j] - '0',tot+=(s[j]=='1'); } tot = (n+1) * (m+1) - tot; int one=0; for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) if (mp[i][j] == 1 && vis[i][j]==0) bfs(Node(i,j),1),one++; bfs(Node(0,0),0); if (one!=1) printf("-1\n"); else { int zero=0; for (int i=1; i<=n; i++) for(int j=1; j<=m; j++) if (mp[i][j] == 0) bfs(Node(i,j),0), zero++; if (zero==1) printf("0\n"); if (zero==0) printf("1\n"); if (zero>=2) printf("-1\n"); } } return 0;}
阅读全文
0 0
- 2017百毒之星第一场
- 百毒之星资格赛A题
- 2017百度之星初赛第一场题解
- 百度之星 2017初赛第一场 1005 今夕何夕
- 2012百度之星初赛第一场
- 百度之星冬季赛第一场
- 百度之星2015初赛第一场
- 百度之星第一场选拔赛第一题
- 编程之美 第一场 第一题
- 百度之星 2017初赛第一场 1001 小C的倍数问题
- 2017百度之星初赛B场第一题Chess--简单杨辉三角问题
- 2008百度之星第一场初赛题目
- 百度之星2009程序设计大赛 初赛第一场试题
- 2012百度之星初赛第一场B题
- 2014百度之星初赛第一场部分题解
- 百度之星第一场初赛部分题解
- 2017计蒜之道初赛第一场
- 2017计蒜之道 初赛 第一场
- 2017百度之星初赛(A) 1005 今夕何夕(阅读题)
- python : pip install matplotlib
- 背包九讲第一讲-简单的0/1背包问题有感1.2
- 设计模式之观察者模式
- 删除确认弹出框
- 2017百毒之星第一场
- IBM Minus One 简单字符处理
- Spring MVC:从零开始
- Javascript中的this,call,apply,bind函数
- JavaScript执行环境可以访问变量的类型及优先顺序
- [leetCode]Two Sum
- java中,a=a+b与a+=b的异同
- RedHat7 安装redis
- 8月12日总结