【POJ2699】The Maximum Number of Strong Kings 枚举(二分)+网络流check、

题意:

有n个人,两两都有比赛,然后有每个人的胜场次数。

规定把比自己胜场次数多的人都赢了的就是strong(weak) king (vegetables)

(why i say that they are so weak?

:****,how do you think a person who beat the heroes but defeated at the dogface? )

让你安排比赛,问最多有多少个strongking?

题解:

首先(有人说)能证如果有k个sk,那么一定可以是rating最高的那k个。

然后枚举k,水图check验证maxflow。

破题水。

代码:

#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 405 // 网络图中点
#define G 100000 // 网络图中边
#define P 15 // 原图中点等
#define M 50 // 原图中边等
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fll
#define LL int
using namespace std;
struct KSD
{
	int v,next,len;
}e[G];
int head[N],cnt;
void add(int u,int v,int len)
{
	cnt++;
	e[cnt].v=v;
	e[cnt].len=len;
	e[cnt].next=head[u];
	head[u]=cnt;
}
queue<int>q;
int d[N],s,t;
bool bfs()
{
	memset(d,0,sizeof(d));
	int i,u,v;
	while(!q.empty())q.pop();
	q.push(s),d[s]=1;
	while(!q.empty())
	{
		u=q.front(),q.pop();
		for(i=head[u];i;i=e[i].next)if(e[i].len)
		{
			v=e[i].v;
			if(!d[v])
			{
				d[v]=d[u]+1;
				if(v==t)
					return 1;
				q.push(v);
			}
		}
	}
	return 0;
}
int dinic(int x,int flow)
{
	if(x==t)return flow;
	int remain=flow,k;
	int i,v;
	for(i=head[x];i&&remain;i=e[i].next)
	{
		v=e[i].v;
		if(e[i].len&&d[v]==d[x]+1)
		{
			k=dinic(v,min(remain,e[i].len));
			if(!k)d[v]=0;
			e[i^1].len+=k,e[i].len-=k;
			remain-=k;
		}
	}
	return flow-remain;
}
int n,m,maxflow;
int rating[P];
bool cmp(int a,int b){return b<a;}
void build(int mid)
{

	int i,j,cnt=n;
	for(i=1;i<=n;i++)add(s,i,rating[i]),add(i,s,0);
	for(j=1;j<=n;j++)for(i=j+1;i<=n;i++)
	{
		cnt++;
		add(i,cnt,1),add(cnt,i,0);
		if(i>mid||rating[j]==rating[i])add(j,cnt,1),add(cnt,j,0);
		add(cnt,t,1),add(t,cnt,0);
	}
}
void work()
{
	int i;
	char inp[5];
	n=0;
	while(scanf("%c",&inp[0])!=EOF&&inp[0]!='\n')if(inp[0]!=' ')rating[++n]=inp[0]-'0';
	m=n*(n-1)/2;
	s=n+m+1,t=n+m+2;

	sort(rating+1,rating+n+1,cmp);
	for(i=n;i;i--) // 枚举sk个数,n<=10,二分见鬼去吧~~
	{
		cnt=1;
		memset(head,0,sizeof(head));
		build(i);
		maxflow=0;
		while(bfs())maxflow+=dinic(s,inf);
		if(maxflow==m)
		{
			printf("%d\n",i);
			return ;
		}
	}
	return ;
}
int main()
{
	freopen("test.in","r",stdin);
	int g;for(scanf("%d",&g),getchar();g--;)work();
}

读(dou)者(bi)们RE的是不是没删freopen?

时间: 2024-08-21 06:03:39

【POJ2699】The Maximum Number of Strong Kings 枚举(二分)+网络流check、的相关文章

解题报告 之 POJ2699 The Maximum Number of Strong Kings

解题报告 之 POJ2699 The Maximum Number of Strong Kings Description A tournament can be represented by a complete graph in which each vertex denotes a player and a directed edge is from vertex x to vertex y if player x beats player y. For a player x in a t

POJ2699 The Maximum Number of Strong Kings

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2102   Accepted: 975 Description A tournament can be represented by a complete graph in which each vertex denotes a player and a directed edge is from vertex x to vertex y if player x beats

【POJ2699】The Maximum Number of Strong Kings(二分,最大流)

题意: 有n个队伍,两两都有比赛 知道最后每支队伍获胜的场数 求最多有多少队伍,他们战胜了所有获胜场数比自己多的队伍,这些队伍被称为SK N<=50 思路:把每个队伍和它们两两之间的比赛都当做点,判断最大流是否满流即可 S-->队伍 a[i] 队伍 -->比赛 1 比赛-->T 1 i号队伍是SK:如果j为SK且a[i]>a[j]则j必胜,如果a[i]<a[j]则i必胜 只要必胜者向他们之间的比赛连1条边即可 如果j不为SK,胜负未知,两个点都向他们之间的比赛连1条边

【POJ2699】The Maximum Number of Strong Kings

Description A tournament can be represented by a complete graph in which each vertex denotes a player and a directed edge is from vertex x to vertex y if player x beats player y. For a player x in a tournament T, the score of x is the number of playe

POJ2699_The Maximum Number of Strong Kings

这题目,,,真是...诶.坑了好久. 给一个有向图.U->V表示U可以打败V并得一分. 如果一个人的得分最高,或者他打败所有比自己得分高的人,那么此人就是king. 现在给出每个人的得分,求最多可能有多少个king同时存在. 可以证明,如果有k个人是king,那么至少有一种分配方案使得这k个king都是分数最高的那k个人.(证明略,想想就知道了) 于是我们可以开始枚举从i个人开始,后面的都是king. 除了源点和汇点以外,还有两种点,一种表示人(n),一种表示比赛(n*(n/2)/2). 如果一

POJ 2699 The Maximum Number of Strong Kings Description

The Maximum Number of Strong Kings Description A tournament can be represented by a complete graph in which each vertex denotes a player and a directed edge is from vertex x to vertex y if player x beats player y. For a player x in a tournament T, th

POJ 2699 The Maximum Number of Strong Kings (最大流+枚举)

http://poj.org/problem?id=2699 题意: 一场联赛可以表示成一个完全图,点表示参赛选手,任意两点u, v之间有且仅有一条有向边(u, v)或( v, u),表示u打败v或v打败u.一个选手的得分等于被他打败的选手总数.一个选手被称为“strong king”当且仅当他打败了所有比他分高的选手.分数最高的选手也是strong king.现在给出某场联赛所有选手的得分序列,由低到高,问合理安排每场比赛的结果后最多能有几个strong king.已知选手总数不超过10个.

【poj2699】 The Maximum Number of Strong Kings

http://poj.org/problem?id=2699 (题目链接) 题意 给出1张有向完全图.U->V表示U可以打败V并得一分.如果一个人的得分最高,或者他打败所有比自己得分高的人,那么此人就是king.现在按顺序给出每个人的得分,求最多可能有多少个king同时存在. Solution 想了半天贪心,然而得分相等的情况真的很不好处理..真的没想到是最大流..左转题解:http://blog.csdn.net/sdj222555/article/details/7797257 考虑这样建图

The Maximum Number of Strong Kings

poj2699:http://poj.org/problem?id=2699 题意:n个人,进行n*(n-1)/2场比赛,赢一场则得到一分.如果一个人打败了所有比他分数高的对手,或者他就是分数最高的,那么他就是strong kind.现在给你每个人的得分,问你最多有多少个strong kind. 题解:自己没有思路,看了别人的题解,才勉强理解了.首先,肯定让得分高的成为strong king,因为概率比较大,然后就是怎建图了.假如,我们已经知道了,有m个strong kind,那么这m个人一定是