Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B.Problems for Round
来源:互联网 发布:mysql5.7 for mac下载 编辑:程序博客网 时间:2024/04/28 12:20
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 21 45 2
2
3 31 22 31 3
0
3 23 13 2
1
思路:给相似两边排序,找出难度小那边的最大难度和难度大那边的最小难度,中间的就是可移动的题目,最小难度都大于最大难度,则不可分割。
#include <stdio.h>#include <algorithm>#include <math.h>#include <iostream>using namespace std;#define maxn 100005int a[maxn];int b[maxn];int ans=0;int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { ans=0; if(m==0) { printf("%d\n",n-1); continue; } for(int i=0;i<m;i++) { scanf("%d%d",&a[i],&b[i]); if(a[i]>b[i]) swap(a[i],b[i]); } sort(a,a+m); sort(b,b+m); if(a[m-1]>=b[0]) { printf("0\n"); continue; } ans=b[0]-a[m-1]; printf("%d\n",ans); } return 0;}
- 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. Problems for Round
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A B C D 构造
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) easy(上)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) ABCD
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- 【解题报告】Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟
- Codeforces VK Cup 2016 - Round 1 (Div. 2 Edition)
- VK Cup 2016 - Round 1 (Div. 2 Edition) B
- VK Cup 2016 - Round 1 (Div. 2 Edition) A B
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 1 Edition)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-B. Little Artem and Grasshopper(模拟)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
- ConcurrentHashMap原理
- 【Unity Shaders】学习笔记之固定着色器命令(二)
- Path Sum
- HMM原理介绍 示例 python代码实现
- Socket原理与编程基础
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B.Problems for Round
- 细谈java中的堆和栈
- hibernate一级缓存和二级缓存的区别
- 转载 css放大效果实现
- Qt之自定义布局管理器(QFlowLayout)
- webservice 客户端 调用服务端 进行测试
- Activity过滤器
- POJ 2406 Power Strings
- Java-三大框架