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;
    }
}
posted @ 2014-03-12 20:01  thermal  阅读(182)  评论(0编辑  收藏  举报