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\n");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\n");
            else
                printf("No\n");
        }
        else
        {
            if(_o>=x)
                printf("Yes\n");
            else if(_j%2==0&&_j+_o==x)
                printf("No\n");
            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\n");
                else
                    printf("No\n");
            }
        }
    }
    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\n");
        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\n",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\n");continue;
        }
        if(vv[x].size()<=1)
        {
            printf("Ayush\n");continue;
        }
        if(n&1)
        {
            printf("Ashish\n");
        }
        else
            printf("Ayush\n");
       
    }
    return 0;
}
View Code

 

posted @ 2020-06-01 09:46  branna  阅读(214)  评论(0编辑  收藏  举报