【Codeforces Round #351 Div. 2】 673B Problems for Round

原创 2016年08月28日 21:34:37

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.


【题目分析】
把一列数划分成两个集合,只能从中间分开,要求左面的比右面的要小,显然,可以维护一个左面最大值和右面最小值,看看是否冲突就好了。


【代码】

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream> 
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int lmax=1,rmin=n;
    for (int i=1;i<=m;++i){
        int u,v;
        scanf("%d%d",&u,&v);
        lmax=max(min(u,v),lmax);
        rmin=min(max(u,v),rmin);
    }
    if (lmax>=rmin) {
        printf("0\n"); return 0;
    }
    else {
        printf("%d\n",rmin-lmax); return 0;
    }
}
版权声明:标注来源之后可随意引用[请记得添加友链]

相关文章推荐

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B.Problems for Round

B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces 673B Problems for Round【思维】

B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes i...

Codeforces Round #351(Div 2)

熬到半夜打结果前一个小时提交代码的页面根本加载不进去,D题写完还因为小点没判被hack掉了。。。 rating什么的都是身外之物了,于是乎喜闻乐见地又掉回绿名了。A题:*题目描述: Bear看一场...

Codeforces Round #128 (Div. 2) A. Two Problems

A. Two Problems 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. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths

D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes ...

【解题报告】Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

简略的解题报告。
  • TRiddle
  • TRiddle
  • 2016年11月08日 11:58
  • 185

Codeforces Round #222 (Div. 1) B - Preparing for the Contest

先二分,输入排序,然后对于确定的天数,贪心判断是否可行。 #include #include #include #include #include #include #include ...

Codeforces Round #261 (Div. 2)B. Pashmak and Flowers(容易)

Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the gard...

Codeforces Round #141 (Div. 2) B. Two Tables 枚举

You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zero...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:【Codeforces Round #351 Div. 2】 673B Problems for Round
举报原因:
原因补充:

(最多只允许输入30个字)