B - 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一直WA,查不出来,,,,后来偶然看到我的for循环是i《begin;i!=end;i++。。。。哎,平常写的手顺了,应该是〈=。下回要特别注意。附上25行代码:my answer:#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T,n;
cin>>T;
while(T--)
{
scanf("%d",&n);
int m=0,begin,end, sum[500]={0};
for(int i=0;i!=n;i++){
cin>>begin>>end;
begin = (begin - 1)/2;
end = (end - 1 )/2;
if(begin >end )swap(begin ,end );
if(m<end)m=end;
for(int j=begin;j<=end;j++)
sum[j]+=10;
}
printf("%d\n",*max_element(sum,sum+m));
}
return 0;
}有一点就是房间是要分奇偶的,上面那个有点不理解为啥要减一除以2.下面是我的代码:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T,n;
cin>>T;
while(T--)
{
scanf("%d",&n);
int m=0,begin,end, sum[500]={0};
for(int i=0;i!=n;i++){
cin>>begin>>end;
if(begin >end )swap(begin ,end );
if(end%2!=0) end++;
if(m<end)m=end;
for(int j=begin;j<=end;j++)
sum[j]+=10;
}
printf("%d\n",*max_element(sum,sum+m));
}
return 0;
}
B - Moving Tables的更多相关文章
- zstu.2512. Moving Tables(贪心)
Moving Tables Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1182 Solved: 563 Description The famo ...
- Moving Tables(贪心或Dp POJ1083)
Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28304 Accepted: 9446 De ...
- 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 ...
- Moving Tables
Moving Tables Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- uvalive 2326 - Moving Tables(区间覆盖问题)
题目连接:2326 - Moving Tables 题目大意:在一个走廊上有400个教室, 先在有一些桌子要移动, 每次移动需要十分钟, 但是不同房间的桌子可以在同一个十分钟内移动,只要走廊没有被占用 ...
- HDU1050(Moving Tables:贪心算法)
解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...
- POJ1083 Moving Tables
POJ1083 Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35297 Accepted: ...
随机推荐
- $(window).width() is not a function
昨天在帮同事调试JS的时候,FF报错了,$(window).width() is not a function.我以前也是这么用的,都没问题,为什么现在就报错了呢? 这是因为jQuery用" ...
- html系列教程--article audio
<article> 标签 <article> 标签规定独立的自包含内容.一篇文章应有其自身的意义,应该有可能独立于站点的其余部分对其进行分发. <article> ...
- 性能监控工具javamelody与spring的集成
详细信息可以访问javamelody的官方网站 我在集成的过程中,一直出现commonHibernateDao的加载问题, 另外,根据官方文档,如果你的应用与monitoring-spring.xml ...
- Java语言导学笔记 Chapter 9 IO
java.io 9.1.1 字符流 Reader为读取器(reader)提供API和部分实现,读取器是读取16位字符的流: Writer为写出器(writer)提供API和部分实现,写出器是写16位字 ...
- js获取input file完整路径的方法
function getPath(){ //判断浏览器 var Sys = {}; var obj = document.getElementById("headImg"); ...
- Android 如何让 app 自行处理 power key M
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- Linux网络管理——网关作用
1. 网络基础 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB",&q ...
- Android 内存管理之优化建议
OOM(OutOfMemory)转:http://hukai.me/android-performance-oom/ 前面我们提到过使用getMemoryClass()的方法可以得到Dalvik He ...
- linux 程序运行监控
一 . 使用supervise 是daemon-tools 的一个功能,系统的守护进程.在进程挂掉的时候可以自动重启. 二 安装 wget http://cr.yp.to/daemontools/ ...
- Probability theory
1.Probability mass functions (pmf) and Probability density functions (pdf) pmf 和 pdf 类似,但不同之处在于所适用的分 ...