其他分享
首页 > 其他分享> > P8342 [COCI2021-2022#6] Med 题解

P8342 [COCI2021-2022#6] Med 题解

作者:互联网

题意:

给你 \(n\) 个人,还有他的五场成绩,第六场成绩不知道,但成绩在 \([0,500]\) 中,问每个人的最优和最劣排名。

思路:

简单模拟题。

对于每个人,他的最大排名就是自己拿 \(500\),别人都是 \(0\) 分。

他的最小排名是自己拿 \(0\) 分,别人都是 \(500\) 分。

模拟即可。

AC code:

/*
	Work by: TLE_Automation
*/
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define int long long
using namespace std;

const int N = 1e6 + 10;
const int MAXN = 2e5 + 10;

inline char readchar() {
	static char buf[100000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read() {
#define readchar getchar
	int res = 0, f = 0;
	char ch = readchar();
	for (; !isdigit(ch); ch = readchar()) if (ch == '-') f = 1;
	for (; isdigit(ch); ch = readchar()) res = (res << 1) + (res << 3) + (ch ^ '0');
	return f ? -res : res;
}

inline void print(int x) {
	if (x < 0 ) putchar('-'), x = -x;
	if (x > 9 ) print(x / 10);
	putchar(x % 10 + '0');
}

struct _Node {
	string s;
	int sum;
	bool operator < (const _Node &x) const {
		return sum != x.sum ? sum > x.sum : s < x.s;
	}
} a[MAXN], b[MAXN];
int wz;
#define re register
signed main() {
//	ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);
	int n = read();
	for (register int i = 1; i <= n; i++) {
		cin >> a[i].s;
		for (re int j = 1; j <= 5; j++) a[i].sum += read();
	}
	for (re int i = 1; i <= n; i++) b[i].s = a[i].s, b[i].sum = a[i].sum;
	for (re int i = 1; i <= n; i++) {
		string S = a[i].s;
	for (re int j = 1; j <= n; j++) b[j].s = a[j].s, b[j].sum = a[j].sum;	
		for (re int j = 1; j <= n; j++) {
			if (b[j].s == S) {
				b[j].sum += 500;
				break;
			}
		}
		sort(b + 1, b + n + 1);
		for (re int j = 1; j <= n; j++) {
			if (b[j].s == S) {
				printf("%lld ", j);
				wz = j;
				break;
			}
		}
		b[wz].sum -= 500;
		for(re int j = 1; j <= n; j++)  {
			if(b[j].s != S) b[j].sum += 500;
		}
		sort(b + 1, b + n + 1);
		for (re int j = 1; j <= n; j++) {
			if (b[j].s == S) {
				printf("%lld\n", j);
			}
		}
	}
	return 0;
}

标签:Med,ch,P8342,题解,int,p1,readchar,include,buf
来源: https://www.cnblogs.com/tttttttle/p/16293582.html