zoukankan      html  css  js  c++  java
  • 洛谷1199 三国游戏

    原题链接

    因为电脑始终会把你选择的武将的同行默契最大的配对武将选走,所以你肯定不能配对出同行默契最大的武将。
    所以我们可以考虑退(da)而(li)求(cai)其(jie)次(lun),配对出每行次大中最大的那一对。
    然后不管电脑选择的武将是全部最大还是仅同行最大,你都可以破坏电脑的匹配。
    因为你是先手,电脑总是被动的,虽然你拿不到最大的,但你也可以让电脑也拿不到最大的,于是你配对的最大次大就是最后最大的了。
    上面纯属我的叽歪,更详细的证明可以看这位大佬的博客

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int N = 510;
    int a[N][N];
    inline int re()
    {
    	int x = 0;
    	char c = getchar();
    	bool p = 0;
    	for (; c < '0' || c > '9'; c = getchar())
    		p |= c == '-';
    	for (; c >= '0' && c <= '9'; c = getchar())
    		x = x * 10 + c - '0';
    	return p ? -x : x;
    }
    inline int maxn(int x, int y)
    {
    	return x > y ? x : y;
    }
    int main()
    {
    	int i, j, ma = 0, n;
    	n = re();
    	for (i = 1; i <= n; i++)
    		for (j = i + 1; j <= n; j++)
    			a[i][j] = a[j][i] = re();
    	for (i = 1; i <= n; i++)
    	{
    		sort(a[i] + 1, a[i] + n + 1);
    		ma = maxn(ma, a[i][n - 1]);
    	}
    	printf("1
    %d", ma);
    	return 0;
    }
    
  • 相关阅读:
    插入排序
    JavaMail学习笔记
    Struts2的工作原理
    我的快速排序
    截取字符串,只截取前N个字节的字符
    修改MyEclipse8.6中的Servlet.java模板
    Java类装载的过程及原理介绍
    cmd检查jdk的版本
    快速排序
    flash 侦测人的面部
  • 原文地址:https://www.cnblogs.com/Iowa-Battleship/p/9855388.html
Copyright © 2011-2022 走看看