1.双击
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n >> d;
int p = -1, t = 0;
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
if(p != -1) {
if(x - p <= d) {
if(!t) {
cout << x << "\n";
}
t = 1;
}
}
p = x;
}
if(!t)
cout << -1 << '\n';
return 0;
}
2.chess960
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int b = 0, r = 0, t = 1;
for(int i = 0; i < int(s.size()); i++) {
if(s[i] == 'R') r ++;
else if(s[i] == 'B') b += i;
if(s[i] == 'K') {
if(r == 2 || r == 0) {
t = 0;
}
}
}
if(!t || b % 2 == 0) {
cout << "No\n";
} else {
cout << "Yes\n";
}
return 0;
}
3.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m,t = 1;
while (t--){
cin >> n >> m;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
for (int i = 1; i < m; i++)
{
if (s[i] == 'T' && s[i - 1] == 'T')
{
s[i] = 'C';
s[i - 1] = 'P';
}
}
cout << s << endl;
}
}
return 0;
}
4. Count Subtractions Editorial
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll a, b;
cin >> a >> b;
ll ans=0;
while(a>0 && b>0){
if(a>b){
ans+=a/b;
a%=b;
}
else{
ans+=b/a;
b%=a;
}
}
cout << ans-1 << endl;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[15];
int main(void)
{
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
set<ll> que;//默认的std::less<T>规则,会对存储的 string 类型元素做升序排序
que.insert(0);
int cnt = 0;
ll ans = 0;
while (!que.empty())
{
ll money = *que.begin();
que.erase(money);
for (int i = 0; i < n; i++)
{
que.insert(money + a[i]);
}
if (cnt == k)
{
ans = money;
break;
}
cnt++;
}
cout << ans << endl;
return 0;
}
补
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=2e5+5; LL n, m, k, l, r; LL a[N], cnt, sum; set<LL> st; int main(){ cin>>n>>l>>r; int cnt=0, res=0; int x=l+r; int s=0; for(int i=0; i<n; ++i){ cin>>k; k%=l+r; s^=k/l; } if(s) cout<<"First"; else cout<<"Second"; return 0; }