D - Alice and the Doll 模拟题

在模拟的过程中走着走着死掉了。。。。。

题目链接:https://codeforces.com/contest/1236/problem/D

ac代码:

#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <set>
#include <iterator>
using namespace std;
typedef long long ll;
const int mx = 1e5+100;
const ll mod = 1e9+7;
set<ll>r[mx], c[mx];
ll dr[4];

int main()
{
    ll n, m, k;
    scanf("%lld%lld%lld", &n, &m, &k);

    for (int i = 0; i < k; ++i) {
        ll a, b;
        scanf("%lld%lld", &a, &b);
        r[a].insert(b);
        c[b].insert(a);
    }
    for (int i = 1; i <= n; ++i) r[i].insert(m+1), r[i].insert(0);
    for (int i = 1; i <= m; ++i) c[i].insert(n+1), c[i].insert(0);
    int f = 0;
    ll s1 = 0, a = 1, b = 1, st = 1, di = 0;
    dr[0] = m, dr[1] = n, dr[2] = 1, dr[3] = 1;
    while (f<2) {
        set<ll>::iterator x;
        ll xs;
        if (di == 0) {
            x = r[a].upper_bound(b);
            xs = min(*x-1, dr[0]);
            dr[3] = a+1;
            st = st+xs-b;
            b = xs;
        }
        if (di == 1) {
            x = c[b].upper_bound(a);
            xs = min(*x-1, dr[1]);
            dr[0] = b-1;
            st = st+xs-a;
            a = xs;
        }
        if (di == 2) {
            x = r[a].upper_bound(b);
            x--;
            xs = max(*x+1, dr[2]);
            dr[1] = a-1;
            st = st+b-xs;
            b = xs;
        }
        if (di == 3) {
            x = c[b].upper_bound(a);
            x--;
            xs = max(*x+1, dr[3]);
//            if (!f)C
            dr[2] = b+1;
            st = st+a-xs;
            a = xs;
        }
//        printf("%d %d %d %d %d\n", a, b, xs, di, st);
        di = (di+1)%4;
        if(s1 == st) break;
        s1 = st;
    }
    if (n*m-k == st) puts("Yes");
    else puts("No");
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值