• hdu 1176 免费馅饼


    。。免费馅饼
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 

    65536/32768 K (Java/Others)
    Total Submission(s): 24187    Accepted Submission(s): 8162

    Problem 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 <algorithm>
    #include <cctype>
    #include <stdlib.h>
    #include <cstring>
    #include <string>
    using namespace std;
    
    int dp[100003][12];
    int main()
    {
        int n,timend;
        while(scanf("%d",&n)==1&&n)
        {
            int timend=0,ans=0;memset(dp,0,sizeof(dp));//pay attention to initialize!!!!!!!!
            while(n--)
            {
                int x,t;
                scanf("%d%d",&x,&t);
                dp[t][x]++;
                timend=timend<t?t:timend;//record when did the time end
            }
            
            for(int i=timend-1;i>=0;i--)//because timend can not +1,in some situation
            {
                for(int j=0;j<=10;j++)//which means from one point marked as j to the end 
                {                        //and record the bigger number of pies in one pace(next 1s)
                    if(j==0){
                        dp[i][j]+=max(dp[i+1][j],dp[i+1][j+1]);//pay attention to the special location like 0, 10
                    }
                    else if(j==10){
                        dp[i][j]+=max(dp[i+1][j],dp[i+1][j-1]);
                    }
                    else{
                        dp[i][j]+=max(max(dp[i+1][j],dp[i+1][j-1]),max(dp[i+1][j-1],dp[i+1][j+1]));//2 2 compare,then campare 2 
                    }
                }
            }
            printf("%d
    ",dp[0][5]);//because gameboy sat point 5 originally.
        }
        
        return 0;
    }
  • 相关阅读:
    [原]OpenSSL SSL连接初始化部分解析
    [转]C++日志系统log4cxx使用总结
    js打字效果
    抓取网页Email地址
    jQuery语法总结及注意事项
    Reporting Services中参数说明(因为在框架中要在新的窗口打开报表,所以这理主要是rc:LinkTarget)
    jQuery性能优化指南
    安装文件制作总结
    alert弹出层(待完善……)
    我的tab页面,Jquery方便扩展
  • 原文地址:https://www.cnblogs.com/greenaway07/p/11225740.html
Copyright © 2020-2023  润新知