2021牛客暑期多校训练营2
不要问为什么2在3后 gugugu
2021-07-19 12:00:00 至 2021-07-19 17:00:00
C--Draw Grids
题意: 在给定范围坐标点内,一人画一条 长度为1 的线,并且所画的线不能围成多边形,问谁先能让对方画不了则胜利
博弈题,找规律,发现最多可以画n*m-1条线,找奇偶即可
#include <bits/stdc++.h>
#define ri int
typedef int lll;
typedef long long ll;
using namespace std;
const ll mod=80112002;
const ll inf=999999999;
const ll N=5e4+5;
ll t;
ll n,m;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> m;
ll ans=n*m-1;
if(ans&1) cout << "YES\n";
else cout << "NO\n";
return 0;
}
D--Er Ba Game
题意: 一款"二八游戏",每人拿两张卡片,看谁能赢(或者平局)
纯模拟题,一步步判断就完了 debug一小时
#include <bits/stdc++.h>
#define ri int
typedef int lll;
typedef long long ll;
using namespace std;
const ll mod=80112002;
const ll inf=999999999;
const ll N=5e4+5;
ll t;
ll a[3],b[3];
void print(ll x)
{
if(x==1) cout << "first\n";
else if(x==2) cout << "second\n";
else cout << "tie\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> t;
while(t--)
{
for(ri i=1;i<=2;i++) cin >> a[i] >> b[i];
for(ri i=1;i<=2;i++) if(b[i]<a[i]) swap(a[i],b[i]);
ll ans[3]={0};
ans[1]=(a[1]+b[1])%10;
ans[2]=(a[2]+b[2])%10;
if(a[1]==2&&b[1]==8 || a[2]==2&&b[2]==8)
{
if(a[2]==a[1]&&b[2]==b[1]) print(3);
else if(a[1]==2&&b[1]==8) print(1);
else print(2);
}
else if(a[1]==b[1] || a[2]==b[2])
{
if(a[2]!=b[2]) print(1);
else if(a[1]!=b[1]) print(2);
else print(3);
}
else if(a[1]==b[1]&&a[2]==b[2])
{
if(a[1]>a[2]) print(1);
else if(a[1]==a[2]) print(3);
else print(2);
}
else if(a[1]!=b[1]&&a[2]!=b[2])
{
if(ans[1]>ans[2]) print(1);
else if(ans[1]<ans[2]) print(2);
else
{
if(b[1]>b[2]) print(1);
else if(b[1]==b[2]) print(3);
else print(2);
}
}
}
return 0;
}
F--Girlfriend
题意: 给出A,B,C,D坐标要求计算限制条件下P1,P2两点的合法空间的相交部分体积.
纯纯的立体几何数学题 几何题 贪心 √,转化成两球体的位置关系,推出公式即可 恶心人
#include <bits/stdc++.h>
#define ri int
using namespace std;
typedef long long lll ;
typedef int ll;
const double PI=acos(-1);
ll t;
double ans=0;
double xa,ya,za,xb,yb,zb,xc,yc,zc,xd,yd,zd,k1,k2,a1,b1,c1,d1,a2,b2,c2,d2,t1,t2,r1,r2;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>t;
while(t--)
{
cin>>xa>>ya>>za>>xb>>yb>>zb>>xc>>yc>>zc>>xd>>yd>>zd>>k1>>k2;
t1=k1*k1-1,t2=k2*k2-1;
a1=(k1*k1*xb-xa)/t1;
b1=(k1*k1*yb-ya)/t1;
c1=(k1*k1*zb-za)/t1;
d1=(k1*k1*(xb*xb+yb*yb+zb*zb)-(xa*xa+ya*ya+za*za))/t1;
r1=sqrt(a1*a1+b1*b1+c1*c1-d1);
a2=(k2*k2*xd-xc)/t2;
b2=(k2*k2*yd-yc)/t2;
c2=(k2*k2*zd-zc)/t2;
d2=(k2*k2*(xd*xd+yd*yd+zd*zd)-(xc*xc+yc*yc+zc*zc))/t2;
r2=sqrt(a2*a2+b2*b2+c2*c2-d2);
double dis=sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)+(c1-c2)*(c1-c2));
if(dis>=r1+r2) ans=0;
else if(dis+r1<=r2) ans=(4.0/3.0)*PI*r1*r1*r1;
else if(dis+r2<=r1) ans=(4.0/3.0)*PI*r2*r2*r2;
else
{
double dr1=(r1*r1+dis*dis-r2*r2)/(2.0*dis*r1);
double h1=r1-r1*dr1;
ans+=PI*h1*h1*(r1-h1/3.0);
double dr2=(r2*r2+dis*dis-r1*r1)/(2.0*dis*r2);
double h2=r2-r2*dr2;
ans+=(PI*h2*h2*(r2-h2/3.0));
}
cout << ans << '\n';
}
return 0;
}
I--Penguins
题意: 两只企鹅走迷宫,走到相应点的最短距离,两只企鹅对称。
bfs,dfs都行,暴力求解就行,注意内存和小细节 不注意debug一整天
#include <bits/stdc++.h>
#define ri int
using namespace std;
typedef long long lll ;
typedef int ll;
ll dx[4]={1,0,0,-1};
ll dy[2][4]={0,-1,1,0,0,1,-1,0};
char m1[25][25];
char m2[25][25];
char op[4]={'D','L','R','U'};
ll f[25][25][25][25];
char ans[4004];
ll num=0;
struct node{
int x1,y1,x2,y2;
node(int a,int b,int c,int d):x1(a),y1(b),x2(c),y2(d){}
node(){ }
};
node pre[25][25][25][25]; //开四维
queue<node> q;
int vis[25][25][25][25];
void bfs()
{
memset(vis,0x3f3f3f,sizeof(vis));
vis[20][20][20][1]=0;
q.push(node(20,20,20,1));
while(!q.empty())
{
node p=q.front();
q.pop();
int tv=vis[p.x1 ][p.y1 ][p.x2 ][p.y2 ];
for(ri i=0;i<4;i++)
{
ll tx1=p.x1+dx[i],ty1=p.y1+dy[0][i];
ll tx2=p.x2+dx[i],ty2=p.y2+dy[1][i];
if(m1[tx1][ty1]!='.')
{
tx1=p.x1;
ty1=p.y1 ;
}
if(m2[tx2][ty2]!='.')
{
tx2=p.x2;
ty2=p.y2;
}
if(tv+1<vis[tx1][ty1][tx2][ty2])
{
vis[tx1][ty1][tx2][ty2]=tv+1;
pre[tx1][ty1][tx2][ty2]=node(p.x1,p.y1,p.x2,p.y2 );
f[tx1][ty1][tx2][ty2]=i;
q.push(node(tx1,ty1,tx2,ty2));
}
}
}
return;
}
void solve(node s)
{
node t=pre[s.x1 ][s.y1 ][s.x2 ][s.y2 ];
m1[s.x1 ][s.y1 ]='A';
m2[s.x2 ][s.y2 ]='A';
if(s.x1==20&&s.y1==20&&s.x2==20&&s.y2==1) return ;
solve(t);
ans[num++]=op[f[s.x1][s.y1 ][s.x2 ][s.y2 ]];
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
for(ri i=1;i<=20;i++) scanf("%s%s",m1[i]+1,m2[i]+1);
bfs();
solve(node(1,20,1,1));
printf("%d\n%s\n",num,ans);
for(int i=1;i<=20;i++)
printf("%s %s\n",m1[i]+1,m2[i]+1);
return 0;
}
K--Stack
题意:
有a,b两个序列按照以下方式构造:
Stk is an empty stack
for i = 1 to n :
while ( Stk is not empty ) and ( Stk's top > a[i] ) :
pop Stk
push a[i]
b[i]=Stk's size
现在给出b序列的部分,请找出a序列,找不到输出-1
发现b序列可以直接全部构造出来,直接将构造代码逆向构造出a序列即可
#include <bits/stdc++.h>
#define ri int
typedef int lll;
typedef long long ll;
using namespace std;
const ll mod=80112002;
const ll inf=999999999;
const ll N=5e4+5;
ll t;
ll n,k;
ll p,x;
ll b[1000005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> k;
while(k--)
{
cin >> p >> x;
b[p]=x;
}
for(ri i=1;i<=n;i++)
{
if(!b[i]) b[i]=b[i-1]+1;
else
{
if(b[i]>b[i-1]+1)
{
cout << "-1\n";
return 0;
}
}
}
stack<ll> s,ans;
ll max=0;
for(ri i=n;i>=1;i--)
{
while(b[i]>s.size()) s.push(++max);
ans.push(s.top());s.pop();
}
while(!ans.empty())
{
cout << ans.top() << ' ';
ans.pop();
}
return 0;
}