[博弈论]P1199

https://www.luogu.com.cn/problem/P1199

题意:

思路:
机器人每次都搞破坏,所以最优方案永远也取不到,
所以考虑取最大的次大值,按照两数之和从大到小排列,
每次遍历过去之后,就将那两个数的vis都记录为1,
如果某次时,有某个数在之前被遍历过了,则我们就当作我们之前拿的这个数,
而机器人只会取最大值,这是一个次大值,他不会取,所以我们能保证自己最大。

代码

const int N=250010,M=1e6+10;
int t,n,m;
int vis[N];
struct node{
    int a,b,c;
    bool operator<(const node& t)const{
        return c > t.c;
    }
}a[N];
int main(){
    read(n);
    int pos = 0;
    for(int i=1;i<=n-1;i++){
        for(int j=i+1;j<=n;j++){
            int x;
            read(x);
            a[pos++] = {i,j,x};
        }
    }
    sort(a,a+pos);
    for(int i=0;i<pos;i++){
        int x = a[i].a,y = a[i].b,z = a[i].c;
        if(vis[x]){
            puts("1");
            printf("%d\n",z);
            return 0;
        }else if(vis[y]){
            puts("1");
            printf("%d\n",z);
            return 0;
        }else{
            vis[x] = vis[y] = 1;
        }
    }
    puts("0");
    return 0;
}
posted @ 2021-06-30 17:09  Isaac233  阅读(57)  评论(0)    收藏  举报