Google Code Jam 2012 round 2 problem A: Swinging Wild

题目连接

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

做法: 直接模拟

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;
    }
}
Google Code Jam 2012 round 2 problem A: Swinging Wild

Google Code Jam 2012 round 2 problem A: Swinging Wild,布布扣,bubuko.com

Google Code Jam 2012 round 2 problem A: Swinging Wild

上一篇:跨程序共享数据,读取联系人信息


下一篇:WinRAR解压