CodeForces 673B Problems for Round(比赛出题规则)
2016-08-12 21:10
393 查看
http://codeforces.com/problemset/problem/673/B
B. Problems for Round
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
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.
Examples
input
output
input
output
input
output
Note
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.
题意:
Codeforces出题有 Div1 和 Div2 等级,D1中最简单的题目也要比 D2中的难(雨神说我现在的水平做不出来Div1的题)。
给定一些相似的题目,问可以出多少套题目,
数字代表难度(越大越难)。
思路:
模拟试一下,参考官方的题解。
Code:
B. Problems for Round
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
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.
Examples
input
5 2 1 4 5 2
output
2
input
3 3
1 22 3
1 3
output
0
input
3 23 13 2
output
1
Note
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.
题意:
Codeforces出题有 Div1 和 Div2 等级,D1中最简单的题目也要比 D2中的难(雨神说我现在的水平做不出来Div1的题)。
给定一些相似的题目,问可以出多少套题目,
数字代表难度(越大越难)。
思路:
模拟试一下,参考官方的题解。
Code:
#include<cstdio> #include<cstring> const int MYDD=1103; int MAX(int x,int y) { return x>y? x:y; } int MIN(int x,int y) { return x<y? x:y; } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int div1=n,div2=1;//div1题目等级高 int max,min; while(m--) { int a,b; scanf("%d%d",&a,&b);//类似的题目 min=MIN(a,b); max=MAX(a,b); div1=MIN(div1,max);//div1题目中最简单的题目 div2=MAX(div2,min);//div2题目中最难的题目 } if(div1-div2<0) {//难题中最简单的题目没有容易题中最难的难 puts("0"); } else { printf("%d\n",div1-div2); } } return 0; } /*By: Shyazhut*/
相关文章推荐
- 关于codeforces比赛规则介绍(转载)
- 【关于codeforces比赛规则介绍】(转载)
- CodeForces官方比赛规则介绍
- 关于codeforces比赛规则介绍(转载)
- CodeForces比赛规则
- 关于codeforces比赛规则介绍(转载)
- CSU-ACM2017暑假集训比赛2 CodeForces - 724D
- CSU-ACM2017暑假集训比赛8 - B - The Two Routes - CodeForces - 601A
- CodeForces 478B 第六周比赛B题
- AStar2006 --- 变态比赛规则问题
- php解:2006 年百度之星程序设计大赛初赛题目 3 ----变态的比赛规则
- CSU-ACM2017暑假集训比赛7 A - Equivalent Strings - CodeForces - 560D
- sql 类似歌手得分或跳水比赛的打分规则.
- 2011年分形艺术国际大赛比赛规则
- CodeForces 569A 第六周比赛C踢
- 足球比赛规则
- 第二届院级杯足球赛比赛规则
- "百度之星"程序设计大赛试题解答(Java实现)---变态的比赛规则(未完成!!!)
- 2006 年百度之星程序设计大赛初赛题目 3 变态的比赛规则
- [2018-4-8]BNUZ套题比赛div2 CodeForces 960A【补】