省赛训练赛

来源:互联网 发布:反向代理服务器nginx 编辑:程序博客网 时间:2024/06/11 16:51
B - 大还是小?#include<iostream>#include<string>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){    cin.sync_with_stdio(false);    string str1,str2;    string x1,y1,x2,y2;    int T=1;    while (cin>>str1>>str2)    {        int Ans=1;        int pos=str1.find('.');        x1=str1.substr(0,pos);        y1=str1.substr(pos+1);        int pos2=str2.find('.');        x2=str2.substr(0,pos2);        y2=str2.substr(pos2+1);        int lenx1=x1.length(),leny1=y1.length(),lenx2=x2.length(),leny2=y2.length();        int mark=leny1;        for (int i=leny1-1;i>=1;i--)        {            if (y1[i]=='0')                mark=i;            else            {                y1.erase(mark);                leny1=y1.length();                break;            }            if (i==1)            {                y1.erase(mark);                leny1=y1.length();            }        }        mark=leny2;        for (int i=leny2-1;i>=1;i--)        {            if (y2[i]=='0')                mark=i;            else            {                y2.erase(mark);                leny2=y2.length();                break;            }            if (i==1)            {                y2.erase(mark);                leny2=y2.length();            }        }        //cout<<x1<<' '<<y1<<endl<<x2<<' '<<y2<<endl;        if (lenx1==lenx2)        {            bool flag=true;            for (int i=0;i<lenx1;i++)            {                if (x1[i]>x2[i])                {                    Ans=2;                    flag=false;                    break;                }                else if (x1[i]<x2[i])                {                    Ans=0;                    flag=false;                    break;                }            }            if (flag)            {                for (int i=0;;i++)                {                    if (i==leny1||i==leny2)                    {                        if (leny1==leny2)                        {                            Ans=1;                            break;                        }                        else if (leny1<leny2)                        {                            Ans=0;                            break;                        }                        else if (leny1>leny2)                        {                            Ans=2;                            break;                        }                    }                    if (y1[i]>y2[i])                    {                        Ans=2;                        break;                    }                    else if (y1[i]<y2[i])                    {                        Ans=0;                        break;                    }                }            }        }        else        {            if (lenx1<lenx2)                Ans=0;            else                Ans=2;        }        cout<<"Case "<<T++<<": ";        if (Ans==0)            cout<<"Smaller\n";        if (Ans==1)            cout<<"Same\n";        if (Ans==2)            cout<<"Bigger\n";    }    return 0;}D:#include<iostream>#include<string>#include<stdio.h>#include<string.h>#include<algorithm>#include<vector>using namespace std;const int MAX=505;int Mat[MAX][MAX];int SumX[MAX],SumY[MAX];int N,M,u,v;void BadAns(){    int m=-1;    for (int i=1; i<=N; i++)        if (SumX[i]>m)            m=SumX[i],u=i;    m=-1;    for (int j=1; j<=M; j++)        if (SumY[j]>m)            m=SumY[j],v=j;}int main(){    int cases=1;    while (scanf("%d%d",&N,&M)!=EOF)    {        memset(SumX,0,sizeof(SumX));        memset(SumY,0,sizeof(SumY));        for (int i=1; i<=N; i++)            for (int j=1; j<=M; j++)                scanf("%d",&Mat[i][j]);        for (int i=1; i<=N; i++)            for (int j=1; j<=M; j++)                SumX[i]+=Mat[i][j];        for (int j=1; j<=M; j++)            for (int i=1; i<=N; i++)                SumY[j]+=Mat[i][j];        BadAns();        int m=-1;        vector<int> Xs,Ys;        for (int i=1; i<=N; i++)            for (int j=1; j<=M; j++)            {                int temp=SumX[i]+SumY[j]-Mat[i][j];                if (temp>m)                {                    m=temp;                    Xs.clear();                    Ys.clear();                    Xs.push_back(i);                    Ys.push_back(j);                }                if (temp==m)                {                    Xs.push_back(i);                    Ys.push_back(j);                }            }        if (binary_search(Xs.begin(),Xs.end(),u)&&binary_search(Ys.begin(),Ys.end(),v))            cout<<"Case "<<cases++<<": Weak\n";        else            cout<<"Case "<<cases++<<": Strong\n";    }    return 0;}E:#include <map>#include <set>#include <cstdio>#include <cmath>#include <cstring>#include <vector>#include <queue>#include <iostream>#include <string>#include <sstream>#include <cstdlib>#include <ctime>#include <cctype>#include <algorithm>using namespace std;const int INF = 0x3f3f3f3f;const int MAXM = 1e5;const int MAXN = 5e2 + 5;int n, m, r1, c1, step1, step2, r2, c2, mp[MAXN][MAXN];int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};bool vis[MAXN][MAXN],viss[MAXN][MAXN][4];char op[5];struct point{    int x,y,step,dist;    point(int a,int b,int c):x(a),y(b),step(c) {}    point(int a,int b,int c,int d):x(a),y(b),step(d),dist(c) {}    bool operator > (const point& a) const    {        return step > a.step;    }};void BFS1(){    memset(vis, false, sizeof(vis));    priority_queue<point,vector<point>, greater<point> > que;    que.push(point(r1, c1, 0));    vis[r1][c1] = true;    while(!que.empty())    {        point e = que.top();        que.pop();        if(e.x == r2 && e.y == c2)        {            step1 = e.step;            return;        }        for(int i = 0; i < 4; i ++)        {            int nx = e.x + dx[i];            int ny = e.y + dy[i];            if(nx <= 0 || ny <= 0|| nx > n || ny > m || vis[nx][ny] || mp[nx][ny] == -1) continue;            vis[nx][ny] = true;            que.push(point(nx, ny, e.step + mp[nx][ny]));        }    }}void BFS2(){    memset(viss, false, sizeof(viss));    priority_queue<point,vector<point>, greater<point> > que;    que.push(point(r1, c1, 0, 0));    que.push(point(r1, c1, 1, 0));    que.push(point(r1, c1, 2, 0));    que.push(point(r1, c1, 3, 0));    viss[r1][c1][0] = viss[r1][c1][1] = viss[r1][c1][2] = viss[r1][c1][3] = true;    while(!que.empty())    {        point e = que.top();        que.pop();        if(e.x == r2 && e.y == c2)        {            step2 = e.step;            return;        }        for(int i = 0; i < 4; i ++)        {            if(i == e.dist) continue;            int nx = e.x + dx[i];            int ny = e.y + dy[i];            if(nx <= 0 || ny <= 0|| nx > n || ny > m || viss[nx][ny][i] || mp[nx][ny] == -1) continue;            viss[nx][ny][i] = true;            que.push(point(nx, ny, i, e.step + mp[nx][ny]));        }    }}int main(){    int cas = 1;    while(cin >> n >> m >> r1 >> c1 >> r2 >> c2)    {        step2 = step1 = -1;        for(int i = 1; i <= n; i ++)        {            for(int j = 1; j <= m; j ++)            {                cin >> op;                if(op[0] == '*')                    mp[i][j] = -1;                else                    mp[i][j] = atoi(op);            }        }        BFS1();        BFS2();        if(step1 != -1) step1 += mp[r1][c1];        if(step2 != -1) step2 += mp[r1][c1];        printf("Case %d: %d %d\n",cas++, step1, step2);    }    return 0;}F: 阶乘除法#include<iostream>#include<string>#include<stdio.h>#include<string.h>#include<algorithm>#include<vector>#include<queue>#include<functional>#include<cmath>using namespace std;const int MAX=1005;const int INF=0x3f3f3f3f;const int dX[4]= {-1,0,1,0};const int dY[4]= {0,-1,0,1};int main(){    cin.sync_with_stdio(false);    long long k,cases=1,n,m;    while (cin>>k)    {        n=-1,m=-1;        if (k%2==1)            n=k,m=k-1;        else            for (long long i=1; i*i<=k; i++)            {                long long temp=1,j;                for (j=i+1; temp<k; j++)                    temp*=j;                if (temp==k)                {                    n=j-1,m=i;                    break;                }            }        cout<<"Case "<<cases++<<": ";        if ((n==-1&&m==-1)||(n<=m)||n<=0||m<=0)            cout<<"Impossible\n";        else            cout<<n<<' '<<m<<'\n';    }    return 0;}J:又一道简单题#include<iostream>#include<string>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;bool is[10005];int main(){    cin.sync_with_stdio(false);    memset(is,false,sizeof(is));    for (int i=32; i*i<=9999; i++)        is[i*i]=true;    int T;    char str[10];    char str2[10];    cin>>T;    for (int cases=1; cases<=T; cases++)    {        cin>>str;        int Ans=0;        for (char i='1'; i<='9'; i++)        {            if (i==str[0])                continue;            memcpy(str2,str,sizeof(str));            str2[0]=i;            if (is[atoi(str2)])                Ans++;        }        for (int j=1; j<=3; j++)        {            for (char i='0'; i<='9'; i++)            {                if (i==str[j])                    continue;                memcpy(str2,str,sizeof(str));                str2[j]=i;                if (is[atoi(str2)])                    Ans++;            }        }        cout<<"Case "<<cases<<": "<<Ans<<endl;    }    return 0;}
0 0
原创粉丝点击