【Codeforces Round #641 (Div. 2) 】E. Orac and Game of Life

5 篇文章 0 订阅

考虑只有一个询问的情况。
把第一个回合就开始波动的点称为波动点。
询问 i,j,k时,我们先找到距离坐标(i,j)最近的波动点的距离,如果k小于这个距离,那么在第k回合波动还没有传到(i,j),(i,j)的颜色不改变。如果k大于这个距离,那么在波动传到(i,j)后,(i,j)的颜色每回合改变一次。
对于多个询问,将所有初始的波动点放入队列que中,整体宽搜,记录距离。

#include<bits/stdc++.h>
#define rep(i,b) for(int i=1;i<=b;i++)
#define drep(i,b) for(int i=b;i>=1;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pr pair<int,int>
#define ff first
#define ss second
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
int n,m,k,t,x,y,z;

int a[1005][1005],inque[1005][1005],dis[1005][1005];
string s[1005];
int X[]={0,0,1,0,-1},Y[]={0,1,0,-1,0};

bool check(int x,int y,int fg=1) {
    if(!x||!y||x>n||y>m) return false;
    if(fg&&inque[x][y]) return false;
    return true;
}

bool check1(int _x,int _y) {
    rep(i,4) {
        int x=_x+X[i],y=_y+Y[i];
        if(check(x,y,0)&&a[x][y]==a[_x][_y]) return true;
    }
    return false;
}

void solve(int ans=0) {
    int T;
    cin>>n>>m>>T;
    rep(i,n) cin>>s[i];
    rep(i,n) rep(j,m) a[i][j]=s[i][j-1]-'0';
    rep(i,n) rep(j,m) inque[i][j]=0,dis[i][j]=0;
    queue<pr> que;
    rep(i,n) rep(j,m) {
        if(check1(i,j)) {
            que.push(pr(i,j));
            inque[i][j]=1;
        }
    }
    int t=0;
    while(!que.empty()) {
        t++;
        queue<pr> que2;
        while(!que.empty()) {
            pr p=que.front();que.pop();
            int _x=p.ff,_y=p.ss;
            dis[_x][_y]=t;
            rep(i,4) {
                x=_x+X[i],y=_y+Y[i];
                if(check(x,y)) inque[x][y]=1,que2.push(pr(x,y));
            }
        }
        while(!que2.empty()) que.push(que2.front()),que2.pop();
    }
    while(T--) {
        cin>>x>>y>>k;
        if(!dis[x][y]||k<dis[x][y]) cout<<a[x][y]<<endl;
        else {
            int fg=(k-dis[x][y]+1)&1;
            cout<<(a[x][y]^fg)<<endl;
        }
    }
}

#undef int
int main() {
    ios::sync_with_stdio(false);
    //int T;cin>>T;
    //while(T--)
        solve();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值