zoukankan      html  css  js  c++  java
  • ECUST 12级 Practise

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26399#overview

    果断开小号水过

    CodeForces 58A

    #include<string.h>
    #include<iostream>
    #include<stdio.h>
    using namespace std;
    char a[]="hello";
    char s[1000];
    int main()
    {
        while(cin>>s)
        {
            int k=0;
            for(int i=0;i<strlen(s);i++)
            {
                if(s[i]==a[k])
                k++;
            }
            if(k==5)
            printf("YES
    ");
            else
            printf("NO
    ");
        }
        return 0;
    }

    CodeForces 58B

    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    using namespace std;
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            if(n==1)
            {
                printf("1
    ");
                continue;
            }
            int k=n;
            printf("%d ",n);
            while(n--)
            {
                if(n==1)
                break;
                if(k%n==0)
                {printf("%d ",n);k=n;}
            }
            printf("1
    ");
        }
        return 0;
    }
    View Code

    CodeForces 216B

    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    #define MAXN 110
    #define clr(a,b); memset(a,b,sizeof(a));
    using namespace std;
    int n,m;
    int a,b;
    int p[MAXN];
    int circle[MAXN];
    int sum;
    int num[MAXN];
    int find(int x)
    {
        return x==p[x]?x:find(p[x]);
    }
    int main()
    {
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            sum=0;
            clr(circle,0);
            clr(num,0);
            int k=0;
            for(int i=0;i<n;i++)
            p[i]=i;
            for(int i=0;i<m;i++)
            {
                scanf("%d%d",&a,&b);
                int x=find(a);
                int y=find(b);
                if(x!=y)
                p[x]=y;
                else
                circle[k++]=x;
            }
            for(int i=1;i<=n;i++)
            {
                num[find(i)]++;
            }
            for(int i=0;i<k;i++)
            {
                int tmp=find(circle[i]);
                if(num[tmp]%2==1)
                sum++;
            }
            if((n-sum)%2==1) sum++;
            printf("%d
    ",sum);
        }
        return 0;
    }
    View Code

    HDU 4475

    #include<stdio.h>
    #include<math.h>
    #define MAXN 1000003
    using namespace std;
    long long a[MAXN];
    long long n;
    int main()
    {
        a[0]=1;
        for(int i=1;i<MAXN;i++)
        {
            a[i]=a[i-1]*i*2%MAXN;
        }
        int t;
        while(scanf("%d",&t)!=EOF)
        {
            while(t--)
            {
                scanf("%I64d",&n);
                if(n>=MAXN)
                printf("0
    ");
                else
                printf("%I64d
    ",a[n]);
            }
        }
        return 0;
    }
    View Code

    CodeForces 58C

    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n;
    int tmp;
    int x[100010];
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            memset(x,0,sizeof(x));
            for(int i=0;i<n;i++)
            {
                scanf("%d",&tmp);
                if(i<=(n+1)/2-1)
                {
                if((tmp-i)<0)
                continue;
                x[tmp-i]++;
                }
                else
                {
                if((tmp-n+1+i)<0)
                continue;
                x[tmp-n+1+i]++;
                }
            }
            sort(x+1,x+100010);
            printf("%d
    ",n-x[100009]);
        }
        return 0;
    }
    View Code

    POJ 2632

    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    using namespace std;
    struct node
    {
        int x;
        int y;
        int dir;
    }robot[110];
    struct node1
    {
        int rob;
        char action;
        int repeat;
    }move[110];
    
    int A,B;int N,M;char tmp;
    int dy[]={1,0,-1,0};
    int dx[]={0,1,0,-1};
    int map[110][110];
    int flag;
    
    void judge(int num,int x,int y)
    {
        if(x<=0||x>A||y<=0||y>B)
        {
            printf("Robot %d crashes into the wall
    ",num);
            flag=1;return;
        }
        if(map[x][y]==0)
        {
            map[x][y]=num;
            return;
        }
        else
        {
            printf("Robot %d crashes into robot %d
    ",num,map[x][y]);
            flag=1;return;
        }
    
    }
    int main()
    {
        int t;
        while(scanf("%d",&t)!=EOF)
        {
    
            while(t--)
            {
                flag=0;
                memset(map,0,sizeof(map));
                scanf("%d%d",&A,&B);
                scanf("%d%d",&N,&M);
                for(int i=1;i<=N;i++)
                {
                    cin>>robot[i].x>>robot[i].y>>tmp;
                    map[robot[i].x][robot[i].y]=i;
                    if(tmp=='N')
                    robot[i].dir=0;
                    else if(tmp=='E')
                    robot[i].dir=1;
                    else if(tmp=='S')
                    robot[i].dir=2;
                    else if(tmp=='W')
                    robot[i].dir=3;
                }
                for(int i=1;i<=M;i++)
                {
                    cin>>move[i].rob>>move[i].action>>move[i].repeat;
                }
                for(int i=1;i<=M;i++)
                {
                    if(move[i].action=='F')
                    {
                        for(int j=0;j<move[i].repeat;j++)
                        {
                            map[robot[move[i].rob].x][robot[move[i].rob].y]=0;
                            robot[move[i].rob].x+=dx[robot[move[i].rob].dir];
                            robot[move[i].rob].y+=dy[robot[move[i].rob].dir];
                            judge(move[i].rob,robot[move[i].rob].x,robot[move[i].rob].y);
                            if(flag==1)
                            break;
                        }
                        if(flag==1)
                        break;
                    }
                    if(move[i].action=='L')
                    {
                        for(int j=0;j<move[i].repeat;j++)
                        {
                            robot[move[i].rob].dir-=1;
                            if(robot[move[i].rob].dir==-1)
                            robot[move[i].rob].dir=3;
                        }
                    }
                    if(move[i].action=='R')
                    {
                        for(int j=0;j<move[i].repeat;j++)
                        {
                            robot[move[i].rob].dir+=1;
                            robot[move[i].rob].dir%=4;
                        }
                    }
                }
                if(flag==0)
                printf("OK
    ");
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    yii框架中获取添加数据后的id值
    linux环境安装filephp扩展
    yii框架中使用gii的用法
    lanmp环境中创建个软连接
    lanmp环境中php版本的升级为7.1
    内置函数
    递归函数
    装饰器函数精讲
    函数对象
    初识函数集锦
  • 原文地址:https://www.cnblogs.com/whatthefy/p/3196863.html
Copyright © 2011-2022 走看看