zoukankan      html  css  js  c++  java
  • POJ 1925 Spiderman



    Spiderman
    Time Limit: 5000MSMemory Limit: 65536K
    Total Submissions: 5858Accepted: 1143

    Description

    Dr. Octopus kidnapped Spiderman's girlfriend M.J. and kept her in the West Tower. Now the hero, Spiderman, has to reach the tower as soon as he can to rescue her, using his own weapon, the web. 

    From Spiderman's apartment, where he starts, to the tower there is a straight road. Alongside of the road stand many tall buildings, which are definitely taller or equal to his apartment. Spiderman can shoot his web to the top of any building between the tower and himself (including the tower), and then swing to the other side of the building. At the moment he finishes the swing, he can shoot his web to another building and make another swing until he gets to the west tower. Figure-1 shows how Spiderman gets to the tower from the top of his apartment – he swings from A to B, from B to C, and from C to the tower. All the buildings (including the tower) are treated as straight lines, and during his swings he can't hit the ground, which means the length of the web is shorter or equal to the height of the building. Notice that during Spiderman's swings, he can never go backwards. 
    POJ 1925 Spiderman - qhn999 - 码代码的猿猿

    You may assume that each swing takes a unit of time. As in Figure-1, Spiderman used 3 swings to reach the tower, and you can easily find out that there is no better way.

    Input

    The first line of the input contains the number of test cases K (1 <= K <= 20). Each case starts with a line containing a single integer N (2 <= N <= 5000), the number of buildings (including the apartment and the tower). N lines follow and each line contains two integers Xi, Yi, (0 <= Xi, Yi <= 1000000) the position and height of the building. The first building is always the apartment and the last one is always the tower. The input is sorted by Xi value in ascending order and no two buildings have the same X value.

    Output

    For each test case, output one line containing the minimum number of swings (if it's possible to reach the tower) or -1 if Spiderman can't reach the tower.

    Sample Input

    2
    6
    0 3
    3 5
    4 3
    5 5
    7 4
    10 4
    3
    0 3
    3 4
    10 4

    Sample Output

    3
    -1

    Source

    Beijing 2004 Preliminary@POJ 



    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    typedef long long LL;

    LL x[5555],h[5555];
    int  n;
    LL dp[2000002];

    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
                scanf("%I64d%I64d",x+i,h+i);
            memset(dp,63,sizeof(dp));
            dp[x[1]]=0;
            for(int i=2;i<=n;i++)
            {
                for(int j=x-1;j>=x[1];j--)
                {
                    LL d=(j-x)*(j-x)+(h-h[1])*(h-h[1]);
                    if(d>h*hbreak;
                    dp[2*x-j]=min(dp[2*x-j],dp[j]+1);
                }
            }
            LL ans=0x3f3f3f3f;
            for(int i=x[n];i<=2*x[n];i++)
                ans=min(ans,dp);
            if(ans>=0x3f3f3f3f)
                ans=-1;
            printf("%d ",ans);
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )

  • 相关阅读:
    找最后的字符
    统计指定数字和
    班级排队
    python编程题
    python函数题
    2019.6.24-2019.6.28(实训数据结构)3.数组编码求解问题
    2019.6.24-2019.6.28(实训数据结构)1.商品管理系统实训c++(实现的基本功能:初始化,创建表,插入,删除,更新,查询,链表数据与文件之间的转换)
    2019.6.24-2019.6.28(实训数据结构) 2.背包问题
    2019.6.24-2019.6.28(实训数据结构)4.树和二叉树应用项目
    2019.6.24-2019.6.28(实训数据结构)5.图的邻接矩阵表示
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350841.html
Copyright © 2011-2022 走看看