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 ...
随机推荐
- Python标准库笔记(9) — functools模块
functools 作用于函数的函数 functools 模块提供用于调整或扩展函数和其他可调用对象的工具,而无需完全重写它们. 装饰器 partial 类是 functools 模块提供的主要工具, ...
- Shell-输入密码转换为*
Code: read -p "请输入使用者都名称:" USER echo -e "请输入使用者密码: \c" while : ;do char=` #这里是反引 ...
- 使用postman做接口测试(三)
三,接口用例的设计 个人感觉用例的设计才是重要的哈,网上查了一些资料总结了一下 1.业务流程测试 通过性验证: 1, 按照接口文档上的参数,正常传参,是否可以返回正确的结果 2, 是否满足前提条件,比 ...
- maven profile 优先级
maven profile是有优先级别 也就是说在setting.xml的profile优先级比pom中同名的profile高. 可以使用 mvn help:active-profiles 这个命令是 ...
- error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory
一般我们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误, 比如: tmux: error while loading shared libraries: libevent-1.4.s ...
- 七、springcloud之配置中心Config(二)之高可用集群
方案一:传统作法(不推荐) 服务端负载均衡 将所有的Config Server都指向同一个Git仓库,这样所有的配置内容就通过统一的共享文件系统来维护,而客户端在指定Config Server位置时, ...
- SQLAlchemy-方言(Dialects)
一: Dialects 文档是分为三个部分: SQLAlchemy ORM, SQLAlchemy Core, and Dialects. SQLAlchemy ORM:在SQLAlchemy ORM ...
- dragstart drag dragend dragenter dragover dragleave drop
dragstart drag dragend dragenter dragover dragleave drop 前端框架层出不穷,网页上的效果越来越绚丽,制作绚丽的效果的成本越来越低,其中有种拖 ...
- Oracle 中count(1) 、count(*) 和count(列名) 函数的区别
1)count(1)与count(*)比较: 1.如果你的数据表没有主键,那么count(1)比count(*)快2.如果有主键的话,那主键(联合主键)作为count的条件也比count(*)要快3. ...
- luoguP2735 电网 Electric Fences
一道校内模拟赛遇见的题 ** 不会正解就真的很麻烦的 数学题 ** 有一种东西叫 皮克定理 发现的千古神犇: 姓名:George Alexander Pick(所以叫皮克定理呀 国籍:奥地利(蛤!竟然 ...