C. NEKO's Maze Game

题目:C. NEKO’s Maze Game

唉~,可惜一次上分的机会。

题解:对于点x,y,如果它的(上/下)侧有,或者顶角有,对于为1的,就加。否则就减。

#include 
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const ll mod = 1e9+7;
const int inf = 0x7FFFFFFF;

int vis[3][N];
int n,q;
int op[6][2]={1,1,1,0,1,-1,-1,1,-1,-1,-1,0};


int fun(int x,int y){
    int cnt = 0;
    vis[x][y] = (vis[x][y]+1)%2;
    for(int i = 0;i < 6;i++){
        int e = x+op[i][0];
        int f = y+op[i][1];
        if(e>=1&&e<=2&&f>=1&&f<=n){
            if(vis[e][f] == 1) cnt++;
        }
    }
    if(vis[x][y] == 0) return -1*cnt;
    return cnt;
}
int main(){
    int ans = 0;
    cin >> n >> q;     
    while(q--){
        int x,y;
        scanf("%d%d",&x,&y);
        ans += fun(x,y);
        if(ans > 0){
            cout<<"No"<

你可能感兴趣的:(Codeforces)