zoukankan      html  css  js  c++  java
  • CF1236D Alice and the Doll(模拟)

    最重要的是观察到一点,最优策略一定是走到最远不能走的地方在转弯

    因为我们一旦转弯,就永远不能越过这条线,因为只能右转,其实就相当于一个蛇形

    所以只需要暴力模拟即可

     #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<ll,ll> pll;
    typedef pair<int,pll> plll;
    const int N=5e5+10;
    const int inf=0x3f3f3f3f;
    const int mod=1e9+7;
    vector<int> col[N],row[N];
    int main(){
        ios::sync_with_stdio(false);
        int n,m;
        ll k;
        cin>>n>>m>>k;
        int i;
        for(i=1;i<=k;i++){
            int a,b;
            cin>>a>>b;
            row[a].push_back(b);
            col[b].push_back(a);
        }
        ll sum=1;
        int mxrow=n,mirow=2,mxcol;
        int micol=1;
        int ed=m;
        int x=1,y=1;
        for(auto a:row[1]){
            if(a>y){
                ed=min(ed,a-1);
            }
        }
        sum+=ed-1;
        mxcol=ed-1;
        y=ed;
        while(1){
            ed=mxrow;
            for(auto a:col[y]){
                if(a>x){
                    ed=min(ed,a-1);
                }
            }
            if(ed==x)
                break;
            sum+=ed-x;
            x=ed;
            mxrow=ed-1;
            ed=micol;
            for(auto a:row[x]){
                if(a<y){
                    ed=max(ed,a+1);
                }
            }
            if(ed==y)
                break;
            sum+=y-ed;
            y=ed;
            micol=ed+1;
            ed=mirow;
            for(auto a:col[y]){
                if(a<x){
                    ed=max(ed,a+1);
                }
            }
            if(ed==x)
                break;
            sum+=x-ed;
            x=ed;
            mirow=ed+1;
            ed=mxcol;
            for(auto a:row[x]){
                if(a>y)
                    ed=min(ed,a-1);
            }
            if(ed==y)
                break;
            sum+=ed-y;
            y=ed;
            mxcol=ed-1;
        }
        if((ll)n*m-sum!=k){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
        return 0;
    }
    View Code
    没有人不辛苦,只有人不喊疼
  • 相关阅读:
    C艹目录
    C艹重复输入小方法,for循环+while
    python with 语句妙用
    python with妙用
    Kali配置网卡静态信息
    Spring 之 注解详解
    html基础之 表单提交方法
    html 基础之 <link>标签
    android:padding和android:margin的区别
    css基础之 font的简写规则 以及 自定义 CSS3 @font-face详细用法
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/13572271.html
Copyright © 2011-2022 走看看