Land oj 1606 - Funny Sheep(技巧&规律)
来源:互联网 发布:淘宝游戏账号交易平台 编辑:程序博客网 时间:2024/05/21 07:04
Problem 1606 - Funny Sheep
Time Limit: 1000MS Memory Limit: 65536KB
Total Submit: 612 Accepted: 169 Special Judge: No
Total Submit: 612 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)
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
2 2
Sample Output
1
2
//题意:
现在有一个n*m的矩形的网格栅栏,每个网格里有一头羊,问最少拆掉多少根的栅栏可以让所有的羊走到一起。
//思路:
因为是让所有的羊走到一起,所以通过模拟可以找出规律:拆的最少栅栏数为min(min(n,m),m+n-2);n表示将横行拆掉,只剩下一行
m表示将所有的纵列拆掉,只剩下一列,n+m-2表示将中间的栅栏拆掉。找到它们三个之间的最小值即可。
#include<stdio.h>#include<string.h>#include<math.h>#include<map>#include<queue>#include<stack>#include<set>#include<algorithm>#include<iostream>#define INF 0x3f3f3f3f#define ull unsigned long long#define ll long long#define IN __int64#define N 100010#define M 1000000007using namespace std;int main(){int n,m;while(scanf("%d%d",&n,&m)!=EOF){int ans=min(n,m);ans=min(ans,n+m-2);printf("%d\n",ans);}return 0;}
0 0
- Land oj 1606 - Funny Sheep(技巧&规律)
- Whu oj 1606 - Funny Sheep
- lanoj--1606--Funny Sheep(规律水题)
- Problem 1606 - Funny Sheep
- WHOJ 1606 - Funny Sheep【水】
- POJ 2484 A Funny Game(规律)
- Land oj 1609 - Han Move (模拟)
- Land oj 1611 - Null (水)
- HDU 6050 Funny Function (规律+逆元)
- POJ 2484 A Funny Game(规律直推)
- UVA The Land of Justice(找规律)
- 【HDU-OJ】-6016-Count the Sheep(二分图,vector)
- 哈理工OJ 2033 A Funny Game(博弈问题)
- UVa OJ 12265 - Selling Land
- POJ 2484 A Funny Game(找规律)
- light oj 1202 - Bishops(规律推导)
- *规律-技巧
- AOJ-AHU-OJ-31 Counting Sheep
- vs生成exe
- [转]回文串判断算法——Manacher算法
- 10142 - Australian Voting
- 【Android基础】文件操作
- PHP入门学习笔记之—— PHP 控制结构
- Land oj 1606 - Funny Sheep(技巧&规律)
- 日语中一些标点符号的读法(权威版)
- 一个大四求职菜鸟的前端学习之路(三)
- Android自定义view的一般步骤
- html5--位置感知(基于js的地理定位geolocation API)结合Google Maps
- adaboost
- 输入输出函数(一)
- JVM内存参数详解以及配置调优
- C 【for循环嵌套 图形规律 问题】