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 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.
Input
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.
Output
Print one integer — the number of ways to split problems in two divisions.
Sample Input
5 2
1 4
5 2
Sample Output
2
题意
有n道题,他们的编号就是他们的难度,你需要把这些题目分到div1和div2去
div1的题目难度都应该比div2高
现在给你m个关系,a[i],b[i]表示,a[i]和b[i]应该在不同的div
问你一共有多少种分类的方式
题解:
枚举每一个位置,前面的全部扔到div2去,后面的全部扔到div1去
看是否合法就好了
前面的不能有div1的题目,后面的不能有div2的,就检查这个就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
int a[maxn],b[maxn],flag[maxn],n,m,ma[maxn],mi[maxn];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&a[i],&b[i]);
if(a[i]>b[i])swap(a[i],b[i]);
if(flag[a[i]]==2)return puts("0");
if(flag[b[i]]==1)return puts("0");
flag[a[i]]=1,flag[b[i]]=2;
}
for(int i=1;i<=n+1;i++)
ma[i]=0,mi[i]=100;
for(int i=1;i<=n;i++)
ma[i]=max(ma[i-1],flag[i]);
for(int i=n;i>=1;i--)
{
if(flag[i]==0)mi[i]=mi[i+1];
else
{
if(mi[i+1]==100)mi[i]=flag[i];
else mi[i]=min(flag[i],mi[i+1]);
}
}
int ans = 0;
for(int i=1;i<n;i++)
if(ma[i]<=1&&mi[i+1]>=2)ans++;
cout<<ans<<endl;
}
Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题的更多相关文章
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B
B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabyte ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造
D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D
D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- 在c++中实现反射的初步想法
最近在思考如何在c++中实现反射.事情的起因是这样的:我们服务器是用c++开发的,如果需要写一些测试用的GM指令的话,需要编写完GM代码后重新编译并且重启进程,工序繁琐且比较耗时.因此就有了想用脚本( ...
- mariadb/mysql使用Navicat连接报错
[问题1] 使用Navicat连接服务器的mariadb/mysql时报错 access denied for user root@192.168.xx.xx(using password:yes) ...
- linux 下用户组、文件权限详解
参考资料:http://www.cnblogs.com/123-/p/4189072.html
- java基础27 单例集合Collection及其常用方法
1.集合 集合是存储对象数据的集合容器 1.1.集合比数组的优势 1.集合可以存储任意类型的数据,数组只能存储同一种数据类型的数据 2.集合的长度是变化的,数组的长度是固定的 1.2.数组:存储 ...
- Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor
Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor */--> div ...
- KDE 下 U 盘挂载失败
重装完 KDE 后发现在 dolphin 中无法挂载 U 盘了,提示 unable to authenticate.但是用 udisksctl 却可以挂载: yyc@TDesk run > ud ...
- KnockoutJs学习笔记(一)
由于工作需要,接触到了Knockout,但是之前对于前台开发真的是不太了解,只能是摸着石头过河,边学边实践了. Knockout的官方网站是:http://knockoutjs.com/.我也是跟着官 ...
- mvc的cshtml Request取不到值
如果路径为:http://localhost:2317/food/1,这时用Request["id"]是取不到值的应该用: Request.RequestContext.Route ...
- 一步一步学习IdentityServer4 (2) 开始一个简单的事例
前面将来一些配置,但是很多都不是必要的,先放一些事例需要的简要配置把 既然是IdentityServer4 所里下面的例子我 直接放到 Linux上 测试环境 CentOS 7 +Nginx1.9.3 ...
- CCF CSP 201512-2 消除类游戏
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201512-2 消除类游戏 问题描述 消除类游戏是深受大众欢迎的一种游戏,游戏在一个包含有n行 ...