生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #659 (Div. 2)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
日常爆零掉分wa
A. Common Prefixes
根據前一個字符串構造后一個字符串,從哪不同就從哪換
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
#include<string>
using namespace std
;
int main()
{IO
;int T
;cin
>>T
;while(T
--){int n
;cin
>>n
;string
s(200,'a');cout
<<s
<<endl
;while(n
--){int j
;cin
>>j
;s
[j
]=s
[j
]=='a'?'b':'a';cout
<<s
<<endl
;}}return 0;
}
大佬博客題解
這方法太妙了啊!!!我什么時候能想出這么秒的方法
B1. Koa and the Beach (Easy Version)
動態規劃
狀態表示:f[i][j]表示在第j秒到達第i片海域是否合法
狀態計算:可以從第i-1片海域花費1秒過來,或者在第i片海域原地等待1秒,即f[i][j]=f[i-1][j-1]|f[i][j-1],當然還要檢查是否滿足水位限制
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
using namespace std
;
const int N
=110,M
=20010;
int f
[N
][M
];
int d
[N
],p
[2*N
];
void init(int k
)
{memset(f
,0,sizeof f
);for(int i
=1;i
<=k
;i
++) p
[i
]=i
;for(int i
=k
+1;i
<2*k
;i
++) p
[i
]=2*k
-i
;for(int i
=0;i
<2*k
;i
++) f
[0][i
]=1;
}
int main()
{IO
;int T
;cin
>>T
;while(T
--){int n
,k
,l
;cin
>>n
>>k
>>l
;init(k
);for(int i
=1;i
<=n
;i
++) cin
>>d
[i
];for(int i
=1;i
<=n
;i
++)for(int j
=1;j
<2*k
*n
;j
++){f
[i
][j
]=f
[i
-1][j
-1]|f
[i
][j
-1];if(d
[i
]+p
[j
%(2*k
)]>l
)f
[i
][j
]=0;}bool ok
=0;for(int i
=0;i
<2*k
*n
;i
++) if(f
[n
][i
]){ok
=1;break;}if(ok
) cout
<<"Yes"<<endl
;else cout
<<"No"<<endl
;}return 0;
}
有一說一英語不好題目都沒看懂-。-wtcl
C. String Transformation 1
對于A,B字符串如果存在A[i]>B[i]則無解,否則有解
用一個set記錄每一個字符需要變成那些字符,每次貪心的讓其變成最小需要變成的字符,重復操作。set自動排序去重
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std
;
typedef long long ll
;
set
<int> mp
[26];
int main()
{IO
;int T
;cin
>>T
;while(T
--){int n
;cin
>>n
;string a
,b
;cin
>>a
>>b
;bool ok
=1;for(int i
=0;i
<n
;i
++){if(a
[i
]!=b
[i
]){if(a
[i
]>b
[i
]){ok
=0;break;}else mp
[a
[i
]-'a'].insert(b
[i
]-'a');}}if(!ok
) {for(int i
=0;i
<26;i
++) mp
[i
].clear();cout
<<-1<<endl
;continue;}int res
=0;for(int i
=0;i
<26;i
++){if(mp
[i
].empty()) continue;int ans
=*mp
[i
].begin();for(auto t
:mp
[i
]){if(t
==ans
) continue;mp
[ans
].insert(t
);}res
++;mp
[i
].clear();}cout
<<res
<<endl
;}return 0;
}
雖然不會寫,但是看到思路后自己能用set獨立碼出代碼還是非常高興的!!!漸漸熟悉STL(我是傻了嗎-。-
D. GameGame
異或操作有結合律,可以按位考慮,我們每次從最高位考慮。
設當前位是111的數字個數為xxx,是000的數字個數為yyy。
如果xxx為偶數,則無論怎么選,最后兩個得分在這個位都是一樣的沒必要考慮這一位。
如果xxx為奇數,且xmod4=1x mod 4=1xmod4=1,先手先選擇一個1,然后后手選什么先手就選什么,先手最終該位一定是111必勝;如果xmod4=3,x mod4 = 3,xmod4=3, 且yyy是偶數,則后手完全可以跟隨先手的操作,最后先手在該位一定是偶數個1,異或結果為0,先手必輸。如果xmod4=3x mod4 = 3xmod4=3但是yyy是奇數,那么先手一定能贏,先手先拿該位為0的數,使整個局勢轉移到上一情形中。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std
;
typedef long long ll
;
const int N
=40;
int bit
[N
];
int main()
{IO
;int T
;cin
>>T
;while(T
--){int n
;cin
>>n
;memset(bit
,0,sizeof bit
);for(int i
=0;i
<n
;i
++){ll a
;cin
>>a
;for(int j
=0;j
<=32;j
++) bit
[j
]+=(a
>>j
&1);}int flag
=0;for(int i
=32;i
>=0;i
--)if(bit
[i
]&1){int x
=bit
[i
],y
=n
-bit
[i
];if(x
%4==1){flag
=1;}else {if(y
&1) flag
=1;else flag
=-1;}break;}if(flag
==1) cout
<<"WIN"<<endl
;else if(flag
==-1) cout
<<"LOSE"<<endl
;else cout
<<"DRAW"<<endl
;}return 0;
}
爭取div2不爆0~~要加油哦!
總結
以上是生活随笔為你收集整理的Codeforces Round #659 (Div. 2)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。