免费馅饼

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

Appoint description: 
prayerhgq  (2015-07-28)
System Crawler  (2015-09-05)

Description

都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝,每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标: 

为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼) 
 

Input

输入数据有多组。每组数据的第一行为以正整数n(0<n<100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0<T<100000),表示在第T秒有一个馅饼掉在x点上。同一秒钟在同一点上可能掉下多个馅饼。n=0时输入结束。 
 

Output

每一组输入数据对应一行输出。输出一个整数m,表示gameboy最多可能接到m个馅饼。 
提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。

 

Sample Input

6
5 1
4 1
6 1
7 2
7 2
8 3
0
 

Sample Output

4
 
 
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; const int SIZE = ;
int DP[SIZE][];
struct Node
{
int pos,time;
}S[SIZE]; bool comp(const Node & r_1,const Node & r_2);
int main(void)
{
int n; while(scanf("%d",&n) && n)
{
memset(DP,,sizeof(DP));
for(int i = ;i < n;i ++)
scanf("%d%d",&S[i].pos,&S[i].time);
sort(S,S + n,comp); int ans = ;
for(int i = ;i < n;i ++)
{
int box = ;
if(S[i].time < abs(S[i].pos - ))
continue;
for(int j = ;j <= ;j ++)
for(int t = S[i].time - abs(S[i].pos - j);t >= ;t --)
if(DP[t][j])
{
box = max(box,DP[t][j]);
break;
}
DP[S[i].time][S[i].pos] = box + ;
ans = max(ans,box + );
}
printf("%d\n",ans);
} return ;
} bool comp(const Node & r_1,const Node & r_2)
{
return r_1.time < r_2.time;
}

怒刷DP之 HDU 1176的更多相关文章

  1. 怒刷DP之 HDU 1257

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. 怒刷DP之 HDU 1160

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  3. 怒刷DP之 HDU 1260

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

  4. 怒刷DP之 HDU 1087

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  5. 怒刷DP之 HDU 1114

    Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  6. 怒刷DP之 HDU 1069

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. 怒刷DP之 HDU 1024

    Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. 怒刷DP之 HDU 1029

    Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d &a ...

  9. 【DP】HDU 1176

    HDU 1176 免费馅饼 题意:中文题目不解释. 思路:因为是从中间出发所以思路卡了许久,还在之前做了道HIHO入门的题.能想到的点,从时间思考,然后初始化1s的时候,4,5,6,的数值要特别赋值. ...

随机推荐

  1. redis 重用命令

    一. set 1.smembers key 查看所有元素

  2. lua安装和简单使用

    1.安装 下载地址:https://www.lua.org/download.html 编译之前要安装readline,直接用yum安装 yum -y install readline-devel n ...

  3. 特现C语言编程特点的小代码,itoa,数值转换成字符串

    #define BASE_MAX (26 + 10) char const* itostr(int x, int base) { /* map 居中, 支技负余数 */ static char con ...

  4. [SQL]sql语句bug

    sql语句格式必须严格检查,一个空格的错误都会导致执行错误. 常见有 1:字符串的值要用  ‘  ’  括起来 2:用 , 分隔语句段 3:切记判断条件前有一空格:eg:这里最容易出错 4:属性名是否 ...

  5. 利用HTML5开发Android(6)---构建HTML5离线应用

    需要提供一个cache manifest文件,理出所有需要在离线状态下使用的资源例如 Manifest代码 CACHE MANIFEST #这是注释 images/sound-icon.png ima ...

  6. C#中的Collection 2

    Core Generic interface IEnumerable<T>:you can interate my elemnts, no need to know the count, ...

  7. MFC非模态对话框中屏蔽ESC键

    个人的编程经验认为:对于非模态对话框,按下ESC键和点击红叉都会响应OnCancel()函数,而不会去响应OnClose()函数. 我们都知道,如果想屏蔽Enter键,只须重写OnOK()函数即可(重 ...

  8. IIS网站程序无法访问oracle

    系统环境: win7 + iis7 asp.net应用程序访问oracle数据库时,报ORA-12560: TNS: 协议适配器错误. 使用c/s程序访问数据库没有问题,plsql也没问题,说明ora ...

  9. UVa11205 The Broken Pedometer

    // 题意:有P个LED灯,以及N个字符,要求选出个数最少的LED灯,使得即使只有这些灯正常工作,也能区分出这N个字符 // 题意抽象:输入两个整数P, N以及N行P列的01矩阵,找少的列,能区分所有 ...

  10. js密码强度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...