8VC Venture Cup 2017

题目链接:http://codeforces.com/contest/755/problem/B

题意:给定PolandBall 和EnemyBall 这2个人要说的单词,然后每一回合轮到的人要说一个单词,之前说过的单词不能再说,当轮到某个人的回合没单词说即输。每人都采取最优策略,PolandBall 先说问PolandBall 是否能赢。

思路: 首先两个的单词可以分为相同和不相同两个部分,由于说过的词不能重复说所以比起说不相同的那部分的单词还是说相同的那部分比较优,因为说了一个对面有的但是目前还没说的单词那么对方就会少一个单词。然后模拟即可。

import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static final int MAXN=100000+10;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n=cin.nextInt(),m=cin.nextInt(); 
        HashSet<String>se=new HashSet<String>();
        for(int i=1;i<=n;i++){
            String str=cin.next();
            se.add(str);
        }
        int Same=0; boolean flag=true,OK=false;
        for(int i=1;i<=m;i++){
            String str=cin.next(); 
            if(se.contains(str)==true){
                Same++;
            }
        }
        int OtherP=n-Same, OtherE=m-Same;
        for(int i=0; OK==false ;i++){
            if(i%2==0){
                if(Same==0&&OtherP==0){
                    flag=false; OK=true;
                }
                if(Same>0){
                    Same--;
                }else{
                    OtherP--;
                }
            }
            else{
                if(Same==0&&OtherE==0){
                    flag=true; OK=true;
                }
                if(Same>0){
                    Same--;
                }else{
                    OtherE--;
                }
            }
        }
        out.printf(flag==true?"YES
":"NO
");
        cin.close();
        out.flush();
    }
}
原文地址:https://www.cnblogs.com/kirito520/p/6349421.html