2021牛客暑期多校训练营2
Draw Grids
#include <iostream>
using namespace std;
int n, m;
int main()
{
cin >> n >> m;
if (n*m%2==1) cout<<"NO\n";
else cout<<"YES\n";
return 0;
}
Er Ba Game
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;cin>>t;
while(t--)
{
int a1,b1,a2,b2;
cin>>a1>>b1>>a2>>b2;
if(a1>b1)swap(a1,b1);
if(a2>b2)swap(a2,b2);
if(a1==2&&b1==8&&a2==2&&b2==8)cout<<"tie"<<endl;
else if(a1==2&&b1==8)cout<<"first"<<endl;
else if(a2==2&&b2==8)cout<<"second"<<endl;
else
{
if(a1==b1&&a2==b2)//如果都是对子
{
if(a1>a2)cout<<"first"<<endl;
else if(a1<a2)cout<<"second"<<endl;
else cout<<"tie"<<endl;
}
else if(a1==b1)cout<<"first"<<endl;
else if(a2==b2)cout<<"second"<<endl;
else//如果都不是对子
{
if((a1+b1)%10==(a2+b2)%10)
{
if(b1>b2)cout<<"first"<<endl;
else if(b1<b2)cout<<"second"<<endl;
else cout<<"tie"<<endl;
}
else
{
if((a1+b1)%10>(a2+b2)%10)cout<<"first"<<endl;
else if((a1+b1)%10<(a2+b2)%10)cout<<"second"<<endl;
else cout<<"tie"<<endl;
}
}
}
}
}
Girlfriend
思路
其实就是阿波罗尼斯球+求两个球的体积并
#include<bits/stdc++.h>
using namespace std;
double PI = acos(-1.0);
int main()
{
int t;cin>>t;
while(t--)
{
double a1,b1,c1,d1,e1,f1,a2,b2,c2,d2,e2,f2;
cin>>a1>>b1>>c1>>d1>>e1>>f1>>a2>>b2>>c2>>d2>>e2>>f2;
double k1,k2;cin>>k1>>k2;
//将球化成一般方程
double A1=(2*a1-2*d1*k1*k1)/(k1*k1-1);
double B1=(2*b1-2*e1*k1*k1)/(k1*k1-1);
double C1=(2*c1-2*f1*k1*k1)/(k1*k1-1);
double D1=(k1*k1*(d1*d1+e1*e1+f1*f1)-(a1*a1+b1*b1+c1*c1))/(k1*k1-1);
//求出圆心坐标
double rx1,ry1,rz1;
rx1=-A1/2;
ry1=-B1/2;
rz1=-C1/2;
//求出半径
double r1=sqrt((A1*A1+B1*B1+C1*C1-4*D1)/4);
double A2=(2*a2-2*d2*k2*k2)/(k2*k2-1);
double B2=(2*b2-2*e2*k2*k2)/(k2*k2-1);
double C2=(2*c2-2*f2*k2*k2)/(k2*k2-1);
double D2=(k2*k2*(d2*d2+e2*e2+f2*f2)-(a2*a2+b2*b2+c2*c2))/(k2*k2-1);
double rx2,ry2,rz2;
rx2=-A2/2;
ry2=-B2/2;
rz2=-C2/2;
double r2=sqrt((A2*A2+B2*B2+C2*C2-4*D2)/4);
//cout<<rx1<<" "<<ry1<<" "<<rz1<<" "<<r1<<endl;
//cout<<rx2<<" "<<ry2<<" "<<rz2<<" "<<r2<<endl;
//算出两个球心的距离
double dis = sqrt((rx1 - rx2) * (rx1 - rx2) + (ry1 - ry2) * (ry1 - ry2) + (rz1 - rz2) * (rz1 - rz2));
//计算体积并的模版
if (dis >= r1 + r2)
{
printf("0.0000000\n");
}
else if (dis <= fabs(r1 - r2))
{
double maxn = min(r1, r2);
double s = 4.0 / 3.0 * PI * (maxn * maxn * maxn);
printf("%.7lf\n", s);
}
else
{
double s = 0;
double h1 = r1 - (r1 * r1 - r2 * r2 + dis * dis) / (2 * dis);
s += (PI * h1 * h1 * (3 * r1 - h1) / 3.0);
double h2 = r2 - (r2 * r2 - r1 * r1 + dis * dis) / (2 * dis);
s += (PI * h2 * h2 * (3 * r2 - h2) / 3.0);
printf("%.7lf\n", s);
}
}
}
Stack
#include <iostream>
#include <algorithm>
using namespace std;
int b[1000010];
int a[1000010];
int st[1000010];
int main()
{
int n,k;
cin>>n>>k;
for(int i=1;i<=k;i++){
int pos;
cin>>pos>>a[pos];
}
for(int i=1;i<=n;i++){
if(!a[i])a[i]=a[i-1]+1;
else if(a[i]>a[i-1]+1){
cout<<"-1"<<endl;
return 0;
}
}
int cnt=0,top=0;
for(int i=n;i>=1;i--){
while(a[i]>top)st[++top]=++cnt;//++cnt能保证先把小的弹出来再把大的弹出来
b[i]=st[top];
top--;
}
for(int i=1;i<=n;i++)cout<<b[i]<<' ';
return 0;
}
Penguins
#include <bits/stdc++.h>
using namespace std;
struct node{
int x1,y1,x2,y2;
};
queue<node>q;
char a1[30][30];
char a2[30][30];
int d[30][30][30][30];
int dx[]={1,0,0,-1};
int dy[2][4]={0,-1,1,0,0,1,-1,0};
char op[]={'D','L','R','U'};
char p[30][30][30][30];
node pre[30][30][30][30];
char s[1000000];
int ans=0;
void bfs(){
memset(d,0x3f3f,sizeof(d));
d[20][20][20][1]=0;
q.push({20,20,20,1});
while(!q.empty()){
node t=q.front();
int dis=d[t.x1][t.y1][t.x2][t.y2];
q.pop();
for(int i=0;i<4;i++){
int x1=t.x1+dx[i],y1=t.y1+dy[0][i],x2=t.x2+dx[i],y2=t.y2+dy[1][i];
if(a1[x1][y1]!='.')x1-=dx[i],y1-=dy[0][i];
if(a2[x2][y2]!='.')x2-=dx[i],y2-=dy[1][i];
if(dis+1<d[x1][y1][x2][y2]){
d[x1][y1][x2][y2]=dis+1;
pre[x1][y1][x2][y2]={t.x1,t.y1,t.x2,t.y2};
p[x1][y1][x2][y2]=op[i];
q.push({x1,y1,x2,y2});
}
}
}
return;
}
void solve(int x1,int y1,int x2,int y2){
a1[x1][y1]=a2[x2][y2]='A';
node t=pre[x1][y1][x2][y2];
if(x1==20&&y1==20&&x2==20&&y2==1)return;
solve(t.x1,t.y1,t.x2,t.y2);
s[ans++]=p[x1][y1][x2][y2];
return;
}
int main()
{
for(int i=1;i<=20;i++){
scanf("%s%s",a1[i]+1,a2[i]+1);
}
bfs(); solve(1,20,1,1);
cout<<ans<<endl<<s<<endl;
for(int i=1;i<=20;i++){
printf("%s %s\n",a1[i]+1,a2[i]+1);
}
return 0;
}