题意:给定一个2*N的方格,从左上角开始走,有些格子不能走,问能否一次遍历所有能走的方格

在Gym上看到一场香港的比赛,很好奇就去看了一下,发现第一题很有趣,并且很水,似乎讨论一下奇偶性就行了,然后。。。我Wa了五次。。。

主要是以下三种情况比较坑:

#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000+10
struct point{int x,y;}p[MAXN];
int n,m,tot;
bool cmp(point a,point b){return a.x<b.x;}
int main(){
scanf("%d%d",&n,&m);
bool flag=;
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
swap(x,y);
if(x==&&y==){printf("No\n");return ;}
if(x==&&y==)flag=;
p[i].x=x;p[i].y=y;
}
if(flag){
sort(p+,p+m+,cmp);
tot=;
int t=m;
while(t){
if(p[t].x==p[t-].x){
if(p[t].x!=n){printf("No\n");return ;}
else {n--;m-=;}
}
else break;
t-=;
}
for(int i=;i<m;i++){
if(tot==*n-m)break;
if(p[i].y!=p[i+].y){
int dis=p[i+].x-p[i].x;
if(dis==){
if(tot==*n-m-)break;
else{printf("No\n");return ;}
}
else if(dis&){printf("No\n");return ;}
tot+=*(dis-)+;
}
else{
int dis=p[i+].x-p[i].x;
if(!(dis&)){printf("No\n");return ;}
tot+=*(dis-)+;
}
}
}
else{
m++;p[m].x=;p[m].y=;
tot=;
sort(p+,p+m+,cmp);
int t=m;
while(t){
if(p[t].x==p[t-].x){
if(p[t].x!=n){printf("No\n");return ;}
else {n--;m-=;}
}
else break;
t-=;
}
for(int i=;i<m;i++){
if(tot==*n-(m-))break;
if(p[i].y!=p[i+].y){
int dis=p[i+].x-p[i].x;
if(dis&){printf("No\n");return ;}
tot+=*(dis-)+;
}
else{
int dis=p[i+].x-p[i].x;
if(!(dis&)){printf("No\n");return ;}
tot+=*(dis-)+;
}
}
}
printf("Yes\n");
return ;
}

Codeforces Gym 101521A Shuttle Bus的更多相关文章

  1. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  2. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  3. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  4. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  5. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  6. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  7. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

  8. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

  9. codeforces Gym 100187J J. Deck Shuffling dfs

    J. Deck Shuffling Time Limit: 2   Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

随机推荐

  1. zookeeper启动异常

    zookeeper启动报异常 java.io.EOFException  at java.io.DataInputStream.readInt(DataInputStream.java:392) 遇到 ...

  2. babel从入门到入门

    babel从入门到入门 来源 http://www.cnblogs.com/gg1234/p/7168750.html 博客讲解内容如下: 1.babel是什么 2.javascript制作规范 3. ...

  3. C++获取基类指针所指子类对象的类名

    我们在程序中定义了一个基类,该基类有n个子类,为了方便,我们经常定义一个基类的指针数组,数组中的每一项指向都指向一个子类,那么在程序中我们如何判断这些基类指针是指向哪个子类呢? 关键字 typeid, ...

  4. python抓去网页一部分

    import sys, urllib2 headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9. ...

  5. Hacker Rank: Kingdom Division 不完全报告

    原题链接: Kingdom Division 由于树的层次可能很深,所以这里不能使用递归版的DFS.我使用了BFS. BFS确定各结点的父结点和它的孩子数. 用逆拓扑排序确定结点的计算顺序. same ...

  6. VS2013创建Windows服务

    一.创建服务 1.文件->新建->项目->windows桌面->windows服务,修改你要的项目名称.我这不改名,仍叫WindowsService1,确定. 2.其中的Pro ...

  7. ldap数据库--ODSEE--ACI

    查看跟DN下的aci ldapsearch -h hostname -p port -D "cn=Directory Manager" -w - -b "BASE_DN& ...

  8. 全排列Permutations

    描述 Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the foll ...

  9. [转载] Storm:最火的流式处理框架

    转载自http://www.cnblogs.com/langtianya/p/5199529.html 伴随着信息科技日新月异的发展,信息呈现出爆发式的膨胀,人们获取信息的途径也更加多样.更加便捷,同 ...

  10. MySQL原理相关

    1.索引 http://blog.codinglabs.org/articles/theory-of-mysql-index.html