2013
11-13

# Kindergarten

In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all players know each other. You are to help to find maximum number of kids the teacher can pick.

The input consists of multiple test cases. Each test case starts with a line containing three integers
G, B (1 ≤ G, B ≤ 200) and M (0 ≤ MG × B), which is the number of girls, the number of boys and
the number of pairs of girl and boy who know each other, respectively.
Each of the following M lines contains two integers X and Y (1 ≤ X≤ G,1 ≤ Y ≤ B), which indicates that girl X and boy Y know each other.
The girls are numbered from 1 to G and the boys are numbered from 1 to B.

The last test case is followed by a line containing three zeros.

For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the maximum number of kids the teacher can pick.

2 3 3
1 1
1 2
2 3
2 3 5
1 1
1 2
2 1
2 2
2 3
0 0 0

Case 1: 3
Case 2: 4

//* @author: Yeming Hu"[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */"
import java.util.*;

public class Main
{
public static int b;
public static int g;
public static int m;
public static boolean[][] graph;
public static boolean[] checked;

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
graph = new boolean[200][200];
checked = new boolean[200];
int t = 0;

while(true)
{
b = sc.nextInt();
g = sc.nextInt();
m = sc.nextInt();

if(b == 0 && g == 0 && m == 0)
{
break;
}

Arrays.fill(checked,false);

for(int i = 0; i < b; i++)
{
Arrays.fill(graph[i],true);
}
for(int i = 0; i < m; i++)
{
int a = sc.nextInt();
int b = sc.nextInt();
graph[a-1][b-1] = false;
}
int ans = 0;
for(int i = 0; i < b; i++)
{
Arrays.fill(checked,false);
if(find(i))
{
ans++;
}
}
System.out.println("Case " + (++t) + ": " + (g+b-ans));
}
}

public static boolean find(int a)
{
for(int i = 0; i < g; i++)
{
if(graph[a][i] && !checked[i])
{
checked[i] = true;
{
return true;
}
}
}
return false;
}
}

1. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮

2. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮

3. #include <stdio.h>
int main(void)
{
int arr[] = {10,20,30,40,50,60};
int *p=arr;
printf("%d,%d,",*p++,*++p);
printf("%d,%d,%d",*p,*p++,*++p);
return 0;
}

为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下？