8VC Venture Cup 2017 - Elimination Round - B

本文解析了CodeForces上一题目的最优策略。通过分析波兰球(PolandBall)与敌方球(EnemyBall)的词汇交集及差异,采用模拟方法确定先手玩家能否获胜。

 

题目链接: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\n":"NO\n");
        cin.close();
        out.flush();
    }
}

 

转载于:https://www.cnblogs.com/kirito520/p/6349421.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值