K - 简单dp

Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Submit Status

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 file. 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 3 + N -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
题目大意:有400个房屋,需要在这些房屋之间搬运箱子,但是同一段走廊在每10分钟只能进行一次搬运,问你最少要多少分钟才能完成搬运任务。
思路分析:我看题目分类这道题是划分在dp里面的,刚开始一直想构造状态转移方程,就是没有弄出来,后来看了别人的题解,才造用贪心做,直接
记录每个区间的访问次数,访问最大次数*10就是需要的最短时间。
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int maxn=400+10;
const int inf=0xffffff;
int t[maxn];
int main()
{
     int T,n,a,b;
     cin>>T;
     while(T--)
     {
         scanf("%d",&n);
         mem(t);
         int ma=-inf;
         for(int i=0;i<n;i++)
         {
             scanf("%d%d",&a,&b);
             if(a>b) swap(a,b);
             if(a%2==0) a--;
             if(b%2==1) b++;
             for(int j=a;j<=b;j++)
               t[j]++;
         }
         for(int i=1;i<=400;i++)
         {
             ma=max(ma,t[i]);
         }
         cout<<10*ma<<endl;
     }
    return 0;
}

poj1083 贪心的更多相关文章

  1. Moving Tables(贪心或Dp POJ1083)

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

  2. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  3. HDOJ 1051. Wooden Sticks 贪心 结构体排序

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

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  8. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  9. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

随机推荐

  1. Ubuntu与Ubuntu系统之间的mount挂载

    1.被挂载机 1>安装Ubuntu nfs apt-get install nfs-kernel-server 2>配置/etc/exports Ubuntu nfs允许挂载的目录及权限在 ...

  2. python之6-5偏函数

    functools.partial 偏函数的作用是简化操作,简化什么操作呢?就是当我们有一个已知函数A,且这个函数包含有某个或多个参数A1,通过固定这个参数A1,我们可以自己编写一个新函数B,来减少代 ...

  3. mongoDB初探

    最近在努力学习node方面的东西,看别人的资料里提到最多用到的数据库还是mongoDB,早打算下载下来试一下,由于电脑新配置,网络也由于住的地方现在上不了网暂时用的手机4G网络在凑合,这里面也踩到了不 ...

  4. jquery easyui根据需求二次开发记录

    1.tree需要显示多个图标 实际需求:设备树上节点需搁三个图片,分别标识运行状态.告警状态.设备类型 解决方法:给tree的iconCls传入一个数组,分别是各状态下的class(css),然后要改 ...

  5. 深入理解7816(5)-----关于文件DF/EF/MF/FID/AID/SFI

    刚开始接触CPU卡的时候,对于各种文件.应用的定义容易模糊不清,通常不能准确地界定什么是文件?什么是应用?DF和EF的区别真的就像计算机里的目录和文档那样吗?FID.AID.SFI这些概念都在什么时候 ...

  6. windows进程间通讯的方法

    版权声明 请尊重原创作品.转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正.   1.使用共享内存 代码如下: void FileMapp ...

  7. 构建WDK驱动出现fatal error U1087: cannot have : and :: dependents for same target

    原因:WDK在编译驱动时,是不允许源文件所在的路径(全路径)中包含空格的,如果你包含了空格,就会出现上述错误. 解决方法:把源文件放在一个没有空格的路径下. reference: http://blo ...

  8. 【hihoCoder第十五周】最近公共祖先·二

    老实说我没有读题,看见标题直接就写了,毕竟hiho上面都是裸的算法演练. 大概看了下输入输出,套着bin神的模板,做了个正反map映射,但是怎么都得不了满分.等这周结束后,找高人询问下trick. 若 ...

  9. Quartz定时调度CronTrigger时间配置格式说明与实例

    1.   CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 ...

  10. 应用Observer接口实践Observer模式

    原文:http://zhangjunhd.blog.51cto.com/113473/68949/ 在Java中通过Observable类和Observer接口实现了观察者模式.Observer对象是 ...