lanoj--1606--Funny Sheep(规律水题)
2016-04-10 09:40
387 查看
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
1
2
题意:m行n列的网格由篱笆围成,每个格子中都有一个一只羊,每次可以选择拆除一行或者一列的篱笆,最后要使得所有的羊可以跑到一起
刚开始傻了,其实很简单,拆除m行或者n列再或者n+m-2行和列,取三者的最小值,说是让他们可以跑到一起,但是并没有说必须要全部锁在一个格子,所以他们可以通过外部跑到一起
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
1
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; }
相关文章推荐
- linux备份
- 第五章 套餐管理系统
- REST API
- 上海地铁游移动APP需求分析
- Visual Studio 2015 Update 2
- 判断当前控制器是否是根控制器
- 如何将路径中的中文换成%
- 线程饥饿死锁
- 数据结构-线性表
- Nginx的编译安装
- 通过运行时获取某个类下所有的属性
- OpenGL 中 GLUT 消息事件处理函数
- 微软官网下载正版WIN
- (七)理解angular中的module和injector,即依赖注入
- Scrapy 默认设置
- BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~
- 进度条--第六周
- 基于NodeBB的网站服务器迁移步骤
- Double-Lock Checking
- Class不是对象,用assign修饰