Hdoj 1050.Moving Tables 题解
Problem Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.
The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
Sample Input
3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50
Sample Output
10
20
30
Source
Asia 2001, Taejon (South Korea)
思路
两个思路:
- 把移动的房间号\(l,r\)看成平面上的一条线段,要找的就是最大重叠次数,此处刚好范围也比较小,所以可以用这个方法
- 用贪心的思想,有点像Hdoj 2037.今年暑假不AC(https://www.cnblogs.com/MartinLwx/p/9727939.html)这道题目,具体思路可以看这个
代码(思路一)
#include<bits/stdc++.h>
using namespace std;
int a[210];
int cor(int x)
{
return x%2==0 ? x/2 : (x+1)/2;
}//返回走廊位置
int main()
{
int t;
while(cin>>t)
{
for(int i=1;i<=t;i++)
{
int n;
cin >> n;
int l,r;
memset(a,0,sizeof(a));
for(int j=1;j<=n;j++)
{
scanf("%d%d",&l,&r);
if(l>r)
{
int t;
t = l; l = r; r = t;
}
int corl = cor(l);
int corr = cor(r);
for(int k=corl;k<=corr;k++)
a[k]++;
}
//for(int j=1;j<=30;j++) cout<<a[j]<<" ";
int max_value = -1;
for(int j=1;j<=201;j++)
if(a[j]>max_value)
max_value = a[j];
if(max_value==0)
cout << 10 << endl;
else
cout << max_value*10 << endl;
}
}
return 0;
}
Hdoj 1050.Moving Tables 题解的更多相关文章
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDOJ 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1083 && HDU 1050 Moving Tables (贪心)
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 【HDOJ】1050 Moving Tables
贪心问题,其实我觉得贪心就是合理的考虑最优情况,证明贪心可行即可.这题目没话多久一次ac.这道题需要注意房间号的奇偶性.1 3.2 4的测试数据.答案应该为20. #include <stdio ...
- HDU ACM 1050 Moving Tables
Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buildin ...
- hdu 1050 Moving Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...
- HDU – 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...
- --hdu 1050 Moving Tables(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...
随机推荐
- TCP粘包问题解析与解决
一.粘包分析 作者本人在写一个FTP项目时,在文件的上传下载模块遇到了粘包问题.在网上找了一些解决办法,感觉对我情况都不好用,因此自己想了个比较好的解决办法,提供参考 1.1 粘包现象 在客户端与服务 ...
- GFS浅析
1 . 简介 GFS, Big Table, Map Reduce称为Google的三驾马车,是许多基础服务的基石 GFS于2003年提出,是一个分布式的文件系统,与此前的很多分布式系统的前提假设存在 ...
- VO和DO转换(四) MapStruct
VO和DO转换(一) 工具汇总 VO和DO转换(二) BeanUtils VO和DO转换(三) Dozer VO和DO转换(四) MapStruct MapStruct
- 【Python3练习题 010】将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
#参考http://www.cnblogs.com/iderek/p/5959318.html n = num = int(input('请输入一个数字:')) #用num保留初始值 f = [] ...
- 使用PSR-4配合composer autoload 自动加载文件夹
require 文件很麻烦,使用PSR-4搭配composer一次加载,终生受用. 感觉类似java中的import了,自己先记录一下最近理解的. 用composer管理自己的包吧 安装compose ...
- oracle查看表结构命令desc
- Flutter 中 JSON 解析
本文介绍一下Flutter中如何进行json数据的解析.在移动端开发中,请求服务端返回json数据并解析是一个很常见的使用场景.Android原生开发中,有GsonFormat这样的神器,一键生成Ja ...
- png8、16、24、32位的区别
我们都知道一张图片可以保存为很多种不同的格式,比如bmp/png/jpeg/gif等等.这个是从文件格式的角度看,我们抛开文件格式,看图片本身,我们可以分为8位, 16位, 24位, 32位等. 单击 ...
- Java——scoket通讯
Socket 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. Socket是TCP/IP协议通信的抽象层,所以我们还需要了解TCP协议 传输层协议 TCP: ...
- 老男孩python学习自修第十八天【面向对象】
1.类与对象(构造方法与实例化) #!/usr/bin/env python # _*_ coding:UTF-8 _*_ class Province: def __init__(self, nam ...