Whu oj 1606 - Funny Sheep

来源:互联网 发布:网络注册表修复win7 编辑:程序博客网 时间:2024/05/21 05:20

Problem 1606 - Funny Sheep

Time Limit: 1000MS   Memory Limit: 65536KB  
Total Submit: 605  Accepted: 165  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
1
2

可以拆除最外围的栅栏。

#include<cstdio> #include<cstring> int main() {     int n,m,ans;     while(scanf("%d%d",&n,&m)!=EOF)     {         if(n>=m)             ans=m;         if(m>n)             ans=n;         if(ans>(n-1+m-1))             ans=n-1+m-1;         printf("%d\n",ans);     }     return 0; }


0 0
原创粉丝点击