2021牛客多校二(补题)

I.Penguins

可爱的企鹅竟然都不配被讲~ 可恶啊 ~
题意:问同时到给定点的最短路,并且输出他们的最短路径和行走方向~且两边的点都是镜像的 左右刚好是反的
思路:从学姐代码里学到的设立一个四维的dis的数组,然后写一个bfs按照字典序的顺序设立它的上下左右,加一个记录路径的数组,再回溯一下,然后随便搞一下,答案大概就出来啦~

#include<bits/stdc++.h>
using namespace std;
int INF = 0x3f3f3f3f;
char mp1[25][25];
char mp2[25][25];
int dis[25][25][25][25];
int vis[25][25][25][25];
int n = 20;
int dx1[4] = { 1,0,0,-1 };
int dy1[4] = { 0,-1,1,0 };
int dx2[4] = { 1,0,0,-1 };
int dy2[4] = { 0,1,-1,0 };
struct point {
	int x1, y1, x2, y2;
};
point path[25][25][25][25];
int pre[25][25][25][25];
struct node {
	int x1, y1, x2, y2;
};
void bfs(int sx1, int sy1, int sx2, int sy2) {
	queue<node>qwq;
	qwq.push({ sx1,sy1,sx2,sy2 });
	dis[sx1][sy1][sx2][sy2] = 0;
	while (!qwq.empty()) {
		node now = qwq.front();
		qwq.pop();
		int x1 = now.x1, x2 = now.x2;
		int y1 = now.y1, y2 = now.y2;
		if (vis[x1][y1][x2][y2]) continue;
		vis[x1][y1][x2][y2] = 1;
		for (int i = 0; i < 4; i++) {
			int xx1 = x1 + dx1[i];
			int yy1 = y1 + dy1[i];
			int xx2 = x2 + dx2[i];
			int yy2 = y2 + dy2[i];
			if (xx1 == 0) xx1 = 1;
			if (xx1 == n + 1) xx1 = n;
			if (xx2 == 0) xx2 = 1;
			if (xx2 == n + 1) xx2 = n;
			if (yy1 == 0) yy1 = 1;
			if (yy1 == n + 1) yy1 = n;
			if (yy2 == 0) yy2 = 1;
			if (yy2 == n + 1) yy2 = n;
			if (mp1[xx1][yy1] == '#') xx1 = x1, yy1 = y1;
			if (mp2[xx2][yy2] == '#') xx2 = x2, yy2 = y2;
			if (dis[xx1][yy1][xx2][yy2] > dis[x1][y1][x2][y2] + 1) {
				qwq.push({ xx1,yy1,xx2,yy2 });
				dis[xx1][yy1][xx2][yy2] = dis[x1][y1][x2][y2] + 1;
				pre[xx1][yy1][xx2][yy2] = i;
				path[xx1][yy1][xx2][yy2] = point{ x1,y1,x2,y2 };
			}
		}
	}
}
char fx[4] = { 'D','L','R','U' };
void print(int x1, int y1, int x2, int y2) {
	mp1[x1][y1] = 'A';
	mp2[x2][y2] = 'A';
	if (x1 == 20 && y1 == 20 && x2 == 20 && y2 == 1) {
	     return;
     }
	int num = pre[x1][y1][x2][y2];
	point p = path[x1][y1][x2][y2];
	print(p.x1, p.y1, p.x2, p.y2);
	cout << fx[num];
}
int main() {
	for (int i = 1; i <= 20; i++) {
		for (int j = 1; j <= 41; j++) {
			if (j > 21) {
				cin >> mp2[i][j - 21];
			}
			else if (j == 21) getchar();
			else {
				cin >> mp1[i][j];
			}
		}
	}
	memset(dis, INF, sizeof(dis));
	//	cout << dis[1][1][1][1] << endl;
	bfs(20, 20, 20, 1);
	cout << dis[1][20][1][1] << endl;
	print(1, 20, 1, 1);
	cout << endl;
	for (int i = 1; i <= 20; i++) {
		for (int j = 1; j <= 41; j++) {
			if (j > 21) cout << mp2[i][j - 21];
			else if (j == 21) cout << " ";
			else cout << mp1[i][j];
		}
		cout << endl;
	}
	return 0;
}

F.Girlfriend

思路:根据题目所给的公式,可以画出这个两个球,并且求出这两个球的相交体积,所以首先需要求出两个球心的坐标和半径,然后根据两球坐标确定两球位置关系,最后通过公式来求出相关体积。

#include<bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int t;
struct node {
	double x, y, z, r;
}c1, c2;
double x[5], y[5], z[5], k1, k2;
double get_area(node c1, node c2) {
	double ans = 0;
	double d = sqrt((c1.x - c2.x) * (c1.x - c2.x) + (c1.y - c2.y) * (c1.y - c2.y) + (c1.z - c2.z) * (c1.z - c2.z)); //两球球心距离
	if (d >= c1.r + c2.r) { //两球相切或相离 
		ans = 0;
	}
	else if (d + c1.r <= c2.r) { //两球内含或内切 
		ans = (4.0 / 3.0) * PI * c1.r * c1.r * c1.r;
	}
	else if (d + c2.r <= c1.r) {
		ans = (4.0 / 3.0) * PI * c2.r * c2.r * c2.r;
	}
	else { //两球相交
		double h1 = c1.r - (c1.r * c1.r - c2.r * c2.r + d * d) / (2.0 * d); //c1拱高 
		ans += (1.0 / 3.0) * PI * h1 * h1 * (3.0 * c1.r - h1); //c1部分球冠体积 
		double h2 = c2.r - (c2.r * c2.r - c1.r * c1.r + d * d) / (2.0 * d);//c2拱高 
		ans += (1.0 / 3.0) * PI * h2 * h2 * (3.0 * c2.r - h2);//c2部分球冠体积
	}
	return ans;
}
int main() {
	cin >> t;
	while (t--) {
		for (int i = 1; i <= 4; i++) {
			cin >> x[i] >> y[i] >> z[i];
		}
		cin >> k1 >> k2;
		c1.x = (k1 * k1 * x[2] - x[1]) * 1.0 / (k1 * k1 - 1) * 1.0;
		c1.y = (k1 * k1 * y[2] - y[1]) * 1.0 / (k1 * k1 - 1) * 1.0;
		c1.z = (k1 * k1 * z[2] - z[1]) * 1.0 / (k1 * k1 - 1) * 1.0;
		double tmp = x[1] * x[1] + y[1] * y[1] + z[1] * z[1] - k1 * k1 * (x[2] * x[2] + y[2] * y[2] + z[2] * z[2]);
		c1.r = sqrt(c1.x * c1.x + c1.y * c1.y + c1.z * c1.z + tmp / (k1 * k1 - 1));

		c2.x = (k2 * k2 * x[4] - x[3]) * 1.0 / (k2 * k2 - 1) * 1.0;
		c2.y = (k2 * k2 * y[4] - y[3]) * 1.0 / (k2 * k2 - 1) * 1.0;
		c2.z = (k2 * k2 * z[4] - z[3]) * 1.0 / (k2 * k2 - 1) * 1.0;
		tmp = x[3] * x[3] + y[3] * y[3] + z[3] * z[3] - k2 * k2 * (x[4] * x[4] + y[4] * y[4] + z[4] * z[4]);
		c2.r = sqrt(c2.x * c2.x + c2.y * c2.y + c2.z * c2.z + tmp / (k2 * k2 - 1));


		printf("%.4lf\n", get_area(c1, c2));
	}
	return 0;
}



开心今天又补拉两道签到~

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值