Simple two-part graph matching:
Each position can be edged to these numbers and can even be
Game with PearlsTime
limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 122 Accepted Submission (s): 85
Problem Descriptiontom and Jerry is playing a game with tubes and pearls. The rule of the game is:
1) Tom and Jerry come up together with a number K.
2) Tom provides N tubes. Within each tube, there is several pearls. The number of pearls in each tube are at least 1 and at most N.
3) Jerry puts some more pearls to each tube. The number of pearls put into each tube have to be either 0 or a positive multiple of K. After this Jerry organizes these tubes in the order that the first tube have exact one pearl, the 2nd tube has exact 2 pear LS, ..., the Nth tube has exact N pearls.
4) If Jerry succeeds, he wins the game, otherwise Tom wins.
Write a program to determine who wins the game according to a given N, K and initial number of pearls in each tube. If Tom wins the game, output "Tom", otherwise, output "Jerry".
Inputthe first line contains a integer m (m<=500), then M. Games follow. For each game, the first line contains 2 integers, N and K (1 <= n <=, 1 <= K <= N), and the second line C Ontains N integers presenting the number of pearls in each tube.
Outputfor each game, output a line containing either "Tom" or "Jerry".
Sample Input
Sample Output
SOURCE2014 Shanghai National Invitational Competition--re-title (thanks to Shanghai University for its topics)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn=110;int n,k;struct edge{int to,next;} Edge[maxn*maxn];int adj[maxn],size;void init () {memset (adj,-1,sizeof (ADJ)); size=0;} void Add_edge (int u,int v) {edge[size].to=v; edge[size].next=adj[u]; adj[u]=size++;} int Linker[maxn];bool used[maxn];bool DFS (int u) {for (int i=adj[u];~i;i=edge[i].next) {int v=edge[i].to; if (!used[v]) {used[v]=true; if (linker[v]==-1| | DFS (Linker[v])) {linker[v]=u; return true; }}} return false;} int Hungary () {int res=0; memset (LINKER,-1,SIZEOF (linker)); for (int u=1;u<=n;u++) {memset (used,false,sizeof (used)); if (DFS (U)) res++; } return res; int A[maxn];int Main () {int t_t; scanf ("%d", &t_t); while (t_t--) {scanf ("%d%d", &n,&k); Init (); for (int i=1;i<=n;i++) {scanf ("%d", a+i); for (int j=0;a[i]+j*k<=n;j++) {int v=a[i]+j*k; Add_edge (I,V); }} int pp=hungary (); cout<< "pp:" <<pp<<endl; if (pp==n) puts ("Jerry"); Else puts ("Tom"); } return 0;}
Copyright statement: From: Code Code APE Ape AC Road Http://blog.csdn.net/ck_boss
Hdoj 5090 Game with pearls binary map matching