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. javascript第四课变量作用域

    局部变量: function f1() { var n1=0;  //局部变量 n1=10; //全局变量,当前页面均可调用 } n1=10;//全局变量 var n1=10;//全局变量 在方法内的 ...

  2. bootstrap-js(5)工具提示tooltip

    实例 当您想要描述一个链接的时候,工具提示(Tooltip)就显得非常有用.工具提示(Tooltip)插件是受 Jason Frame 写的 jQuery.tipsy 的启发.工具提示(Tooltip ...

  3. Php开源项目大全

    WordPress  [PHP开源 博客Blog] WordPress是最热门的开源个人信息发布系统(Blog)之一,基于PHP+MySQL构建.WordPress提供的功能包括: 1.文章发布.分类 ...

  4. Sql Service存储过程分页

    一起是用oracle数据库..感觉oracle数据库强大.查询速度是杠杠的.换了家公司用的是SQL SERVICE.以前用了1年现在捡回以前的记忆.动手写了动态SQL过存储过程分页.感觉和oracle ...

  5. lightoj 1064 Throwing Dice

    题意:给你n个骰子,求n个骰子的和不小于x的概率. 刚开始想每给一组数就计算一次~~太笨了- -,看了别人的代码,用dp,而且是一次就初始化完成,每次取对应的数据就行了.WA了好多次啊,首先不明白的就 ...

  6. leetcode Invert Binary Tree python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

  7. Java学习之System.arraycopy()方法

    java.lang.System的静态方法arraycopy()可以实现数组的复制,讲课的老师说这个方法效率比较高,如果数组有成千上万个元素,那么用这个方法,比用for语句循环快不少.System提供 ...

  8. 测试通用的InsertOrUpdate

  9. HTML中的uniqueID

    Web页面上元素的name属性本身是可以重复的,理论上讲id是不可以重复的,但是现在的浏览器对重复的id都是默许的,可能有时候页面是需要一个唯一编号的.IE浏览器为页面上的所有元素都是提供了一个唯一名 ...

  10. iOS下移除按钮原生样式

    按钮样式,在 Android 手机浏览器中显示正常,但在 iOS Safari 浏览器中会看到按钮显示为圆角样式,设置 border-radius:0; 也不好使. 这是因为iPhone.iPad 设 ...