A Many Formulae

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) {\
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl;\
}
#pragma comment(linker,"/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MXAN (112345)
int n;
ll dp[112233];
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);

dp[0]=1;
dp[1]=2;
Fork(i,2,1e5+10)
dp[i]=(dp[i-1]+dp[i-2])%F;
n=read();
ll ans=0;
For(i,n) {
int x=read();
if(i==1) upd(ans,dp[n-1]*x%F);
else {
upd(ans,sub(mul(dp[max(0,i-2)],dp[n-i]),dp[max(0,i-3)]*dp[max(0,n-i-1)])*x%F);
}
}
cout<<ans<<endl;

return 0;
}

B Insurance

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) {\
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl;\
}
#pragma comment(linker,"/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MXAN (112345)
int n;
ll a[112233];
double ck(double x) {
double p=0;
For(i,n)
p+=x+a[i]-min(a[i]*1.,2*x);
return p;
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);

n=read();
For(i,n) a[i]=read();
double l=0,r=3e9,ans;
Rep(i,404) {
double m=(l+r)/2;
double l1=l+(r-l)/3,r1=r-(r-l)/3;
if(ck(l1)>ck(r1)) l=l1;else r=r1;
}
printf("%.20lf\n",ck((l+r)/2)/n);
return 0;
}

C Calculator

交替进行3,4操作可以构造Fib数列,
如果在其中插入1个1或2操作,得到的会是Tokio Marine & Nichido Fire Insurance Programming Contest 2021(AtCoder Regular Contest 122) 题解_i++,继续进行得到Tokio Marine & Nichido Fire Insurance Programming Contest 2021(AtCoder Regular Contest 122) 题解_git_02

将N转成Tokio Marine & Nichido Fire Insurance Programming Contest 2021(AtCoder Regular Contest 122) 题解_i++_03
按如上方法构造

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) {\
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl;\
}
#pragma comment(linker,"/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MXAN (112345)
int n;
ll dp[112233];
ll a[1123];
ll x=0,y=0;
void work(int t) {
if(t==1) ++x;
else if(t==2) ++y;
else if(t==3) x+=y;
else y+=x;
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);

dp[0]=1;
dp[1]=1;
Fork(i,2,130){
dp[i]=(dp[i-1]+dp[i-2]);
if(dp[i]>1e18) {
n=i;break;
}
}
ll p;cin>>p;
ll N=p;
int m=0;
ForD(i,n) {
a[i]=p/dp[i];
p%=dp[i];
if(!m && a[i]) m=i;
}

int v[100000],len=0;
int op=1;
ForD(i,m) {
For(j,a[i]) v[++len]=op;
v[++len]=5-op;
if(op==1)++op;else --op;
}
cout<<len<<endl;
For(i,len) {
work(v[i]);
// cout<<v[i]<<endl;
}
// cout<<x<<' '<<y<<endl;
int h[10];
h[1]=2,h[2]=1,h[3]=4,h[4]=3;
if(x==N) {
For(i,len) {
cout<<v[i]<<endl;
}
}
else {
For(i,len) {
cout<<h[v[i]]<<endl;
}

}

return 0;
}

D XOR Game

不难发现Bob可以凑出所有2n个数分成n对数的所有情况。
考虑把所有数补前导0扔字典树。
如果字典数左右两子树对应的字符串均为偶数,则显然答案不会出现分别选取两个子树中的数凑成一对的情况,递归求解
否则答案为左右2子树凑1对,剩下的分别在子树内凑。

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) {\
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl;\
}
#pragma comment(linker,"/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MXAN (112345)
int n;
ll a[412345];
#define maxn (400000*31)
struct XorTrie{
int cnt = 0,dfn = 0;
int t[maxn][2];
int L[maxn],R[maxn];

int s[maxn];
void _init(){
cnt = 0;
dfn = 0;
}
void Insert(ll x,int id){
int rt = 0;s[rt]++;
for(int k=32;k>=0;k--){
int op = (x>>k&1ll)?1:0;
if(!t[rt][op]) t[rt][op] = ++cnt;
rt = t[rt][op];
s[rt]++;
if(!L[rt]) L[rt] = id;
R[rt] = id;

}
}
ll AnswerPos(int rt,int pos,ll x){
ll ans = 0;
for(int i=pos;i>=0;i--){
int op = (x>>i&1ll)?1:0;
if(t[rt][op]) rt = t[rt][op];
else{
rt = t[rt][!op];
ans += (1ll<<i);
}
}return ans;
}
ll Divide(int rt,int pos){
if(t[rt][0]&&t[rt][1]){
int x = t[rt][0],y = t[rt][1];
if(s[x]%2==0 && s[y]%2==0) return max(Divide(t[rt][0],pos-1),Divide(t[rt][1],pos-1));
ll minl = INF;
for(int k=L[x];k<=R[x];k++) minl = min(minl,AnswerPos(y,pos-1,a[k])+(1ll<<pos));
return minl;
}
else if(t[rt][0]) return Divide(t[rt][0],pos-1);
else if(t[rt][1]) return Divide(t[rt][1],pos-1);
return 0;
}


}S;
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);

n=read()*2;
For(i,n) cin>>a[i];
sort(a+1,a+1+n);
ll p=0;
for(int i=1;i<=n;i++) S.Insert(a[i],i);

printf("%lld\n",S.Divide(0,32));

return 0;
}