Moving Tables(贪心或Dp POJ1083)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 28304 | Accepted: 9446 |
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
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 3 + N -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
Source
开始做的时候用的贪心后来感觉好麻烦,就又写的Dp;
贪心
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; typedef struct node
{
int L;
int R;
bool operator <(const node &a)const
{
if(L<a.L||(L==a.L&&R<a.R))
{
return true;
}
return false;
}
} Edge; Edge a[300]; bool vis[300]; int main()
{
int T,n,x,y;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d %d",&x,&y);
if(x>y)
{
swap(x,y);
}
if(x&1)
{
a[i].L=(x+1)/2;
}
else
{
a[i].L=x/2;
}
if(y&1)
{
a[i].R=(y+1)/2;
}
else
{
a[i].R=y/2;
} }
sort(a,a+n);
memset(vis,false,sizeof(vis));
int sum=0;
while(1)
{
int ans=-1;
for(int i=0; i<n; i++)
{
if(!vis[i])
{
if(a[i].L>ans)
{
ans=a[i].R;
vis[i]=true;
}
}
}
if(ans==-1)
{
break;
}
else
{
sum++;
}
}
printf("%d\n",sum*10);
}
return 0;
}
Dp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int Dp[201];
int main()
{
int T,n,x,y;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(Dp,0,sizeof(Dp));
for(int i=0; i<n; i++)
{
scanf("%d %d",&x,&y);
if(x>y)
{
swap(x,y);
}
x=(x+1)/2;
y=(y+1)/2;
Dp[x]+=1;
Dp[y+1]-=1;
}
int sum=0;
for(int i=1;i<201;i++)
{
Dp[i]+=Dp[i-1];
sum=max(sum,Dp[i]);
}
printf("%d\n",sum*10);
}
return 0;
}
Moving Tables(贪心或Dp POJ1083)的更多相关文章
- 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 ...
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ1083 Moving Tables
POJ1083 Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35297 Accepted: ...
- 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 ...
随机推荐
- ArcGIS AddIN开发之COM对象写入注册表
做一个交互式绘制文字的工具,希望这次设置的Symbol,下次打开ArcMap时自动调用这个Symbol,并支持对其进行修改. 解决方法是将这个Symbol写入注册表中,每次自动读取上一次设置的Symb ...
- oracle initialization or shutdown in progress问题解决步骤
今天像往常一样打开电脑,启动plsql工具连接数据库,但是尽然连接不了,报了“oracle initialization or shutdown in progress”的提示信息,从操作系统 ...
- oracle结构与安全
从宏观上来看:oracle数据库服务器主要有数据库和实例组成. 在orale数据库服务器中,首先会产生一个实例,通过实例访问一个数据库. 一个实例对应着一个数据库. oracle 数据库在逻辑上是按层 ...
- PLSQL Developer的使用
登陆服务器 除了 sys 用户登陆之外,其他都都选Normal 新建sql 窗口 编写执行sql语句 设置字体.颜色 工具——首选项——用户界面——字体——选择 工具——首选项——用户界面——编辑器— ...
- ios-获取通讯录 姓名和电话
#import "ViewController.h" #import <ContactsUI/ContactsUI.h> @interface ViewControll ...
- ExtJS笔记 Grids
参考:http://blog.csdn.net/zhangxin09/article/details/6885175 The Grid Panel is one of the centerpieces ...
- 为什么Visual Studio的安装目录下有名为1033或2052的文件夹?
一直不清楚MS诸多产品的安装目录下为什么总有个名为1033或者2052的目录 搜索一下才知道,原来叫 LCID(Locale ID,区域性标识符) 常见的如:1033表示英语(美国),2052表示中文 ...
- ArcGIS Server GP服务发布与测试(基础版)
版本:ArcGIS Server 10.4 环境:win10 测试目标:创建一个GP服务,功能为根据要素属性信息(如FID)选择出输入内容的对应匹配要素. 注:这个测试非常基础,仅供新手发布GP ...
- RabbitMQ学习总结 第三篇:工作队列Work Queue
目录 RabbitMQ学习总结 第一篇:理论篇 RabbitMQ学习总结 第二篇:快速入门HelloWorld RabbitMQ学习总结 第三篇:工作队列Work Queue RabbitMQ学习总结 ...
- dubbo源码分析5-dubbo的扩展点机制
dubbo源码分析1-reference bean创建 dubbo源码分析2-reference bean发起服务方法调用 dubbo源码分析3-service bean的创建与发布 dubbo源码分 ...