B - Moving Tables

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d
& %I64u

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
一直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的更多相关文章

  1. zstu.2512. Moving Tables(贪心)

     Moving Tables Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1182  Solved: 563 Description The famo ...

  2. Moving Tables(贪心或Dp POJ1083)

    Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28304   Accepted: 9446 De ...

  3. HDOJ 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. Moving Tables

    Moving Tables Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  6. hdoj 1050 Moving Tables【贪心区间覆盖】

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. uvalive 2326 - Moving Tables(区间覆盖问题)

    题目连接:2326 - Moving Tables 题目大意:在一个走廊上有400个教室, 先在有一些桌子要移动, 每次移动需要十分钟, 但是不同房间的桌子可以在同一个十分钟内移动,只要走廊没有被占用 ...

  8. HDU1050(Moving Tables:贪心算法)

    解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...

  9. POJ1083 Moving Tables

    POJ1083 Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35297   Accepted: ...

随机推荐

  1. How to change a product dropdown attribute to a multiselect in Magento

    First, update the attribute input type to multiselect: UPDATE eav_attribute SET entity_type_id ', at ...

  2. iOS 的 APP 如何适应 iPhone 5s/6/6Plus 三种屏幕的尺寸?(转)

    原文:http://www.niaogebiji.com/article-4379-1.html?utm_source=tuicool 初代iPhone 2007年,初代iPhone发布,屏幕的宽高是 ...

  3. android实现点击短链接进入应用 并获得整个连接的内容

    例如:我收到一个短信是一个链接:http://www.qq.com/a/b/?, 当我点击以后我要实现的场景是:点击----->有两种情况可供选择:手机中有此应用,跳转到应用:反之,则进入网页. ...

  4. clientX,pageX,screenX,offsetLeft,scrollTop

    出处:点击打开链接 一直不太明白,今天看了一下,感觉挺详细,先转载过来....... clientX 观点:鼠标相对于WINDOWS的坐标. 这里这个WINDOWS是指我们能看见的浏览器大小.所以不可 ...

  5. nide.js(二)文件I/O

    文件I/O fs模块的基本用法 node.js中提供一个名为fs的模块来支持I/O操作,fs模块的文件I/O是对标准POSIX函数的简单封装. 1.writeFile函数的基本用法 文件I/O,写入是 ...

  6. svn代码版本管理

    1.0开发,做dev1.0的branch此时的目录结构svn://proj/             +trunk/ (不负担开发任务)             +branches/          ...

  7. Java SE基础部分——常用类库之SimpleDateFormat(日期格式化)

    取得当前日期,并按照不同日期格式化输入.代码如下: // 20160618 SimpleDateFomat类的使用 日期格式化 练习 package MyPackage; //自己定义的包 impor ...

  8. 我也能上google

    之所以起个这么隐晦的标题就是因为怕被黑.但是不能上谷歌,对于我们搞技术的人来说真的很残忍. 目前只找到几个镜像网址: https://xie.lu/ https://www.gotosearch.in ...

  9. 将控制台程序做成windows服务

    一:添加windows服务 二:修改XXXInstaller1的StartType=Automatic,修改ProcessInstaller1的Account=LocalSystem 三:在progr ...

  10. OC语法1——OC概述

    Object-C简介: OC,即Object-C,iOS开发的核心语言.它是基于C语言的,在C的基础上做了面向对象的封装,所以OC是面向对象的语言.同时也因此OC是兼容C的,也就是说在iOS开发中,可 ...