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. Clojure 学习入门(19)—— 数组

    1.创建数组 1.1 从集合创建数组 into-array into-array (into-array aseq) (into-array type aseq) 演示样例: user=> (i ...

  2. ORACLE函数TO_CHAR以及数字转换格式[Z]

    本来这是很简单的函数,但在屡次忘记格式之后,决定还是翻译一遍以铭记在心.      参考<<Oracle Database SQL Reference>>.      关于nl ...

  3. 定时器——Cocos2d-x学习历程(十一)

    1.定时器 利用场景.层和精灵等游戏元素,我们可以构建游戏的框架,但是此时的游戏仍然是静止不动的.在一切游戏中,游戏的状态都会随着时间的流逝而改变,同时我们还需要定时进行一些逻辑判断,例如鱼和子弹的碰 ...

  4. leetcode Binary Tree Level Order Traversal python

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

  5. Linux下为何都是文件的理解

    所谓“文件”,就是在我们的电脑中,以实现某种功能.或某个软件的部分功能为目的而定义的一个单位. Linux都是以文件的形式存在,当我们访问某个文件(Linux中的文件有目录,连接,普通文本),由于Li ...

  6. jira 解决结果配置

    jira 的配置比较繁琐,有很多的小细节,使用中出现了各种小问题,总结梳理下 1.解决结果 问题1:编辑了任务后,解决结果变成了已解决 找到编辑任务所对应的界面方案,将解决结果字段从界面配置里移除 问 ...

  7. Linux----函数中变量的作用域、local关键字。

    问题引出: 问题说明: shell的函数中如果变量的前面没有加local关键字.在全局作用域内存在这个变量名的情况下.函数中会直接使用这个变量 而不是自己创建一个.要想做到在函数创建一个变量也是可以的 ...

  8. CSV 客座文章系列: Pruffi 通过 Windows Azure 挖掘社交媒体的强大招聘潜能

    编辑人员注释:今天这篇文章由 Pruffi 创始人 Alena Vladimirskaya 和 Pruffi 的 CTO Alexander Ivanov 联合撰写,介绍了该公司如何使用 Window ...

  9. c++ 关于类构造函数的初始化列表

    除了性能问题之外,有些时场合初始化列表是不可或缺的,以下几种情况时必须使用初始化列表 常量成员,因为常量只能初始化不能赋值,所以必须放在初始化列表里面 引用类型,引用必须在定义的时候初始化,并且不能重 ...

  10. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(二)

    这篇文章的理解,需要一些专业知识了. 我们可以创建模拟自己的外设吗? 我们已经知道什么是qemu了,我们可以通过qmeu的提供的外设,DIY一个计算机了. 但是我们可能还不满足,我们可以自己制造一个外 ...