社区讨论

20pts求救

P1650田忌赛马参与者 2已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lo7xa1us
此快照首次捕获于
2023/10/27 09:16
2 年前
此快照最后确认于
2023/10/27 09:16
2 年前
查看原帖
CPP
#include<queue>
#include<>
#include<iostream>
#include<algorithm>
using namespace std;

int n,ans;
int T[2010],Q[2010];
inline int read() {
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9') {
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9') {
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}
bool cmp(int x,int y) {
	return x < y;
}
deque <int> q1;
deque <int> q2;

int main() {

	n = read();
	for(int i = 1 ; i <= n ; i ++)
		T[i] = read();
	for(int i = 1 ; i <= n ; i ++)
		Q[i] = read();
	sort(T + 1,T + 1 + n,cmp);
	sort(Q + 1,Q + 1 + n,cmp);
	for(int i = 1 ; i <= n ; i ++) {
		q1.push_back(T[i]);
		q2.push_back(Q[i]);
	}
	while(!q1.empty()) {
		int x1 = q1.front(),x2 = q2.front();
		int y1 = q1.back(),y2 = q2.back();
//		cout << x1 << ' ' << x2 << endl;
		if(x1 > x2) {
			q1.pop_front();
			q2.pop_front();
			ans += 200;
		} else if(x1 < x2) {
			q1.pop_front();
			q2.pop_back();
			ans -= 200;
		} else {
			if(y1 > y2) {
				q1.pop_back();
				q2.pop_back();
				ans += 200;
			} else if(y1 < y2) {
				q1.pop_front();
				q2.pop_back();
				ans -= 200;
			} else {
				q1.pop_front();
				q2.pop_back();
				ans -= 200;
			}
		}
	}
	cout << ans;

	return 0;
}
// 92
// 87 
// -200 + 200 + 200

回复

3 条回复,欢迎继续交流。

正在加载回复...