zoukankan      html  css  js  c++  java
  • NYOJ613 免费馅饼

     

    免费馅饼

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

    为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)
     
    输入
    输入数据有多组。每组数据的第一行为以正整数n(0<n<100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0<T<100000),表示在第T秒有一个馅饼掉在x点上。同一秒钟在同一点上可能掉下多个馅饼。n=0时输入结束。
    输出
    每一组输入数据对应一行输出。输出一个整数m,表示gameboy最多可能接到m个馅饼。
    提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。
    样例输入
    6
    5 1
    4 1
    6 1
    7 2
    7 2
    8 3
    0
    样例输出
    4
    来源
    hdu
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 
     5 using namespace std;
     6 
     7 int pie[11][100001], res[11][100001];
     8 int maxt, ans;
     9 
    10 int max(int a, int b)
    11 {
    12     return a > b ? a : b;
    13 }
    14 
    15 int BFS(int pos, int tim)
    16 {
    17     if(res[pos][tim] >= 0)
    18         return res[pos][tim];
    19     if(tim > maxt)
    20         return 0;
    21     int t1, t2, t3;
    22     t1 = t2 = t3 = 0;
    23     t1 = BFS(pos, tim+1)+pie[pos][tim+1];
    24     if(pos > 0)
    25         t2 = BFS(pos-1, tim+1)+pie[pos-1][tim+1];
    26     if(pos < 10)
    27         t3 = BFS(pos+1, tim+1)+pie[pos+1][tim+1];
    28     return res[pos][tim] = max(t1, max(t2, t3));
    29 }
    30 
    31 int main()
    32 {
    33     int n, x, t;
    34     while(scanf("%d", &n), n)
    35     {
    36         memset(pie, 0, sizeof(pie));
    37         memset(res, -1, sizeof(res));
    38         maxt = -1;
    39         while(n--)
    40         {
    41             scanf("%d%d", &x, &t);
    42             if(t > maxt)
    43                 maxt = t;
    44             ++pie[x][t];
    45         }
    46         ans = 0;
    47         printf("%d\n", BFS(5, 0));
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    Git push 出现 refusing to merge unrelated histories
    The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.
    Linux离线安装docker&docker-compose
    mybatis新增记录使用 useGeneratedKeys无法返回主键
    Docker 修改容器内的时区
    快排写法
    c++学生信息管理系统(window控制台实现鼠标点击操作)
    洛谷P1006 传纸条(多维DP)
    二维bit模板
    一个milller_rabin模板
  • 原文地址:https://www.cnblogs.com/dongsheng/p/3138634.html
Copyright © 2011-2022 走看看