ccf 201604-4 游戏

任一时间t的可能位置=t-1所有可能位置移动一步的有效位置

#include<iostream>
#include<set>
using namespace std;
class tim{
    public:
        int a,b;
        tim(){a=b=-1;}
};
class dex{
    public:
        int r,c;
        dex(int x,int y) {r=x;c=y;}
        dex() {r=0;c=0;}
        bool operator<(const dex v)const{
        return r<v.r || (r==v.r && c<v.c);}
};
tim all[105][105];
int n,m,t;
int _min=9999+m*n;
set<dex> ww[2];
int main(){

    cin>>n>>m>>t;
    int r,c,a,b;
    while(t--){
        cin>>r>>c>>a>>b;
        all[r][c].a=a;
        all[r][c].b=b;
    }
    dex x;
    x.c=x.r=1;
    ww[0].insert(x);
    x.r=n;x.c=m;
    int t=0;
int f=0;
    while(ww[f].find(x)==ww[f].end()){
        ++t;
        int g=(f+1)&1;
        for(set<dex>::iterator it=ww[f].begin();it!=ww[f].end();it++){
            int xx=it->r+1,yy=it->c;
            if(xx>0 && xx<=n && yy>0 && yy<=m && (t< all[xx][yy].a || t>all[xx][yy].b)) ww[g].insert(dex(xx,yy));
            xx=it->r-1;
            if(xx>0 && xx<=n && yy>0 && yy<=m && (t< all[xx][yy].a || t>all[xx][yy].b)) ww[g].insert(dex(xx,yy));
            xx=it->r,yy=it->c+1;
            if(xx>0 && xx<=n && yy>0 && yy<=m && (t< all[xx][yy].a || t>all[xx][yy].b)) ww[g].insert(dex(xx,yy));
            xx=it->r,yy=it->c-1;
            if(xx>0 && xx<=n && yy>0 && yy<=m && (t< all[xx][yy].a || t>all[xx][yy].b)) ww[g].insert(dex(xx,yy));
        }
        ww[f].clear();
        f=g;
    }
    cout<<t<<endl;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值