Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
2016-05-08 08:42
417 查看
B. Problems for Round
题目连接:
http://www.codeforces.com/contest/673/problem/BDescription
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 21 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; }
相关文章推荐
- Android Studio中获取sha1证书指纹数据的方法
- **Regular Expression Match
- spine之五——在程序中使用动画
- Spine之四——用 Spine 架设骨骼,创建动画
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
- 写给奋斗的自己
- Spine之三——实用技巧大全
- 第14课:Spark RDD解密
- D - Palindrome Partitioning (DP)
- Spine之二——认识界面
- smali语法
- sublime text的部分常用配置
- javadoc生成出现错误“编码 GBK 的不可映射字符
- 百度地图-异步加载地图
- bzoj 1299: [LLH邀请赛]巧克力棒(nim游戏的应用)
- RHEL6.2下挂载光驱安装软件
- leetcode--003. Longest Substring Without Repeating Characters
- 在Ubuntu系统中安装Visual Studio Code
- Spark Streaming揭秘 Day5 初步贯通源码
- spine之一——术语和概念