Google Code Jam 2012 round 2 problem A: Swinging Wild

题目连接

题意:你要从起点经过绳子荡到终点,每次你必须抓住另一个绳子,在空中不能向下爬。问是否有合理的方案

做法: 直接模拟

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <functional>
#include <cmath>
#include <stack>
typedef long long ll;
using namespace std;
int n,t,D;
int l[10001],d[10001];
struct st
{
    int l;
    int d;
    st(int a,int b){
        this->l = a;
        this->d = b;
    }
};
int main(){
    freopen("in.txt","r",stdin);
    freopen("out2.txt","w",stdout);
    ios::sync_with_stdio(0);
    cin>>t;
    int cs = 0;
    while(cs<t){
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>l[i]>>d[i];
        cin>>D;
        bool ok = false;
        stack<st> qu;
        vector<bool> inqu(n);
        qu.push(st(0,l[0]));
        inqu[0] = true;
        while(!qu.empty()){
            st cur = qu.top();
            qu.pop();
            if ( l[cur.l]+cur.d>=D)
            {
                ok = true;
                break;
            }
            for(int i=cur.l+1;i<n;i++){
                if(l[cur.l]+cur.d>=l[i]){
                    if(!inqu[i]){
                        qu.push(st(i,min(d[i],l[i]-l[cur.l])));
                        inqu[i] = true;
                    }

                }else{
                    break;
                }
            }
        }
        cout<<"Case #"<<++cs<<": "<<(ok?"YES":"NO")<<endl;
    }
}

转载于:https://www.cnblogs.com/across-fun/p/3597153.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值