[Codeforces673B]Problems for Round(思路,规律)
题目链接:http://codeforces.com/contest/673/problem/B
现在有n个题和m个相似的关系,现在要把他们分到2组去。
要求:
1组的所有题比2组难
每个组都得至少有一个题
两个问题相似的话,不能用在同一组
每个题只能用一次
特别注意的是,相似的关系是没有传递性的,也就是AB相似,BC相似,那AC不相似。
思路:由于每次输入的两个题一定不是一个div的,那我们规定每次都把小的放到2,大的放到1。并且维护2里的最大值和1里的最小值。仔细考虑一下就会发现正确的情况下不会出现2中的最大值大于1中的最小值的。而且用1中的最小值减去2中的最大值就是剩下了几个和其他几个都没关系的。假如l=5,r=8,那剩下了的就是6 7两个题。这两个题可以同时放到2也可以同时放到1,也可以6放到2、7放到1。所以他们的分配数为r-l=3。
注意如果r-l<0的话,那说明出现了交集,这些题是没法正常分配的。
/*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rlf(a) scanf("%llf", &a);
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
int n, m; int main() {
// FRead();
int u, v;
Rint(n); Rint(m);
int l = , r = n;
Rep(i, m) {
Rint(u); Rint(v);
if(u > v) swap(u, v);
l = max(u, l); r = min(v, r);
}
if(r - l < ) printf("0\n");
else printf("%d\n", r-l);
RT ;
}
[Codeforces673B]Problems for Round(思路,规律)的更多相关文章
- codeforces 673B B. Problems for Round(模拟)
题目链接: B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 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 ...
- 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 ...
- Leetcode11 Container With Most Water 解题思路 (Python)
今天开始第一天记录刷题,本人编程小白,如果有写的不对.或者能更完善的地方请个位批评指正! 准备按tag刷,第一个tag是array: 这个是array的第一道题:11. Container With ...
- 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 ...
- C#刷遍Leetcode面试题系列连载(4) No.633 - 平方数之和
上篇文章中一道数学问题 - 自除数,今天我们接着分析 LeetCode 中的另一道数学题吧~ 今天要给大家分析的面试题是 LeetCode 上第 633 号问题, Leetcode 633 - 平方数 ...
- 6专题总结-动态规划dynamic programming
专题6--动态规划 1.动态规划基础知识 什么情况下可能是动态规划?满足下面三个条件之一:1. Maximum/Minimum -- 最大最小,最长,最短:写程序一般有max/min.2. Yes/N ...
- [leetcode] Min Stack @ Python
原题地址:https://oj.leetcode.com/problems/min-stack/ 解题思路:开辟两个栈,一个栈是普通的栈,一个栈用来维护最小值的队列. 代码: class MinSta ...
- [leetcode]Find Minimum in Rotated Sorted Array II @ Python
原题地址:https://oj.leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 解题思路:这道题和上一道题的区别是,数组中 ...
随机推荐
- Setting composer minimum stability for your application
Do you have a confusion of how do you determine the stability when using composer dependency manager ...
- 在Web API中使用Swagger-UI开源组件(一个深坑的解决)
介绍: Swagger-Ui是一个非常棒的Web API说明帮助页,具体详情可自行Google和百度. 官网:http://swagger.io/ GitHub地址:https://github ...
- iOS 进阶 第五天(0330)
0330 cell的一些常见属性 设置cell右边指示器的类型 设置cell右边指示器的view cell的backgroundView和selectedBackgroundView cell的bac ...
- 10.31Daily Scrum
人员 任务分配完成情况 明天任务分配 王皓南 主网页的框架搭建,任务编号752 研究代码,学习相应语言,讨论设计思路 申开亮 学习数据库的操作,任务编号753 研究代码,学习相应语言,讨论设计思路 王 ...
- IIS搭建本地服务器,花生壳实现外网通过域名访问网站
配置服务器 作为一个青年,没有实力,做不出标图所示的服务器. 作为一个学生,买不起服务器 作为一个小孩,买不起域名 但别忘了 作为一个平民玩家,只要有耐心 装备迟早会做出来的 (注:感觉有钱与没钱还是 ...
- c# 应用程序部署发布
转自:http://blog.csdn.net/chenyujing1234/article/details/7558185 最近做了C#软件,发布给客户用时,发现客户运行不起来,原因是客户电脑上没有 ...
- vi之跳到指定行
vi里怎样跳转到某一指定行 输入 :行号 :$跳到最后一行 gg跳到第一行.
- 【BZOJ】【3757】苹果树
树分块 orz HZWER http://hzwer.com/5259.html 不知为何我原本写的倍增求LCA给WA了……学习了HZWER的倍增新姿势- 树上分块的转移看vfk博客的讲解吧……(其实 ...
- Unity3D脚本中文系列教程(十一)
http://dong2008hong.blog.163.com/blog/static/4696882720140313058768/ BoxCollider 类,继承自Collider 一个盒状的 ...
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...