F ght与dxt的博弈
第三和第四种都挺nb的。有一些等价转换。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 104;
int sg[maxn][maxn];
int s[3*maxn]; // 后继的sg的集合
int s4[100006];
int main(){
int t;scanf("%d",&t);
double gold = (1+sqrt(5))/2;
for(int i=0;i<maxn;++i){
for(int j=0;j<maxn;++j){
// (i,j)
int a = min(i,j),b=max(i,j);
double kk=(double)(b-a);
int test=(int)(kk*gold);
if(test==a) {
sg[i][j] = 0;
// cout<<i<<" "<<j<<endl;
continue;
}
memset(s,0,sizeof(s));
for(int k=0;k<i;++k) s[sg[k][j]]=1;
for(int k=0;k<j;++k) s[sg[i][k]]=1;
for(int k=1;k<=min(i,j);++k) s[sg[i-k][j-k]]=1;
for(int k=0;k<3*maxn;++k)
if(!s[k]) {sg[i][j]=k;break;}
}
}
while(t--){
int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
int flg=0;
for(int i=1;i<=a;++i){
int x,y;scanf("%d%d",&x,&y);
flg ^= sg[x][y];
}
for(int i=1;i<=b;++i){
int x;scanf("%d",&x);
flg ^= x%(i+1);
}
for(int i=1;i<=c;++i){
int x;scanf("%d",&x);
flg ^= max(0,x-i);
}
for(int i=1;i<=d;++i){
scanf("%d",&s4[i]);
}
sort(s4+1,s4+d+1);
s4[0]=-1;
if(d&1) for(int i=0;i<d;i+=2)
flg ^= (s4[i+1]-s4[i]-1);
else for(int i=1;i<d;i+=2)
flg ^= (s4[i+1]-s4[i]-1);
if(flg) cout<<"ght"<<endl;
else cout<<"dxt"<<endl;
}
}
D 配对最值
分解了。。。很牛
//
// Created by Artis on 2021/5/11.
//
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
typedef long long ll;
int a[maxn];
ll b[maxn];
priority_queue<ll,vector<ll>,greater<ll> > pq; // 放的是设置为正号,到当前之前的数
int main(){
int t;scanf("%d",&t);
while(t--){
int n;scanf("%d",&n);
for(int i=1;i<=n;++i) {
scanf("%lld",&a[i]);
b[i+1]=b[i]+1ll*a[i];
}
n++;
while(!pq.empty()) pq.pop();
ll ans = 0;
for(int i=1;i<n;i+=2){
if(pq.size()==0){
ans += 1ll*b[i+1]-b[i];
pq.push(b[i+1]);
continue;
}
ll ans1 = 1ll*b[i+1]-b[i]; // -+
ll ans2 = 1ll*b[i+1]+b[i]-2ll*pq.top(); // ++
if(ans1>ans2){
pq.push(b[i+1]);
ans += ans1;
}else{
pq.pop();
pq.push(b[i+1]);
pq.push(b[i]);
ans += ans2;
}
}
printf("%lld\n",ans);
}
}