codeforces 673B B. Problems for Round(模拟)
题目链接:
2 seconds
256 megabytes
standard input
standard output
There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between two division according to the following rules:
- Problemset of each division should be non-empty.
- Each problem should be used in exactly one division (yes, it is unusual requirement).
- Each problem used in division 1 should be harder than any problem used in division 2.
- If two problems are similar, they should be used in different divisions.
Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other.
Note, that the relation of similarity is not transitive. That is, if problem i is similar to problem j and problem j is similar to problem k, it doesn't follow that i is similar to k.
The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following m lines contains a pair of similar problems ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). It's guaranteed, that no pair of problems meets twice in the input.
Print one integer — the number of ways to split problems in two divisions.
5 2
1 4
5 2
2
3 3
1 2
2 3
1 3
0
3 2
3 1
3 2
1
In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sample reminds you that the similarity relation is not transitive. Problem 3 is similar to both 1 and 2, but 1 is not similar to 2, so they may be used together.
题意:
把1到n这些数放到两个容器里,要求第一个容器里的任何数都小于第二个容器里的任何数,还有就是相似的不能放一块,相似没有传递性;
思路:
两个容器第一个记录最大值,第二个记录最小值,对每一对相似的数,小的放在第一个,大的放在第二个,同时检测是否满足最大值最小值,还要更新最大最小;
还有wa点就是两个容器不能为空;
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e5+;
int n,m;
int x[],y[];
int vis[];
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&x[i],&y[i]);
}
int flag1=,flag2=1e6+,mmin,mmax;
int s1=,s2=;
for(int i=;i<=m;i++)
{
mmin=min(x[i],y[i]);
mmax=max(x[i],y[i]);
if(mmin>=flag2||mmax<=flag1){cout<<""<<endl;return ;}
else
{
if(mmin>flag1)flag1=mmin;
vis[mmin]=;
s1++;
if(mmax<flag2)flag2=mmax;
vis[mmax]=;
s2++;
}
}
int num=;
int ans=;
for(int i=;i<=n;i++)
{
if(!vis[i]&&i>flag1&&i<flag2)
{
num++;
}
}
if(s1!=&&s2!=)
printf("%d\n",num+);
else printf("%d\n",num-);
return ;
}
codeforces 673B B. Problems for Round(模拟)的更多相关文章
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- codeforces 723B Text Document Analysis(字符串模拟,)
题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...
- Codeforces 749C:Voting(暴力模拟)
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
- Codeforces 702D Road to Post Office(模拟 + 公式推导)
题目链接:http://codeforces.com/problemset/problem/702/D 题意: 一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公 ...
- CodeForces 388A Fox and Box Accumulation (模拟)
A. Fox and Box Accumulation time limit per test:1 second memory limit per test:256 megabytes Fox Cie ...
- CodeForces 680A&680B&680C&680D Round#356
昨天晚上实在是=_=困...(浪了一天)就没有去打Codeforces 中午醒来看看题,还不太难. A题:模拟(水题 3minAC) // by Sirius_Ren #include <cst ...
随机推荐
- HTML网页滚动加载--mark一下
console控制台: >: function stroll(){ window.scrollTo(, document.body.scrollHeight); }; >: window. ...
- word2013 交叉引用添加参考文献的尾注编号,通过查找 ^# 替换为 [^&] 的方式添加中括号,在进行“更新域”操作后,中括号消失。
word2013 交叉引用添加的尾注编号,通过查找 ^# 替换为 [^&] 的方式添加中括号,用这个方法添加中括号很多次了,这次却出现问题:在进行“更新域”操作后,中括号消失. 详 ...
- ros使用罗技f710无线控制手柄
参考:blog.csdn.net/hcx25909/article/details/9042469 罗技F710无线控制手柄ROS下使用说明 安装手柄相关的包和驱动 sudo apt-get inst ...
- Codeforces 837 E Vasya's Function
Discription Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = ...
- Java并发编程实战 读书笔记(二)
关于发布和逸出 并发编程实践中,this引用逃逸("this"escape)是指对象还没有构造完成,它的this引用就被发布出去了.这是危及到线程安全的,因为其他线程有可能通过这个 ...
- vSphere 6.5支持512e,NVMe SSD呢?
原创 2017-01-12 朱朋博 金笑雨 企事录 2016年底,VMware终于宣布,从vSphere 6.5开始支持512e扇区格式了. 这当然是好事.不过,不黑不舒服斯基说:原来以前的版本连51 ...
- JS那些事儿——Gulp的入门使用
前言 新人使用gulp的一个记录. 首先对于第一个新事物,我会问gulp这是什么? 答:gulp是一个自动化构建工具,它可以做一些自动化的任务,比如: 检查Javascript 编译Sass(或Les ...
- 全志a13开发总结
这几天因为工作的原因,開始接触全志a13芯片,本人在网上搜集了好长时间,可是网上的资料对这方面的描写叙述是很少的, 所以,仅仅能靠数据手冊还有官网上面的英文文档进行开发了,下面仅仅是开发中的非常少的一 ...
- POJ 3928 Ping pong 树状数组模板题
開始用瓜神说的方法撸了一发线段树.早上没事闲的看了一下树状数组的方法,于是又写了一发树状数组 树状数组: #include <cstdio> #include <cstring> ...
- androidproject有红色叹号的解决方式
首先,查看SDK版本号,一般有两处.第一处是project.properties文件里的target=android-?改动成自己工程相应的SDK版本号.第二处是manifest文件里, androi ...