Test instructions
There are n individuals, 22 have competitions, and then each has a number of wins.
Strong (weak) king (vegetables), who has won more than his own number of wins.
(Why I say that they is so weak?)
:* ***,how does think a person who beat the heroes and defeated at the Dogface? )
Let you arrange the game, ask how many strongking?
Exercises
First (some people say) can be proven if there are K SK, then must be the highest rating K.
Then enumerate the k, and the water chart check verifies the Maxflow.
Essay water.
Code:
#include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream > #include <algorithm> #define N 405//Network Diagram Midpoint # a G 100000//Network map in the Edge # # P 15//The original midpoint, etc. # define M 50//The original edge etc #de Fine inf 0x3f3f3f3f#define inf 0x3f3f3f3f3f3f3f3fll#define LL intusing 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--)//enum SK number, n<=10, Two minutes to hell. ~~{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 ();}
Read (Dou) (BI) People re is not deleted Freopen?
"POJ2699" The Maximum number of strong Kings enumeration (two points) + Network flow check,