cf Ping-Pong (Easy Version)
http://codeforces.com/contest/320/problem/B
这道题看了很长时间没看懂, 就是个dfs;
#include <cstdio>
#include <cstring>
#define maxn 2000
using namespace std; int a[maxn],b[maxn];
bool vis[maxn];
int cnt=; bool dfs(int x,int y)
{
vis[x]=true;
if(x==y) return ;
for(int i=; i<=cnt; i++)
{
if(!vis[i]&&((a[i]<a[x]&&a[x]<b[i])||(a[i]<b[x]&&b[x]<b[i])))
{
if(dfs(i,y)) return true;
}
}
return false;
} int main()
{
int n,x,y,c;
scanf("%d",&n);
memset(vis,false,sizeof(vis));
for(int i=; i<=n; i++)
{
scanf("%d%d%d",&c,&x,&y);
if(c==)
{
a[cnt]=x; b[cnt++]=y;
}
else
{
memset(vis,false,sizeof(vis));
if(!dfs(x,y)) printf("NO\n");
else printf("YES\n");
}
}
return ;
}
cf Ping-Pong (Easy Version)的更多相关文章
- CF #579 (Div. 3) D1.Remove the Substring (easy version)
D1.Remove the Substring (easy version) time limit per test2 seconds memory limit per test256 megabyt ...
- HDU 2492 Ping pong (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...
- UVALive 4329 Ping pong
Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Fo ...
- Ping-Pong (Easy Version)(DFS)
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...
- ZOJ 3868 - Earthstone: Easy Version
3868 - Earthstone: Easy Version Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld ...
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- LA4329 Ping pong(树状数组与组合原理)
N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...
- Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3928 Ping pong
题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
- Frequent values && Ping pong
Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最 ...
随机推荐
- 【HDOJ】2577 How to Type
DP. /* 2577 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...
- [原创]HTML5 web性能监控策略
web性能重要指标--时长 通常在监控前端页面性能的时候,我们会需要获取到很多的时间戳,比如用户按下回车的时候开始计时,但这个时候,我们统计的js代码并没有加载过来,也无法读取到相关的信息.在HTML ...
- JAVA 并发实现六(Volatile的使用)
Java™ 语言包含两种内在的同步机制:同步块(或方法)和 volatile 变量. 这两种机制的提出都是为了实现代码线程的安全性.其中 Volatile 变量的同步性较差(但有时它更简单并且开销更低 ...
- js日期和毫秒相互转换
var date = new Date(); var n = date.valueOf() var date2 = new Date(n); console.info(date.valueOf()); ...
- 【C#基础】json数据解析
1.简单的获取某个键值 JToken jtoken = JToken.Parse(jsonStr); string jsjid = jtoken.Value<string>("J ...
- window+Apache 配置虚拟主机(2)
1. 打开虚拟主机功能 2. 设置虚拟主机相应的文件夹 3. 将虚拟的域名绑定到127.0.0.1 4. 结果图: 记忆一下,突然感觉都忘记了!
- 安装orcle10g oel5.6
一.安装OEL 5.6 二.安装VMware Tools 1) 选择菜单里的VM选项,里面有一个子选项是installVMware Tools,选择它. 2) 回到操作系统,将光驱挂载到/mnt ...
- UVA 10651 Pebble Solitaire(bfs + 哈希判重(记忆化搜索?))
Problem A Pebble Solitaire Input: standard input Output: standard output Time Limit: 1 second Pebble ...
- gcc和g++编译c或者c++文件碰到的问题
gcc和g++都是GNU(组织)的一个编译器. 误区一:gcc只能编译c代码,g++只能编译c++代码 两者都可以,但是请注意: 1.后缀为.c的,gcc把它当作是C ...
- Python-xml解析常用方法简介
[XML几种解析方法] 常见的XML编程接口有DOM和SAX,这两种接口处理XML文件的方式不同,使用场合自然也就不同. Python有三种方法解析XML: SAX,DOM,以及ElementTree ...