2024暑假集训测试5
前言
- 比赛链接。
T1、T2 都挂分了,T1 整形除法为向 \(0\) 取整,也就是说当 \(<0\) 时为向上取整,导致挂分,还调了 \(3\) 个多小时导致 T3、T4 根本没看。
T1 Start
\(9\) 牌大模拟,注意几个细节:
- 一个人失败后会扔掉手里的所有牌病重新取 \(3\) 张牌。
- 注意向下取整的问题,前言里说了。
Double
状态用了普通牌后及时消除。
不知道为啥打了 \(1000\) 多行。
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define sort stable_sort
using namespace std;
const int N=40,M=3e5+10;
template<typename Tp> inline void read(Tp&x)
{
x=0;register bool z=true;
register char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') z=0;
for(;'0'<=c&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x=(z?x:~x+1);
}
void wt(int x){if(x>9)wt(x/10);putchar((x%10)+'0');}
void write(int x){if(x<0)putchar('-'),x=~x+1;wt(x);}
int n,m,k,tot,ans1,ans2,head,now;
bool flag,turn;
string name[N],s[N][N],q[M];
bool check1(char x,char y)
{
if(y==0) return 1;
if(x=='E') return 0;
if(x=='C') return 1;
if(x=='A'&&y!='C') return 1;
if(x=='B'&&y!='C'&&y!='A') return 1;
if(x=='D'&&y=='E') return 1;
return 0;
}
bool check2(char x,char y)
{
if(y==0) return 1;
if(x=='E') return 0;
if(x=='D') return 1;
if(x=='B'&&y!='D') return 1;
if(x=='A'&&y!='D'&&y!='B') return 1;
if(x=='C'&&y=='E') return 1;
return 0;
}
void go_turn();
void go()
{
if(m<=0) exit(0);
for(int i=now+1;i<=n;i++)
{
if(!flag)
{
int maxx=-0x3f3f3f3f; ans2=0;
bool normal=0;
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='A')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1+sum>maxx&&ans1+sum<=99)
{
maxx=ans1+sum;
ans2=j;
}
if(ans1+sum==maxx)
{
char last=s[i][ans2][0];
if(check1('A',last)) ans2=j;
}
if(ans1+sum<=99) normal=1;
}
if(s[i][j][0]=='B')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1-sum>maxx&&ans1-sum<=99)
{
maxx=ans1-sum;
ans2=j;
}
if(ans1-sum==maxx)
{
char last=s[i][ans2][0];
if(check1('B',last)) ans2=j;
}
if(ans1-sum<=99) normal=1;
}
if(s[i][j][0]=='C')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1*sum>maxx&&ans1*sum<=99)
{
maxx=ans1*sum;
ans2=j;
}
if(ans1*sum==maxx)
{
char last=s[i][ans2][0];
if(check1('C',last)) ans2=j;
}
if(ans1*sum<=99) normal=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]!='O')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(floor((double)ans1/(double)sum)>maxx&&floor((double)ans1/(double)sum)<=99)
{
maxx=floor((double)ans1/(double)sum);
ans2=j;
}
if(floor((double)ans1/(double)sum)==maxx)
{
char last=s[i][ans2][0];
if(check1('D',last)) ans2=j;
}
if(floor((double)ans1/(double)sum)<=99) normal=1;
}
if(s[i][j][0]=='E')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(sum>maxx&&sum<=99)
{
maxx=sum;
ans2=j;
}
if(sum==maxx)
{
char last=s[i][ans2][0];
if(check1('E',last)) ans2=j;
}
if(sum<=99) normal=1;
}
}
if(!normal)
{
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='P')
{
maxx=ans1;
ans2=j;
break;
}
if(s[i][j][0]=='T')
{
char last=s[i][ans2][0];
if(last=='P') continue;
maxx=ans1;
ans2=j;
}
if(s[i][j][0]=='D'&&s[i][j][1]=='O')
{
if(ans2!=0) continue;
maxx=ans1;
ans2=j;
}
}
}
if(ans2==0)
{
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
puts(" lost the game.");
m--;
if(m>0)
{
tot++;
cout<<"Round "<<tot<<':'<<endl;
}
ans1=0,now=i-1,flag=0,turn=0;
for(int j=1;j<=3;j++)
s[i][j]=q[head],
head++;
if(m>0) go();
if(m<=0) exit(0);
return ;
}
else
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go_turn();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
}
}
else
{
int maxx=0x3f3f3f3f; ans2=0;
bool spe=0,normal=0;
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='P')
{
maxx=ans1;
ans2=j;
spe=1;
break;
}
if(s[i][j][0]=='T')
{
char last=s[i][ans2][0];
if(last=='P') continue;
maxx=ans1;
ans2=j;
spe=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]=='O')
{
if(ans2!=0) continue;
maxx=ans1;
ans2=j;
spe=1;
}
}
if(spe==1)
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go_turn();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
continue;
}
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='A')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1+sum<maxx&&ans1+sum<=99)
{
maxx=ans1+sum;
ans2=j;
}
if(ans1+sum==maxx)
{
char last=s[i][ans2][0];
if(check2('A',last)) ans2=j;
}
if(ans1+sum<=99) normal=1;
}
if(s[i][j][0]=='B')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1-sum<maxx&&ans1-sum<=99)
{
maxx=ans1-sum;
ans2=j;
}
if(ans1-sum==maxx)
{
char last=s[i][ans2][0];
if(check2('B',last)) ans2=j;
}
if(ans1-sum<=99) normal=1;
}
if(s[i][j][0]=='C')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1*sum<maxx&&ans1*sum<=99)
{
maxx=ans1*sum;
ans2=j;
}
if(ans1*sum==maxx)
{
char last=s[i][ans2][0];
if(check2('C',last)) ans2=j;
}
if(ans1*sum<=99) normal=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]!='O')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(floor((double)ans1/(double)sum)<maxx&&floor((double)ans1/(double)sum)<=99)
{
maxx=floor((double)ans1/(double)sum);
ans2=j;
}
if(floor((double)ans1/(double)sum)==maxx)
{
char last=s[i][ans2][0];
if(check2('D',last)) ans2=j;
}
if(floor((double)ans1/(double)sum)<=99) normal=1;
}
if(s[i][j][0]=='E')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(sum<maxx&&sum<=99)
{
maxx=sum;
ans2=j;
}
if(sum==maxx)
{
char last=s[i][ans2][0];
if(check2('E',last)) ans2=j;
}
if(sum<=99) normal=1;
}
}
if(ans2==0)
{
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
puts(" lost the game.");
m--;
if(m>0)
{
tot++;
cout<<"Round "<<tot<<':'<<endl;
}
ans1=0,now=i-1,flag=0,turn=0;
for(int j=1;j<=3;j++)
s[i][j]=q[head],
head++;
if(m>0) go();
if(m<=0) exit(0);
return ;
}
else
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go_turn();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
}
maxx=-0x3f3f3f3f,ans2=0;
normal=0;
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='A')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1+sum>maxx&&ans1+sum<=99)
{
maxx=ans1+sum;
ans2=j;
}
if(ans1+sum==maxx)
{
char last=s[i][ans2][0];
if(check1('A',last)) ans2=j;
}
if(ans1+sum<=99) normal=1;
}
if(s[i][j][0]=='B')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1-sum>maxx&&ans1-sum<=99)
{
maxx=ans1-sum;
ans2=j;
}
if(ans1-sum==maxx)
{
char last=s[i][ans2][0];
if(check1('B',last)) ans2=j;
}
if(ans1-sum<=99) normal=1;
}
if(s[i][j][0]=='C')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1*sum>maxx&&ans1*sum<=99)
{
maxx=ans1*sum;
ans2=j;
}
if(ans1*sum==maxx)
{
char last=s[i][ans2][0];
if(check1('C',last)) ans2=j;
}
if(ans1*sum<=99) normal=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]!='O')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(floor((double)ans1/(double)sum)>maxx&&floor((double)ans1/(double)sum)<=99)
{
maxx=floor((double)ans1/(double)sum);
ans2=j;
}
if(floor((double)ans1/(double)sum)==maxx)
{
char last=s[i][ans2][0];
if(check1('D',last)) ans2=j;
}
if(floor((double)ans1/(double)sum)<=99) normal=1;
}
if(s[i][j][0]=='E')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(sum>maxx&&sum<=99)
{
maxx=sum;
ans2=j;
}
if(sum==maxx)
{
char last=s[i][ans2][0];
if(check1('E',last)) ans2=j;
}
if(sum<=99) normal=1;
}
}
if(!normal)
{
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='P')
{
maxx=ans1;
ans2=j;
break;
}
if(s[i][j][0]=='T')
{
char last=s[i][ans2][0];
if(last=='P') continue;
maxx=ans1;
ans2=j;
}
if(s[i][j][0]=='D'&&s[i][j][1]=='O')
{
if(ans2!=0) continue;
maxx=ans1;
ans2=j;
}
}
}
if(ans2==0)
{
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
puts(" lost the game.");
m--;
if(m>0)
{
tot++;
cout<<"Round "<<tot<<':'<<endl;
}
ans1=0,now=i-1,flag=0,turn=0;
for(int j=1;j<=3;j++)
s[i][j]=q[head],
head++;
if(m>0) go();
if(m<=0) exit(0);
return ;
}
else
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go_turn();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
}
}
}
now=0;
if(m>0) go();
}
void go_turn()
{
if(m<=0) exit(0);
for(int i=now-1;i>=1;i--)
{
if(!flag)
{
int maxx=-0x3f3f3f3f; ans2=0;
bool normal=0;
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='A')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1+sum>maxx&&ans1+sum<=99)
{
maxx=ans1+sum;
ans2=j;
}
if(ans1+sum==maxx)
{
char last=s[i][ans2][0];
if(check1('A',last)) ans2=j;
}
if(ans1+sum<=99) normal=1;
}
if(s[i][j][0]=='B')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1-sum>maxx&&ans1-sum<=99)
{
maxx=ans1-sum;
ans2=j;
}
if(ans1-sum==maxx)
{
char last=s[i][ans2][0];
if(check1('B',last)) ans2=j;
}
if(ans1-sum<=99) normal=1;
}
if(s[i][j][0]=='C')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1*sum>maxx&&ans1*sum<=99)
{
maxx=ans1*sum;
ans2=j;
}
if(ans1*sum==maxx)
{
char last=s[i][ans2][0];
if(check1('C',last)) ans2=j;
}
if(ans1*sum<=99) normal=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]!='O')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(floor((double)ans1/(double)sum)>maxx&&floor((double)ans1/(double)sum)<=99)
{
maxx=floor((double)ans1/(double)sum);
ans2=j;
}
if(floor((double)ans1/(double)sum)==maxx)
{
char last=s[i][ans2][0];
if(check1('D',last)) ans2=j;
}
if(floor((double)ans1/(double)sum)<=99) normal=1;
}
if(s[i][j][0]=='E')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(sum>maxx&&sum<=99)
{
maxx=sum;
ans2=j;
}
if(sum==maxx)
{
char last=s[i][ans2][0];
if(check1('E',last)) ans2=j;
}
if(sum<=99) normal=1;
}
}
if(!normal)
{
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='P')
{
maxx=ans1;
ans2=j;
break;
}
if(s[i][j][0]=='T')
{
char last=s[i][ans2][0];
if(last=='P') continue;
maxx=ans1;
ans2=j;
}
if(s[i][j][0]=='D'&&s[i][j][1]=='O')
{
if(ans2!=0) continue;
maxx=ans1;
ans2=j;
}
}
}
if(ans2==0)
{
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
puts(" lost the game.");
m--;
if(m>0)
{
tot++;
cout<<"Round "<<tot<<':'<<endl;
}
ans1=0,now=i-1,flag=0,turn=0;
for(int j=1;j<=3;j++)
s[i][j]=q[head],
head++;
if(m>0) go();
if(m<=0) exit(0);
return ;
}
else
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
}
}
else
{
int maxx=0x3f3f3f3f; ans2=0;
bool spe=0,normal=0;
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='P')
{
maxx=ans1;
ans2=j;
spe=1;
break;
}
if(s[i][j][0]=='T')
{
char last=s[i][ans2][0];
if(last=='P') continue;
maxx=ans1;
ans2=j;
spe=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]=='O')
{
if(ans2!=0) continue;
maxx=ans1;
ans2=j;
spe=1;
}
}
if(spe==1)
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
continue;
}
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='A')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1+sum<maxx&&ans1+sum<=99)
{
maxx=ans1+sum;
ans2=j;
}
if(ans1+sum==maxx)
{
char last=s[i][ans2][0];
if(check2('A',last)) ans2=j;
}
if(ans1+sum<=99) normal=1;
}
if(s[i][j][0]=='B')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1-sum<maxx&&ans1-sum<=99)
{
maxx=ans1-sum;
ans2=j;
}
if(ans1-sum==maxx)
{
char last=s[i][ans2][0];
if(check2('B',last)) ans2=j;
}
if(ans1-sum<=99) normal=1;
}
if(s[i][j][0]=='C')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1*sum<maxx&&ans1*sum<=99)
{
maxx=ans1*sum;
ans2=j;
}
if(ans1*sum==maxx)
{
char last=s[i][ans2][0];
if(check2('C',last)) ans2=j;
}
if(ans1*sum<=99) normal=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]!='O')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(floor((double)ans1/(double)sum)<maxx&&floor((double)ans1/(double)sum)<=99)
{
maxx=floor((double)ans1/(double)sum);
ans2=j;
}
if(floor((double)ans1/(double)sum)==maxx)
{
char last=s[i][ans2][0];
if(check2('D',last)) ans2=j;
}
if(floor((double)ans1/(double)sum)<=99) normal=1;
}
if(s[i][j][0]=='E')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(sum<maxx&&sum<=99)
{
maxx=sum;
ans2=j;
}
if(sum==maxx)
{
char last=s[i][ans2][0];
if(check2('E',last)) ans2=j;
}
if(sum<=99) normal=1;
}
}
if(ans2==0)
{
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
puts(" lost the game.");
m--;
if(m>0)
{
tot++;
cout<<"Round "<<tot<<':'<<endl;
}
ans1=0,now=i-1,flag=0,turn=0;
for(int j=1;j<=3;j++)
s[i][j]=q[head],
head++;
if(m>0) go();
if(m<=0) exit(0);
return ;
}
else
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
}
maxx=-0x3f3f3f3f,ans2=0;
normal=0;
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='A')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1+sum>maxx&&ans1+sum<=99)
{
maxx=ans1+sum;
ans2=j;
}
if(ans1+sum==maxx)
{
char last=s[i][ans2][0];
if(check1('A',last)) ans2=j;
}
if(ans1+sum<=99) normal=1;
}
if(s[i][j][0]=='B')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1-sum>maxx&&ans1-sum<=99)
{
maxx=ans1-sum;
ans2=j;
}
if(ans1-sum==maxx)
{
char last=s[i][ans2][0];
if(check1('B',last)) ans2=j;
}
if(ans1-sum<=99) normal=1;
}
if(s[i][j][0]=='C')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(ans1*sum>maxx&&ans1*sum<=99)
{
maxx=ans1*sum;
ans2=j;
}
if(ans1*sum==maxx)
{
char last=s[i][ans2][0];
if(check1('C',last)) ans2=j;
}
if(ans1*sum<=99) normal=1;
}
if(s[i][j][0]=='D'&&s[i][j][1]!='O')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(floor((double)ans1/(double)sum)>maxx&&floor((double)ans1/(double)sum)<=99)
{
maxx=floor((double)ans1/(double)sum);
ans2=j;
}
if(floor((double)ans1/(double)sum)==maxx)
{
char last=s[i][ans2][0];
if(check1('D',last)) ans2=j;
}
if(floor((double)ans1/(double)sum)<=99) normal=1;
}
if(s[i][j][0]=='E')
{
int sum=0;
for(int l=1;l<s[i][j].size();l++)
sum=sum*10+s[i][j][l]-'0';
if(sum>maxx&&sum<=99)
{
maxx=sum;
ans2=j;
}
if(sum==maxx)
{
char last=s[i][ans2][0];
if(check1('E',last)) ans2=j;
}
if(sum<=99) normal=1;
}
}
if(!normal)
{
for(int j=1;j<=3;j++)
{
if(s[i][j][0]=='P')
{
maxx=ans1;
ans2=j;
break;
}
if(s[i][j][0]=='T')
{
char last=s[i][ans2][0];
if(last=='P') continue;
maxx=ans1;
ans2=j;
}
if(s[i][j][0]=='D'&&s[i][j][1]=='O')
{
if(ans2!=0) continue;
maxx=ans1;
ans2=j;
}
}
}
if(ans2==0)
{
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
puts(" lost the game.");
m--;
if(m>0)
{
tot++;
cout<<"Round "<<tot<<':'<<endl;
}
ans1=0,now=i-1,flag=0,turn=0;
for(int j=1;j<=3;j++)
s[i][j]=q[head],
head++;
if(m>0) go();
if(m<=0) exit(0);
return ;
}
else
{
ans1=maxx;
for(int j=0;j<name[i].size();j++)
cout<<name[i][j];
cout<<" used ";
for(int j=0;j<s[i][ans2].size();j++)
cout<<s[i][ans2][j];
cout<<",now p="<<ans1<<'.'<<endl;
if(s[i][ans2][0]=='T')
{
turn^=1;
now=i;
s[i][ans2]=q[head];
head++;
go();
}
if(s[i][ans2][0]=='D'&&s[i][ans2][1]=='O')
flag=1;
s[i][ans2]=q[head];
head++;
if(normal) flag=0;
}
}
}
now=n+1;
if(m>0) go_turn();
}
signed main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
read(n),read(m),read(k);
for(int i=1;i<=n;i++)
{
cin>>name[i];
for(int j=1;j<=3;j++)
cin>>s[i][j];
}
for(int i=1;i<=k;i++) cin>>q[i];
head=1;
puts("Round 1:"),tot=1;
while(m)
{
if(!turn) now=0,go();
else now=n+1,go_turn();
}
}
T2 mine
经典线性 DP,赛时没时间打了。
定义:
- \(f_{i,0}\) 表示 \(s_i\) 不是雷,\(s_{i+1}\) 也不是雷。
- \(f_{i,1}\) 表示 \(s_i\) 不是雷,\(s_{i+1}\) 是雷。
- \(f_{i,2}\) 表示 \(s_i\) 是雷,\(s_{i+1}\) 不是雷。
- \(f_{i,3}\) 表示 \(s_i\) 是雷,\(s_{i+1}\) 也是雷。
转移:
初始值 \(f_{0,0}=f_{0,1}=1\),一直转移到 \(f_{n-1}\),对于 \(f_n\) 的情况进行分讨。
答案:
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define sort stable_sort
using namespace std;
const int N=1e6+10,P=1e9+7;
template<typename Tp> inline void read(Tp&x)
{
x=0;register bool z=true;
register char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') z=0;
for(;'0'<=c&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x=(z?x:~x+1);
}
void wt(int x){if(x>9)wt(x/10);putchar((x%10)+'0');}
void write(int x){if(x<0)putchar('-'),x=~x+1;wt(x);}
char s[N];
int f[N][5],n,ans;
signed main()
{
cin>>(s+1);
n=strlen(s+1);
f[0][0]=f[0][1]=1;
for(int i=1;i<=n-1;i++)
{
if(s[i]=='0')
f[i][0]=f[i-1][0];
if(s[i]=='1')
f[i][0]=f[i-1][2],
f[i][1]=f[i-1][0];
if(s[i]=='2')
f[i][1]=f[i-1][2];
if(s[i]=='*')
f[i][2]=(f[i-1][1]+f[i-1][3])%P,
f[i][3]=(f[i-1][1]+f[i-1][3])%P;
if(s[i]=='?')
f[i][0]=(f[i-1][0]+f[i-1][2])%P,
f[i][1]=(f[i-1][0]+f[i-1][2])%P,
f[i][2]=(f[i-1][1]+f[i-1][3])%P,
f[i][3]=(f[i-1][1]+f[i-1][3])%P;
}
if(s[n]=='0') ans=f[n-1][0];
if(s[n]=='1') ans=f[n-1][2];
if(s[n]=='2') ans=0;
if(s[n]=='*') ans=(f[n-1][1]+f[n-1][3])%P;
if(s[n]=='?') ans=(f[n-1][0]+f[n-1][1]+f[n-1][2]+f[n-1][3])%P;
write(ans);
}
T3 小凯的疑惑
弱化版结论:当 \(\gcd(x,y)=1\) 时其无法组成的最大数为 \(xy-x-y\),虽然此题没什么用。
定义 \(ax+by=c\)。
对于 \(\gcd(x,y)\ne 1\) 时,因为有 \(c\) 定为 \(\gcd(x,y)\) 的非负整数倍,故此有无数个。
对于 \(y\) 的完全剩余系 \([0,y-1]\),若有 \([a_1,a_n]\) 构成其完全剩余系,且 \(\gcd(x,y)=1\),有 \([a_1·x,a_n·x]\) 同样构成其完全剩余系,故考虑每个 \(a_i·x\) 即可覆盖所有情况。
定义 \(p=ax\bmod y\),只有在 \(p\) 第一次出现之前的情况才可能无法被凑出,因为对于后来出现的 \(p\) 定能用 \((ax+by)\bmod y\) 表示。
不妨设 \(ax-by=c\) 以统计不合法的 \(b\) 的数量,显然有 \(b\in [1,\lfloor\dfrac{ax}{y}\rfloor]\),即 \(\lfloor\dfrac{ax}{y}\rfloor\) 个。
那么答案为 \(\sum\limits_{a=0}^{y-1}\lfloor\dfrac{ax}{y}\rfloor\)。
此时暴力已经可以跑过了,但式子还可以化简:
T4 春节十二响
对于以 \(x\) 为根的子树,以其子节点为根的子树之间是可以合并的,从贪心的角度,将大的与大的合并,小的与小的合并一定是最优的,故维护一个堆,每次取两个堆的堆首合并,使用启发式合并使复杂度优化为 \(O(n\log(n))\)。
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define sort stable_sort
using namespace std;
const int N=2e5+10;
template<typename Tp> inline void read(Tp&x)
{
x=0;register bool z=true;
register char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') z=0;
for(;'0'<=c&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x=(z?x:~x+1);
}
void wt(int x){if(x>9)wt(x/10);putchar((x%10)+'0');}
void write(int x){if(x<0)putchar('-'),x=~x+1;wt(x);}
int n,a[N],ans;
priority_queue<int>q[N],ls;
vector<int>e[N];
void merge(int x,int y)
{
if(q[x].size()<q[y].size()) swap(q[x],q[y]);
while(!q[y].empty())
ls.push(max(q[x].top(),q[y].top())),
q[x].pop(),q[y].pop();
while(!ls.empty())
q[x].push(ls.top()),
ls.pop();
}
void dfs(int x)
{
for(int y:e[x])
dfs(y),
merge(x,y);
q[x].push(a[x]);
}
signed main()
{
read(n);
for(int i=1;i<=n;i++) read(a[i]);
for(int i=2,x;i<=n;i++)
read(x),
e[x].push_back(i);
dfs(1);
while(!q[1].empty())
ans+=q[1].top(),
q[1].pop();
write(ans);
}
总结
不要再把时间浪费在大模拟上了,大模拟注意细节,好好读题,还有整形除法向 \(0\) 取整的问题。