# 2021牛客暑期多校训练营2

2021/7/21 13:42:21 浏览：

K

``````#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;

int b[N], a[N];

int main()
{
int n, m;
cin >> n >> m;
while(m--)
{
int d,dd;
cin >> d >> dd;
b[d] = dd;
}
for(int i = 1; i <= n; i++)
{
if(!b[i])
b[i] = b[i-1]+1;
if(b[i] > b[i-1]+1)
{
puts("-1");
return 0;
}
}

int cnt = 0;
stack<int> s;
for(int i = n; i > 0; i--)
{
while(b[i] > (int)s.size())
{s.push(++cnt);}
a[i] = s.top();
s.pop();
}
for(int i = 1; i <= n; i++)
cout << a[i] << ' ';
cout << "\n";
return 0;
}
``````

F

``````#include <bits/stdc++.h>
#define INF 99999999
#define LINF LLONG_MAX
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=1;
const double pi = acos(-1);

int T;
double x[5],y[5],z[5];
double k1,k2;

void solve(double x1,double y1,double z1,double r1,double x2,double y2,double z2,double r2){
double ans=0;
//球心距离
double dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
//相离或相切
if(dis>=r1+r2){
ans=0;
}
//内含或内切
else if (dis+r1<=r2){
ans=(4.00/3.00)*pi*r1*r1*r1;
}
else if(dis+r2<=r1){
ans=(4.00/3.00)*pi*r2*r2*r2;
}
//相交
else{
double cal=(r1*r1+dis*dis-r2*r2)/(2.00*dis*r1);
double h=r1*(1-cal);
ans+=(1.00/3.00)*pi*(3.00*r1-h)*h*h;
cal=(r2*r2+dis*dis-r1*r1)/(2.00*dis*r2);
h=r2*(1.00-cal);
ans+=(1.00/3.00)*pi*(3.00*r2-h)*h*h;
}
printf("%.3f\n",ans);
}

int main(){
cin>>T;
while(T--){
for(int i=0;i<4;i++)
cin>>x[i]>>y[i]>>z[i];
cin>>k1>>k2;
//计算球1的球心坐标和半径
double xishu1=k1*k1-1;
double c1x,c1y,c1z,c1r,t;
c1x=(k1*k1*x[1]-x[0])/xishu1;
c1y=(k1*k1*y[1]-y[0])/xishu1;
c1z=(k1*k1*z[1]-z[0])/xishu1;
t=k1*k1*((x[1]*x[1])+(y[1]*y[1])+(z[1]*z[1]))-x[0]*x[0]-y[0]*y[0]-z[0]*z[0];
t/=xishu1;
c1r=sqrt(c1x*c1x+c1y*c1y+c1z*c1z-t);
//计算球2的球心坐标和半径
double xishu2=k2*k2-1;
double c2x,c2y,c2z,c2r;
c2x=(k2*k2*x[3]-x[2])/xishu2;
c2y=(k2*k2*y[3]-y[2])/xishu2;
c2z=(k2*k2*z[3]-z[2])/xishu2;
t=k2*k2*((x[3]*x[3])+(y[3]*y[3])+(z[3]*z[3]))-x[2]*x[2]-y[2]*y[2]-z[2]*z[2];
t/=xishu2;
c2r=sqrt(c2x*c2x+c2y*c2y+c2z*c2z-t);
//计算两个球相交部分体积
solve(c1x,c1y,c1z,c1r,c2x,c2y,c2z,c2r);
}
return 0;
}
``````

I

``````#include <bits/stdc++.h>

using namespace std;

string ans;
int flag;
char c1[30][30], c2[30][30];
int vis[25][25][25][25];
int now[25][25][25][25][5];
string p = "DLRU";
int tx1[] = {1,0,0,-1}, ty1[] = {0,-1,1,0}, tx2[] = {1,0,0,-1}, ty2[] = {0,1,-1,0};
struct no
{
int x1,y1,x2,y2;
};

queue<no> q;

int check(int a, int b)
{
if((a+b)<1 || (a+b)>20)
return a;
return a+b;
}

void put()
{
cout << vis[1][20][1][1]-1 << endl;
reverse(ans.begin(), ans.end());
cout << ans << endl;
c1[20][20]='A';
c2[20][1]='A';
for(int i = 1; i <= 20; i++)
{
printf("%s ",c1[i]+1);
printf("%s\n",c2[i]+1);
}
}

int main()
{
for(int i = 1; i <= 20; i++)
{
scanf("%s",c1[i]+1);
scanf("%s",c2[i]+1);
}
vis[20][20][20][1]=1;
q.push({20,20,20,1});
while(!q.empty())
{
auto t = q.front();
q.pop();
for(int i = 0; i < 4; i++)
{
int xx1 = check(t.x1 , tx1[i]);
int yy1 = check(t.y1 , ty1[i]);
int xx2 = check(t.x2 , tx2[i]);
int yy2 = check(t.y2 , ty2[i]);
if(c1[xx1][yy1] == '#')
{
xx1 -= tx1[i];
yy1 -= ty1[i];
}
if(c2[xx2][yy2] == '#')
{
xx2 -= tx2[i];
yy2 -= ty2[i];
}
if(vis[xx1][yy1][xx2][yy2])
continue;
q.push({xx1,yy1,xx2,yy2});
vis[xx1][yy1][xx2][yy2] = vis[t.x1][t.y1][t.x2][t.y2]+1;
now[xx1][yy1][xx2][yy2][0] = i;
now[xx1][yy1][xx2][yy2][1] = t.x1;
now[xx1][yy1][xx2][yy2][2] = t.y1;
now[xx1][yy1][xx2][yy2][3] = t.x2;
now[xx1][yy1][xx2][yy2][4] = t.y2;
if(xx1 == 1 && yy1 == 20 && xx2 == 1 && yy2 == 1)
{
int a = xx1, b = yy1, c = xx2, d = yy2;
while(a != 20 || b!= 20 || c != 20 || d != 1)
{
c1[a][b]=c2[c][d]='A';
ans += p[now[a][b][c][d][0]];
int a1 = now[a][b][c][d][1];
int b1 = now[a][b][c][d][2];
int c1 = now[a][b][c][d][3];
int d1 = now[a][b][c][d][4];
a=a1,b=b1,c=c1,d=d1;
}
put();
flag = 1;
break;
}
}
}
if(!flag)
puts("-1");
return 0;
}
``````