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 ...
随机推荐
- aarch64_n2
nodejs-is-dotfile-1.0.2-2.fc26.noarch.rpm 2017-02-12 00:27 9.5K fedora Mirroring Project nodejs-is-e ...
- avalonJS-源码阅读(三) VMODEL
avalon的重头戏.终于要到我最期待的vmodel了. ps:这篇博文想做的全一点,错误少一点,所以会有后续的更新在这篇文章中. 状态:一稿 目录[-] avalon dom小结 数据结构 观察者模 ...
- TCP/IP详解(整理)
1.概述 路由器是在网络层进行联通,而网桥是在链路层联通不同的网络. IP层用ICMP来与其他主机或路由器交换错误报文和其他的重要信息.应用程序也可以访问ICMP,两个诊断工具:Ping和Tracer ...
- 12 Release History for go go语言的版本历史
Release History Release Policy go1.11 (released 2018/08/24) go1.10 (released 2018/02/16) Minor revis ...
- 华夏部分互联网科技公司创始及IPO信息
时间:2018-04-19 前面整理了一些美国科技公司的信息,这篇文章整理的是我华夏的一些科技公司的信息. 华为.百度.阿里.腾讯.美团.携程.京东.小米.奇虎360……之后,其它一些公司,要么体量 ...
- MyEclipse自带且常用的快捷键和自己定义的快捷键方法步骤
1.MyEclipse自带且常用的快捷键 内容提示(补全): Alt+/ 导包快捷键: Ctrl+Shift+o 格式化代码: Ctrl+Shift+f 行代码位置上下调换: Alt ...
- linux 101 hacks 第一章cd命令
本系列来源于<linux 101 hacks>,作者还写了其他101 hacks教程,读了几章,觉得技巧都还不错,很实用,做个总结收藏. cdpath 设置基目录 [ramesh@dev- ...
- 【LOJ】#2072. 「JSOI2016」独特的树叶
题解 干脆题解套题解好了 毕竟我的hash方法是抄小迪的 https://www.cnblogs.com/RabbitHu/p/9165770.html 小迪太巨了%%% 之前模数是八位的WA了几个点 ...
- JSP的学习二(指令与标签)
一:page指令 1.JSP的指令 放在<%@ 指令 属性=“值”%> 主要有page,include,tablib. 2.page指令 用于定义JSP页面的各种属性,作用于是JSP的整个 ...
- hdoj2546 饭卡(DP,01背包)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路 首先要判断卡里的钱是不是大于等于5元,如果不足5元,直接输出余额:如果大于等于5元,则先留 ...