日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces 755B. PolandBall and Game 贪心

發布時間:2025/5/22 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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; }

轉載于:https://www.cnblogs.com/Skyminer/p/6358057.html

總結

以上是生活随笔為你收集整理的Codeforces 755B. PolandBall and Game 贪心的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。