NOIP2010普及 三国游戏 贪心

版权声明:本文为DyingShu原创文章,转载请注明出处哦。 https://blog.csdn.net/DyingShu/article/details/82806165

传送门

5min水了一道题。

一句话题解:取对于每个武将第二大的匹配值的最大值就是答案。
就是个很简单的贪心,加上是道水题,也不需要啥优化是吧

#include<cstdio>
#include<algorithm>
using namespace std;

int a[501][501];

inline int read(){
	int k = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){k = k*10 + ch - '0'; ch = getchar();}
	return k * f;
}

inline bool cmp(int a, int b){
	return a > b;
}

int main(){
	int n = read();
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			a[i][j] = a[j][i] = read();
		}
	}
	for(int i = 1; i <= n; i++){
		sort(a[i] + 1, a[i] + n + 1, cmp);
	}
	
	int Ans = 0;
	for(int i = 1; i <= n; i++){
		Ans = max(Ans, a[i][2]);
	}
	printf("1\n%d", Ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/DyingShu/article/details/82806165