zoukankan      html  css  js  c++  java
  • Codeforces Round #646 (Div. 2)

    题目链接:https://codeforces.com/contest/1363

    视频讲解链接:https://www.bilibili.com/video/BV1NC4y1a7si/(审核后可看)

    A. Odd Selection

    //
    //  main.cpp
    //  CF
    //
    //  Created by HanJinyu on 2020/5/15.
    //  Copyright © 2020 by HanJinyu. All rights reserved.
    //
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    typedef double db;
    typedef long long ll;
    const int maxn=2e5+10;
    int main()
    {
            #ifdef ONLINE_JUDGE
            #else
                freopen("in.txt","r",stdin);
            #endif
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n,x;
            scanf("%d%d",&n,&x);
            int a[maxn];
            int _j=0,_o=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d",a+i);
                if(a[i]&1)
                    _j++;
                else
                    _o++;
            }
    //        cout<<"ji="<<_j<<endl;
    //        cout<<"ou="<<_o<<endl;
            if(_j==0)
            {
                printf("No
    ");continue;
            }
            if(x%2==0)
            {
                bool flag=false;
                for(int i=1;i<=x;i++)
                {
                    if(i&1)
                    {
                        if((_j>=i&&_o>=x-i)||(_o>=i&&_j>=x-i))
                        {
                            flag=true;
                            break;
                        }
                    }
                }
                if(flag)
                    printf("Yes
    ");
                else
                    printf("No
    ");
            }
            else
            {
                if(_o>=x)
                    printf("Yes
    ");
                else if(_j%2==0&&_j+_o==x)
                    printf("No
    ");
                else{
                    bool flag=false;
                    for(int i=1;i<=x;i++)
                    {
                        if(i&1)
                        {
                            if((_j>=i&&_o>=x-i))
                            {
                                flag=true;
                                break;
                            }
                        }
                    }
                    if(flag)
                        printf("Yes
    ");
                    else
                        printf("No
    ");
                }
            }
        }
        return 0;
    }
    View Code

    B.Subsequence Hate

    //-------------------------------------------------
    //Created by HanJinyu
    //Created Time :三  5/20 12:29:04 2020
    //File Name :question.cpp
    //-------------------------------------------------
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    typedef double db;
    typedef long long ll;
    const int maxn = 2e5+10;
    #define maxn 0x3f3f3f3f
    int main()
    {
        #ifdef ONLINE_JUDGE
        #else
        freopen("in.txt","r",stdin);
        #endif
        int t;
        scanf("%d",&t);
        while(t--)
        {
            char str[1111];
            scanf("%s",str);
            int len=strlen(str);
            if(len<=2)
                printf("0
    ");
            else{
                int ans=2000;
                for(int i=0;i<len;i++)
                {
                    int left=0;
                    for(int j=0;j<i;j++)
                    {
                        if(str[j]=='1')
                            left++;
                    }
                    for(int j=i;j<len;j++)
                    {
                        if(str[j]=='0')
                            left++;
                    }
                    ans=min(ans,left);
                }
                for(int i=0;i<len;i++)
                {
                    int right=0;
                    for(int j=0;j<i;j++)
                    {
                        if(str[j]=='0')
                            right++;
                    }
                    for(int j=i;j<len;j++)
                    {
                        if(str[j]=='1')
                            right++;
                    }
                    ans=min(ans,right);
                }
                printf("%d
    ",ans);
            }
        }
         return 0;
    }
    View Code

    C.Game On Leaves

    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    typedef double db;
    typedef long long ll;
    const int maxn = 2e5+10;
    #define maxn 0x3f3f3f3f
    int main()
    {
        #ifdef ONLINE_JUDGE
        #else
        freopen("in.txt","r",stdin);
        #endif
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n,x;
            scanf("%d%d",&n,&x);
            int u,v;
            vector<int>vv[2000];
            for(int i=0;i<n-1;i++)
            {
                scanf("%d%d",&u,&v);
                vv[u].push_back(v);
                vv[v].push_back(u);
            }
            if(n==1)
            {
                printf("Ayush
    ");continue;
            }
            if(vv[x].size()<=1)
            {
                printf("Ayush
    ");continue;
            }
            if(n&1)
            {
                printf("Ashish
    ");
            }
            else
                printf("Ayush
    ");
           
        }
        return 0;
    }
    View Code
  • 相关阅读:
    51 Nod 1068 Bash游戏v3
    51 Nod Bash 游戏v2
    51 Nod 1073 约瑟夫环
    UVA 12063 Zeros and ones 一道需要好好体会的好题
    51 Nod 1161 Partial sums
    2018中国大学生程序设计竞赛
    UVA 11971 Polygon
    UVA 10900 So do you want to be a 2^n-aire?
    UVA 11346 Possibility
    python with as 的用法
  • 原文地址:https://www.cnblogs.com/Vampire6/p/13023548.html
Copyright © 2011-2022 走看看