CodeFroces 429B Godsend (模拟)
生活随笔
收集整理的這篇文章主要介紹了
CodeFroces 429B Godsend (模拟)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
解法:由于第一個(gè)人是可以選擇任意長(zhǎng)度,和為奇數(shù)的序列,偶數(shù)相對(duì)于奇數(shù)是可以忽略的,所以當(dāng)?shù)谝粋€(gè)人有奇數(shù)個(gè)奇數(shù)的時(shí)候,一次就能取完,必贏。有大于等于2的偶數(shù)個(gè)的時(shí)候,取掉一個(gè)變?yōu)槠鏀?shù),第二個(gè)人無可奈何,所以也必定為第一個(gè)人贏。唯一第一個(gè)人會(huì)輸?shù)木褪菦]有奇數(shù)的時(shí)候了。
代碼如下:
#include<iostream> #include<cstdio> #include<vector> #include<queue> #include<utility> #include<stack> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<set> #include<map> using namespace std; const int maxn = 1e6 + 5; int n; int a[maxn]; long long sum = 0; int main() { #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endifcin >> n;int odd = 0; for(int i = 0; i < n; i++) {scanf("%d", &a[i]);sum += a[i];if(a[i] % 2 == 1)odd++;}int ans = 0;if(odd < 1) {ans = 2;} else {ans = 1;}if(ans == 1)cout << "First" << '\n';elsecout << "Second" << '\n';return 0; }總結(jié)
以上是生活随笔為你收集整理的CodeFroces 429B Godsend (模拟)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拍卖系统源码 java,基于B2C的网上
- 下一篇: 推荐系统中的相似性