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.
|
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 |
Sample Output
10 |
Source
Asia 2001, Taejon (South Korea)
|
题意:一条走廊,现在要移动桌子,从a房间移动到b房间,有交叉的地方不能同时移,即走廊的宽度只能容纳一个桌子。
分析:首先将左右的房间进行压缩,如1-2,压缩成1,即相对的房间变成了一个房间。然后一条一条的扫,经过的房间就加上1.最后求出经过房间的最大次数。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = +;
int corridor[maxn];
int T;
int ans=-INF; int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin>>T;
while(T--){
memset(corridor,,sizeof(corridor));
int n;
int s,t;
cin>>n;
for( int i=; i<n; i++ ){
cin>>s>>t;
if(s>t) swap(s,t);
s=(s+)/;
t=(t+)/;
for( int j=s; j<=t; j++ ){
corridor[j]++;
}
}
ans=-INF;
for(int i=; i<=; i++ ){
ans=max(ans,corridor[i]);
}
cout<<ans*<<endl;
}
return ;
}
Moving Tables---(贪心)的更多相关文章
- Moving Tables(贪心或Dp POJ1083)
Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28304 Accepted: 9446 De ...
- zstu.2512. Moving Tables(贪心)
Moving Tables Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1182 Solved: 563 Description The famo ...
- HDU1050(Moving Tables:贪心算法)
解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...
- hdu_1050 Moving Tables 贪心
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- UVAlive 2326 Moving Tables(贪心 + 区间问题)
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...
- --hdu 1050 Moving Tables(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...
- 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【贪心区间覆盖】
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 ...
- Moving Tables
Moving Tables Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
随机推荐
- .net core安装及初体验
.net core安装及初体验 .net core 作为微软的新一代技术,在开发跨平台.微服务等方面有很大的优势,也更贴近现代的编码习惯.在2.0版发布很久以后,近期终于决定进行学习和体验. 安装 作 ...
- .Net:System.Guid
ylbtech-.Net:System.Guid 1.返回顶部 1.public static Guid NewGuid(); // // 摘要: // 初始化 System.Guid 结构的新实例. ...
- OpenSceneGraphic 着色器中数组的应用【转】
https://blog.csdn.net/zsq306650083/article/details/50533480 //osg的写法osg::ref_ptr<osg::StateSet> ...
- WSL(Windows Subsystem for Linux)的安装与使用及 mongodb安装
有关WSL的介绍这里就不做解释了.另外,本文仅适用于win10 build 16215以及之后的版本,之前的版本可参考官方链接. (可使用“winver”命令查看windows版本号) 安装:1. ...
- Android:android studio快捷键大全
一.常用快捷键 1.Ctrl+E,可以显示最近编辑的文件列表 2.Shift+Click可以关闭文件 3.Ctrl+[或]可以跳到大括号的开头结尾 4.Ctrl+Shift+Backspace可以跳转 ...
- dubbo常见错误
1.dubbo zookeeper注册中心provider的ip地址为内网ip,导致consumer连不上 我用的阿里云的服务器,host默认配置了内网ip,注销或删除即可 vim /etc/host ...
- Android application捕获崩溃异常
Java代码 .收集所有 avtivity 用于彻底退出应用 .捕获崩溃异常,保存错误日志,并重启应用 , intent, , restartIntent); // 关闭当前应用 finishAllA ...
- Docker入门实践
Docker是一门很成熟的容器技术,类似虚拟机技术主要用做环境的隔离,方便环境的复制镜像,虚拟机是基于操作系统这一层的,而Docker更加的轻量级,像是“应用”层级的.比如我需要一个MySQL环境.一 ...
- redis应用-sortedset实现排行榜(转载)
package site.zy9.redisApp.test; import java.util.HashMap; import java.util.List; import java.util.Ma ...
- mac关闭占用某个端口的进程
在启动项目的时候有时候会提示端口被占用,但是怎么都找不到那个关闭进程的地方,可以直接通过命令行关闭这个进程: 比如要关闭:8000端口的进程: 1. 查找端口进程: lsof -i: 会把所有的占用8 ...