2017_SDNU_ACM/ICPC_Freshman's Easy Game

来源:互联网 发布:case when mysql 编辑:程序博客网 时间:2024/06/06 21:40

吃鸡数
SDNUOJ1239.我,陆历川,吃鸡
题意:给出一个只能被2||3||5||7整除的的数字n,求他所有的因子个数,注意数据一丢丢大
思路:把n分解成sum2-1个2和sum3-1个3和sum5-1个5和sum7-1个7乘积的样子,然后组合
代码

#include<cstdio>#include<iostream>using namespace std;int main(){    long long n;    int sum2,sum3,sum5,sum7;    int sum;    while(cin>>n)    {        sum2=1,sum3=1,sum5=1,sum7=1;        while(n%2==0)        {            sum2++;            n/=2;        }//就这个模式可以求所有质因子        while(n%3==0)        {            sum3++;            n/=3;        }        while(n%5==0)        {            sum5++;            n/=5;        }        while(n%7==0)        {            sum7++;            n/=7;        }        sum=sum2*sum3*sum5*sum7;        cout<<sum<<endl;    }    return 0;}

及及debug之登峰造极
SDNUOJ1238.及及debug之登峰造极
题意:9*9的矩阵表示bug地图,每个格中是bug或bug的个数,然后输出矩阵
代码

#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>#include<string>#include <set>using namespace std ;#define ll long long#define mem(a) memset(a,0,sizeof(a))int main(){    int n;    int x,y;    int bug[9][9]= {0};    int di[8][2]= {{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}};    int cas=0;    while(cin>>n)    {        cas++;        mem(bug);        for(int i=0; i<n; i++)        {            cin>>x>>y;            bug[x][y]='*';            for(int i=0;i<8;i++)            {                if((bug[x+di[i][0]][y+di[i][1]]!='*')&&x+di[i][0]>=0&&x+di[i][0]<9&&y+di[i][1]>=0&&y+di[i][1]<9)                bug[x+di[i][0]][y+di[i][1]]++;            }        }        cout<<"Case #"<<cas<<':'<<endl;        for(int j=0; j<9; j++)        {            for(int i=0; i<9; i++)            {                if(bug[j][i]==0)                    cout<<' ';                else if(bug[j][i]=='*')                    cout<<'*';                else                    cout<<bug[j][i];            }            cout<<endl;        }        cout<<endl;    }}

当时比赛的时候脑抽判断周围的那里分了八个写的……虽然ac了但是很丑吖然后刚才改成跑循环的又交了一次ac了嘿嘿嘿
北望村八卦阵
SDNUOJ1241.北望村八卦阵
代码

#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>#include<string>#include <queue>using namespace std ;#define ll long long#define mem(a) memset(a,0,sizeof(a))struct node{    int x;    int y;    int step;} r,re,pre,tem;queue<node> q;bool vis[101][101];int di[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};int xl,yl,xw,yw;int t;int m,n,x,y;char s[101][101];int bfs1()//把W看成障碍先跑一遍{    q.push(r);    while(!q.empty())    {        pre=q.front();        //cout<<pre.x<<' '<<pre.y<<endl;        q.pop();        if(pre.x==x&&pre.y==y)            return pre.step;        for(int i=0; i<4; i++)        {            tem.x=pre.x+di[i][0];            tem.y=pre.y+di[i][1];            tem.step=pre.step+1;            if((s[tem.x][tem.y]!='*')&&((s[tem.x][tem.y]!='W'))&&(tem.x<=n)&&(tem.x>0)&&(tem.y<=m)&&(tem.y>0)&&(!vis[tem.x][tem.y]))            {                vis[tem.x][tem.y]=1;                q.push(tem);            }        }    }    return -1;}int bfs2()//把L看成障碍跑{    q.push(r);    while(!q.empty())    {        pre=q.front();        //cout<<pre.x<<' '<<pre.y<<endl;        q.pop();        if(pre.x==x&&pre.y==y)            return pre.step;        for(int i=0; i<4; i++)        {            tem.x=pre.x+di[i][0];            tem.y=pre.y+di[i][1];            tem.step=pre.step+1;            if((s[tem.x][tem.y]!='*')&&((s[tem.x][tem.y]!='L'))&&(tem.x<=n)&&(tem.x>0)&&(tem.y<=m)&&(tem.y>0)&&(!vis[tem.x][tem.y]))            {                vis[tem.x][tem.y]=1;                q.push(tem);            }        }    }    return -1;}int main(){    cin>>t;    while(t--)    {        while(!q.empty())            q.pop();        mem(vis);        mem(s);        cin>>n>>m>>x>>y;        for(int i=1; i<=n; i++)            for(int j=1; j<=m; j++)            {                cin>>s[i][j];            }        r.x=1,r.y=1,r.step=0;        vis[1][1]=1;        q.push(r);        int step1=bfs1();        mem(vis);//跑完一次之后得清标记数组        int step2=bfs2();        int step;        if((step1==-1)&&(step2==-1))        {           cout<<"IMPOSSIBLE"<<endl;        }        else if((step1!=-1)&&(step2==-1))        {            step=2*step1;            cout<<step<<endl;        }        else if((step1==-1)&&(step2!=-1))        {            step=2*step2;            cout<<step<<endl;        }        else        {            if(step1>step2)                step=2*step2;            else step=2*step1;            cout<<step<<endl;        }//输出情况要考虑全面    }    return 0;}

这个起初我是想走了L的话顺便把W也标记了,走了W把L也标记,然后还很自信来着,交了好几遍之后,自己又想了一个测试案例,然后就看出来不能这样子吖,因为他有可能比如虽然已经走过W了但可以从没有W的某条路上走,如果这条路恰好要经过L那就错了啊…然后问了师哥(感谢及神),就分开写…
就,别忘了走完一次之后清个数组…或者用在定义一个数组也行
**未完……

原创粉丝点击