POJ2699 the Maximum number of strong Kings enumeration (binary) + network stream check, __poj2699

Source: Internet
Author: User

Meaning

There are n individuals, 22 have games, and then there are the number of wins for everyone.

Strong (weak) king (vegetables) is the one who has won more than the number of wins in the game.

(Why I say that they are so weak?

:* ***,how Do you have beat the heroes but defeated at the Dogface? )


Let you arrange the game and ask how many strongking there are.


Exercises

First (someone said) if there is K SK, then it must be rating the highest K.

Then enumerate K, water map Check to verify Maxflow.


Essay water.

Code:

#include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream > #include <algorithm> #define N 405//Network Map midpoint #define G 100000//Network Map Edge #define P 15//Original midpoint #define M 50/
Edge #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--)//enumeration of SK number, n<=10, two points to Hell go ~ ~ {cnt=1;
		Memset (head) (head,0,sizeof);
		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 ();
 }
Read (Dou) (BI) the RE is not deleted Freopen?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.