Moving Tables-贪心
| Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
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
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
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
接着就是相邻的两个房间进行特殊处理。假设是5号房间,那么6号房间的走廊就不能用。为什么。请
看题目提供的图。所以接下来就处理过去就能够了,知道没有房间能够搬。
/*
Author: 2486
Memory: 1416 KB Time: 0 MS
Language: G++ Result: Accepted
VJ RunId: 4178448 Real RunId: 14210276
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=200+5;
int t,n;
struct obje {
int s,t;
bool operator<(const obje&a)const {
return s<a.s;
}
} objes[maxn];
bool vis[maxn];
int main() {
// freopen("D://imput.txt","r",stdin);
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%d%d",&objes[i].s,&objes[i].t);
if(objes[i].s>objes[i].t)swap(objes[i].s,objes[i].t);
vis[i]=false;
}
sort(objes,objes+n);//按房号開始排序
int cnt=0;
bool flag=false;
while(true) {
int t=0;
flag=false;
for(int i=0; i<n; i++) {
if(vis[i])continue;
if((t%2==1&&t+1<objes[i].s)||(t%2==0&&t<objes[i].s)) {//相邻的房间处理,以及选取末尾比t大的房号
flag=true;
vis[i]=true;
t=objes[i].t;
}
}
if(!flag)break;
else cnt++;
}
printf("%d\n",cnt*10);
}
return 0;
}
第二种方法就是区间覆盖的方法。属于区间覆盖类型题,对于每一回合操作中记录当前覆盖的最大的值,证明这些覆盖的部分肯定不可以同一时候进行搬运,如此这里还须要一个技巧,就是将5,6或者3,4变为一个数,由于他们拥有相同的走廊。将6当做5处理。和把5当做6处理。他们都是占用同一走廊,所得到的效果是一样的
/*
Author: 2486
Memory: 1408 KB Time: 0 MS
Language: G++ Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=200+5;
int t,n,s,tt;
int a[maxn];
int main() {
//freopen("D://imput.txt","r",stdin);
scanf("%d",&t);
while(t--) {
memset(a,0,sizeof(a));
scanf("%d",&n);
int cnt=0;
while(n--){
scanf("%d%d",&s,&tt);
if(s>tt)swap(s,tt);
s=(s+1)>>1;//将他们5,6缩到一起。区间降低一半
tt=(tt+1)>>1;
for(int i=s;i<=tt;i++){
a[i]++;
if(a[i]>cnt)cnt=a[i];//求每一回合,区间的最大覆盖值就可以
}
}
printf("%d\n",cnt*10);
}
return 0;
}
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 ...
随机推荐
- javascript 的回调函数
既然函数可以像其他数据那样赋值给某个个变量,可以被定义.删除.拷贝,那为什么就不能被当成参数传递给其他函数呢? 下面的示例中,我们定义了一个以两个函数为参数的函数.该函数会分别执行这两个参数函数,并返 ...
- 2018 ACM-ICPC 北京网络赛
Problem A 最短路,跑一下dij就可以了. Problem B Problem C 按照题意模拟,不过坑点很多 1.注意字典序: 2.注意挑战的时候失败的那个人要把当前所有桌子上的牌都拿走 P ...
- 洛谷P2280 [HNOI2003] 激光炸弹 [前缀和]
题目传送门 题目描述 输入输出格式 输入格式: 输入文件名为input.txt 输入文件的第一行为正整数n和正整数R,接下来的n行每行有3个正整数,分别表示 xi,yi ,vi . 输出格式: 输出文 ...
- 【SQL】oralce中使用group by和case when按照条件求和
假设我们有一个Salary 薪水表.这个表的字段分别为:id, name, salary, level 在这个表中,每个人有不同的级别(level).我们要根据不同的级别统计相同级别员工的薪水总和. ...
- Codeforces Round #260 (Div. 1) Boredom(DP)
Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Linux命令之nice和renice
(1).nice命令 nice [选项] [命令 [参数]] 在执行程序之前,改变优先级.以调整过的优先级运行命令.如果没有给出命令,就显示当前的优先级.优先级范围从-20到19,越小优先级越高,默认 ...
- [BZOJ 3326] 数数
Link: BZOJ 3326 传送门 Solution: 明显是一道数位$dp$的题目,就是递推式复杂了点 先要求出一个数$\bar{n}$向添加一位后的$\bar{np}$的转化关系 令$res[ ...
- BZOJ 1700 [Usaco2007 Jan]Problem Solving 解题(单调DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1700 [题目大意] 共有p道题目要做,每个月收入只有n元,用于付钱做题之外的部分都会吃 ...
- BZOJ 2288 【POJ Challenge】生日礼物(贪心+优先队列)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2288 [题目大意] 给出一列数,求最多取m段连续的数字,使得总和最大 [题解] 首先我 ...
- 【推导】【模拟】AtCoder Regular Contest 082 F - Sandglass
题意:有个沙漏,一开始bulb A在上,bulb B在下,A内有a数量的沙子,每一秒会向下掉落1.然后在K个时间点ri,会将沙漏倒置.然后又有m个询问,每次给a一个赋值ai,然后询问你在ti时刻,bu ...