lanoj--1606--Funny Sheep(规律水题)

Problem 1606 - Funny Sheep
Time Limit: 1000MS    Memory Limit: 65536KB   
Total Submit: 613   Accepted: 169   Special Judge: No
Description

There are N+1 rows and M+1 columns fence with N*M grids on the grassland. Each grid has a sheep. In order to let the sheep together, we need to dismantle the fence. Every time you can remove a row or a column of fences. What’s the least number of times to reach the goal? 

Input
There are multiple test cases.
The first line of each case contains two integers N and M. (1≤N,M≤1000)
Output
For each case, output the answer in a line.
Sample Input
1 2
2 2
Sample Output

2
题意:m行n列的网格由篱笆围成,每个格子中都有一个一只羊,每次可以选择拆除一行或者一列的篱笆,最后要使得所有的羊可以跑到一起
刚开始傻了,其实很简单,拆除m行或者n列再或者n+m-2行和列,取三者的最小值,说是让他们可以跑到一起,但是并没有说必须要全部锁在一个格子,所以他们可以通过外部跑到一起
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		printf("%d\n",min(n,min(m,m+n-2)));
	}
	return 0;
} 


你可能感兴趣的:(lanoj--1606--Funny Sheep(规律水题))