Problem 1606-funny Sheep
Time Limit: 1000MS
Memory Limit: 65536KB total
Submit: 612
Accepted: 169
Special judge : No Description
There is n+1 rows and m+1 columns fence with n*m grids on the grassland. Each of the grids 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?
Inputthere is multiple test cases. The first line of all case contains, integers N and M. (1≤n,m≤1000) outputfor each case, output the answer in a line. Sample INPUT1 2 2 2Sample Output12the puzzle: A n*m grid, each with a sheep in it, now gathers all the sheep together ... To remove a grid, each time a row or column, ask the minimum number of times;at first did not think to tear around the wall, all kinds of silly ... Finally found the split, split, or split the middle; the n,m or column is the only one that needs to be left; or n-1+m-1;Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;Const intINF =0x3f3f3f3f; typedefLong LongLL;intMain () {intN, M; while(~SCANF ("%d%d",&n,&M)) { intAns =min (n,m); Ans=min (ans,n-1+m-1); printf ("%d\n", ans); } return 0;}
Funny Sheep (thinking)