传送门

文章目录

  • 题意:
  • 思路:

题意:

思路:

还以为这个题有什么高深的算法,结果就是个暴力。
由于n∗mn*mn∗m达到了1e101e101e10的级别,所以直接暴力肯定是不行的,考虑有很多空格,我们可以维护四个变量表示边界,让后在当前轴上二分最近的障碍点,让后判断即可。
实现的时候可以加两个边界比较方便。
要注意如果枚举的四个方向,如果有一个方向不能走的话不能直接退出,有如下样例:
333\ \ 33  3
0110\ \ 1\ \ 10  1  1
0110\ \ 1\ \ 10  1  1
0110\ \ 1\ \ 10  1  1
111代表障碍,一开始是向右走,显然不能走,如果直接退出就错了,我们还可以向下走。
只有这一种情况,所以特判一下是不是起点即可。

还有注意二分前先给数组排个序。。。
没排序卡了我半天。

// Problem: D. Alice and the Doll
// Contest: Codeforces - Codeforces Round #593 (Div. 2)
// URL: https://codeforces.com/contest/1236/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,m,k;
vector<int>x[N],y[N];int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);scanf("%d%d%d",&n,&m,&k);for(int i=1;i<=n;i++) x[i].pb(0);for(int i=1;i<=m;i++) y[i].pb(0);for(int i=1;i<=k;i++) {int xx,b; scanf("%d%d",&xx,&b);x[xx].pb(b); y[b].pb(xx);}for(int i=1;i<=n;i++) sort(x[i].begin(),x[i].end()),x[i].pb(m+1);for(int i=1;i<=m;i++) sort(y[i].begin(),y[i].end()),y[i].pb(n+1);int sx,ex,sy,ey;sx=sy=0; ex=n+1; ey=m+1;LL sum=0;int dx,dy; dx=dy=1;int op=0;while(1) {if(op%4==0) {int pos=lower_bound(x[dx].begin(),x[dx].end(),dy)-x[dx].begin();int add=min(x[dx][pos],ey);if(add-1<=dy) {if(op==0) {sum++; op++;continue;} else break;} sum+=add-dy;dy=add-1; ey=dy; sx=dx;} else if(op%4==1) {int pos=lower_bound(y[dy].begin(),y[dy].end(),dx)-y[dy].begin();int add=min(y[dy][pos],ex);if(add-1<=dx) break;sum+=add-dx;dx=add-1; ex=dx; ey=dy;} else if(op%4==2) {int pos=upper_bound(x[dx].begin(),x[dx].end(),dy)-x[dx].begin();pos--;int add=max(x[dx][pos],sy);if(add+1>=dy) break;sum+=dy-add;dy=add+1; sy=dy; ex=dx;} else if(op%4==3) {int pos=upper_bound(y[dy].begin(),y[dy].end(),dx)-y[dy].begin();pos--;int add=max(y[dy][pos],sx);if(add+1>=dx) break;sum+=dx-add;dx=add+1; sx=dx; sy=dy;}op++; }sum-=op-1;if(sum==1ll*n*m-k) puts("Yes");else puts("No");return 0;
}
/**/

Codeforces Round #593 (Div. 2) D. Alice and the Doll 暴力 + 二分相关推荐

  1. Codeforces Round #635 (Div. 2) D. Xenia and Colorful Gems 暴力 + 二分

    传送门 文章目录 题意: 思路: 题意: 给你三个数组a,b,ca,b,ca,b,c,让你从每个数组中选择一个数x,y,zx,y,zx,y,z,使得(x−y)2+(x−z)2+(y−z)2(x-y)^ ...

  2. Codeforces Round #723 (Div. 2) D. Kill Anton 线段树 + 暴力

    传送门 文章目录 题意: 思路: 题意: 给你一个只有ANTOANTOANTO四个字母的字符串,你每次可以交换相邻两个,花费为111,让后让你打乱字符串,使得将打乱的字符串还原为原来的字符串的花费最小 ...

  3. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  4. 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)

    [题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...

  5. Codeforces Round #401 (Div. 2) D. Cloud of Hashtags(暴力)

    D. Cloud of Hashtags time limit per test2 seconds memory limit per test256 megabytes inputstandard i ...

  6. Codeforces Round #645 (Div. 2) D - The Best Vacation 题解(二分+思维)

    题目链接 题目大意 一年有n个月,每个月有d[i]天,让你找出连续x天,使其日期的总和最大,可以跨年 题目思路 这里要发现一个性质:即连续的x天一定满足最后一天在月份的结尾,结论是显然的. 然后用两个 ...

  7. Codeforces Round #827 (Div. 4)A~G(模拟,暴力,前缀最大值,二分,二进制)

    签到题A~C A #include<bits/stdc++.h> using namespace std; int n,w,x,y;int a[100005],b[100005]; int ...

  8. Codeforces Round #643 (Div. 2)(A, B, C, D, E)

    Codeforces Round #643 (Div. 2) Sequence with Digits 思路 一道暴力题,猜想在某一步一定会出现0,于是怀着忐忑提交了代码,结果还真的是这样. 代码 # ...

  9. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) 思维 + 质因子

    传送门 文章目录 题意: 思路: 题意: 大体题意跟easyeasyeasy版本差不多,就是hardhardhard版本的aaa范围更大.见这里Codeforces Round #601 (Div. ...

最新文章

  1. Linux系统 误删除kvm虚拟机数据恢复方法-数据恢复成功案例
  2. SGU - 507 启发式合并维护平衡树信息
  3. kotlin 反射java类_关于Kotlin反射中实例化类的问题
  4. QT的QQmlPropertyMap类的使用
  5. 用户关联角色操作-代码实现
  6. IDEA基于kotlin开发android程序配置小结
  7. vue 文件转换二进制_vue项目将file转换成二进制流
  8. 深度学习入门(六)——计算机视觉简述
  9. McaFee企业版v8.0i设置指南
  10. 基于MATLAB函数mesh绘制由多张曲面围成的三维封闭曲面详解
  11. pymysql长时间连接自动断开解决方案
  12. 指针概念、指针大小和内存详解
  13. php7国内,介绍php7和php5对比
  14. jenkins下载插件失败的解决方案
  15. Note For Linux By Jes(7)-学习 shell scripts
  16. 前端学习系列——(九)理解什么是ID选择器的“唯一性”
  17. camera摄像原理之三:色温和自动白平衡
  18. MATLAB绘制柱状图
  19. AndroidCameraHAL3-相机都是怎么玩的
  20. 原生js+css实现带预览图片的幻灯片效果实例

热门文章

  1. 计算机与人脑的异同作文,小学信息技术3-6年级全册教案.pdf
  2. IT资料,重磅来袭!
  3. “一边熬夜一边求不要猝死”,90后养生朋克指南,条条扎心!
  4. 重磅大礼!100本《机器学习》by周志华,免费送!
  5. office 高效办公智慧树_干货高效实用的office办公小技巧之word篇
  6. 无法定位程序输入点dxgiget_美国ABB TZIDC 智能定位器调试方法
  7. headless 怎么处理_公司清算注销债务怎么处理
  8. php ip处理函数,PHP取ip地址函数
  9. 实现贝叶斯分类器_机器学习实战项目-朴素贝叶斯
  10. 显卡mx150和230哪个好_建模渲染用专业图形显卡和游戏显卡哪个更好?