C. Digital Logarithm
赛时想到了归并排序,用两个vector做的,想到了之前的用b匹配a,逐个匹配
更好的是题解的优先队列
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define ft first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define int long longconst int N=200010;
int a[N],b[N];
int get(int x){int ret=0;while(x){ret++;x/=10;}return ret;
}
void solve(){int n;cin>>n;priority_queue<int,vector<int>> qa,qb;for(int i=1;i<=n;i++){cin>>a[i];qa.push(a[i]);}for(int i=1;i<=n;i++){cin>>b[i];qb.push(b[i]);}int ans=0;while(!qa.empty()){int t1=qa.top();int t2=qb.top();if(t1>t2){//a的最大值比b的最大值都要大t1=get(t1);qa.pop();qa.push(t1);ans++;}else if(t1<t2){t2=get(t2);qb.pop();qb.push(t2);ans++;}else {qa.pop();qb.pop();}}cout<<ans<<'\n';
}
signed main(){std::ios::sync_with_stdio(false);int T;cin>>T;while(T--){solve();}
}
D. Letter Picking
很少做区间dp,区间博弈dp
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define ft first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define int long long
int comb(char x,char y) {if(x>y) return 1;if(x<y) return -1;return 0;
}
int f[2010][2010];
void solve() {string s;cin>>s;int n=s.size();s="a"+s;for(int i=1;i<=n-1;i++)f[i][i+1]=(s[i]==s[i+1])?0:1;for(int len=4;len<=n;len+=2){for(int l=1,r=len;l<=n;l++,r++){f[l][r]=-1;int f1=f[l+2][r]==0?comb(s[l],s[l+1]):f[l+2][r];int f2=f[l+1][r-1]==0?comb(s[l],s[r]):f[l+1][r-1];int f3=f[l][r-2]==0?comb(s[r],s[r-1]):f[l][r-2];int f4=f[l+1][r-1]==0?comb(s[r],s[l]):f[l+1][r-1];f[l][r]=max(min(f1,f2),min(f3,f4));}}if(f[1][n]==1) puts("Alice");if(f[1][n]==0) puts("Draw");if(f[1][n]==-1) puts("Bob");
}
signed main(){std::ios::sync_with_stdio(false);int T;cin>>T;while(T--){solve();}
}