zoukankan      html  css  js  c++  java
  • [TJOI2018]智力竞赛

    Description
    小豆报名参加智力竞赛,他带上了n个好朋友作为亲友团一块来参加比赛。
    比赛规则如下:
    一共有m道题目,每个入都有1次答题机会,每次答题为选择一道题目回答,在回答正确后,可以从这个题目的后续题目,直达题目答错题目或者没有后续题目。每个问题都会代表一个价值,比赛最后的参赛选手获得奖励价值等价于该选手和他的亲友团没有回答的问题中的最低价值。我们现在知道小豆和他的亲友团实力非常强,能够做出这次竞赛中的所有题目。
    小豆想知道在知道题目和后续题目的条件下,他最大能获得价值是多少?

    Input
    第一行有两个整数n, m。(n ≤ 50, m ≤ 500)
    接下来m行,第i+1行表示编号为i的题目的题目信息;
    格式如下vi, ki, ai_1, ai_2, ..., ai_ki 。
    其中vi表示该题目的价值,ki 表示这个题目的后续,ai_1, ai_2, ..., ai_ki 表示这i 个题目的后续题目编号。
    1 < n ≤ 50, 1 < m ≤ 500, vi ≤ 10^9, ki, ai_j ≤ m。

    Output
    如果全部题目都能答对,这输出“AK”,否则输出小豆可以获得的最高奖励价值。

    Sample Input
    1 3
    1 0
    2 1 3
    3 0

    Sample Output
    AK


    首先我们二分一个答案,那么所有权值比答案大的点都是不能选的,然后对于剩下的点求一遍最大独立点集,然后判断二分上下界的调整即可

    /*program from Wolfycz*/
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define inf 0x7f7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline char gc(){
    	static char buf[1000000],*p1=buf,*p2=buf;
    	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
    }
    inline int frd(){
    	int x=0,f=1; char ch=gc();
    	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline int read(){
    	int x=0,f=1; char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x<0)	putchar('-'),x=-x;
    	if (x>9)	print(x/10);
    	putchar(x%10+'0');
    }
    const int N=5e2,M=3e5;
    int pre[M+10],now[N+10],child[M+10];
    int path[N+10],vis[N+10],v[N+10];
    int limit,tot,n,m,Time;
    bool map[N+10][N+10];
    void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
    bool Extra(int x){
    	for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
    		if (vis[son]==Time||v[son]>=limit)	continue;
    		vis[son]=Time;
    		if (!~path[son]||Extra(path[son])){
    			path[son]=x;
    			return 1;
    		}
    	}
    	return 0;
    }
    bool check(int val){
    	int res=0; limit=val,Time=0;
    	for (int i=1;i<=m;i++)	path[i]=-1,vis[i]=0;
    	for (int i=1;i<=m;i++){
    		if (v[i]>=limit)	continue;
    		++Time,++res;
    		if (Extra(i))	--res;
    	}
    	return res<=n;
    }
    int main(){
    	n=read()+1,m=read();
    	for (int i=1;i<=m;i++){
    		v[i]=read(); int x=read();
    		for (int j=1;j<=x;j++)	map[i][read()]=1;
    	}
    	for (int k=1;k<=m;k++)
    		for (int i=1;i<=m;i++)
    			for (int j=1;j<=m;j++)
    				if (i!=j&&j!=k&&i!=k)
    					map[i][j]|=(map[i][k]&map[k][j]);
    	for (int i=1;i<=m;i++)
    		for (int j=1;j<=m;j++)
    			if (map[i][j])
    				join(i,j);
    	int l=1,r=1e9;
    	while (l<=r){
    		int mid=(l+r)>>1;
    		if (check(mid))	l=mid+1;
    		else	r=mid-1;
    	}
    	printf(r==1e9?"AK
    ":"%d
    ",r);
    	return 0; 
    }
    
  • 相关阅读:
    Leetcode 50.Pow(x,n) By Python
    Leetcode 347.前K个高频元素 By Python
    Leetcode 414.Fizz Buzz By Python
    Leetcode 237.删除链表中的节点 By Python
    Leetcode 20.有效的括号 By Python
    Leetcode 70.爬楼梯 By Python
    Leetcode 190.颠倒二进制位 By Python
    团体程序设计天梯赛 L1-034. 点赞
    Wannafly挑战赛9 C-列一列
    TZOJ Start
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/10253599.html
Copyright © 2011-2022 走看看