zoukankan      html  css  js  c++  java
  • Codeforces 755B. PolandBall and Game 贪心

    题目大意:

    有两个人轮流说单词,已经说过的单词不能再说。给出两人掌握的不同的单词,两人可能掌握相同的单词,但是这个单词也只能说一边。问在两人都是最优策略下先手是否必胜.

    题解:

    我们发现最优策略一定是先说两人都掌握的单词。
    所以我们求出所有同时被掌握的单词
    然后根据这种单词的奇偶性来判断即可.

    求的时候写了个Trie...
    不过好像直接暴力也可以..

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    inline void read(int &x){
    	x=0;char ch;bool flag = false;
    	while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    	while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
    }
    inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
    inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
    const int maxn = 1024;
    char s[512];
    int nodecnt = 0;
    int ch[maxn*256][28];
    bool flag[maxn*256];
    int root = 0;
    void insert(char *s){
    	int n = strlen(s+1);
    	int nw = root;
    	for(int i=1;i<=n;++i){
    		if(ch[nw][s[i] - 'a'] == 0) ch[nw][s[i] - 'a'] = ++nodecnt;
    		nw = ch[nw][s[i] - 'a'];
    	}flag[nw] = true;
    }
    bool find(char *s){
    	int n = strlen(s+1);
    	int nw = root;
    	for(int i=1;i<=n;++i){
    		if(ch[nw][s[i] - 'a'] == 0) return false;
    		nw = ch[nw][s[i] - 'a'];
    	}return flag[nw];
    }
    int main(){
    	int n,m;read(n);read(m);
    	for(int i=1;i<=n;++i){
    		scanf("%s",s+1);
    		insert(s);
    	}
    	int com = 0;
    	for(int i=1;i<=m;++i){
    		scanf("%s",s+1);
    		if(find(s)) ++com;
    	}n -= com;m -= com;
    	if(com&1){
    		if(n >= m) puts("YES");
    		else puts("NO");
    	}else{
    		if(n >  m) puts("YES");
    		else puts("NO");
    	}
    	getchar();getchar();
    	return 0;
    }
      
    
  • 相关阅读:
    什么时候加上android.intent.category.DEFAULT和LAUNCHER
    android中跨进程通讯的4种方式
    Unix Sockets in Go
    android Service 跨进程通信
    Android Activity和Intent机制学习笔记
    AIR 移动设备上的存储控制
    AIR Android开发APK结构详解
    android 内存管理
    Android权限大全
    运营商登录付费接入ANE打包心得
  • 原文地址:https://www.cnblogs.com/Skyminer/p/6358057.html
Copyright © 2011-2022 走看看