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;}
原创粉丝点击