题目链接: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(思路,规律)的更多相关文章

  1. codeforces 673B B. Problems for Round(模拟)

    题目链接: B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. 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 ...

  3. 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 ...

  4. Leetcode11 Container With Most Water 解题思路 (Python)

    今天开始第一天记录刷题,本人编程小白,如果有写的不对.或者能更完善的地方请个位批评指正! 准备按tag刷,第一个tag是array: 这个是array的第一道题:11. Container With ...

  5. 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 ...

  6. C#刷遍Leetcode面试题系列连载(4) No.633 - 平方数之和

    上篇文章中一道数学问题 - 自除数,今天我们接着分析 LeetCode 中的另一道数学题吧~ 今天要给大家分析的面试题是 LeetCode 上第 633 号问题, Leetcode 633 - 平方数 ...

  7. 6专题总结-动态规划dynamic programming

    专题6--动态规划 1.动态规划基础知识 什么情况下可能是动态规划?满足下面三个条件之一:1. Maximum/Minimum -- 最大最小,最长,最短:写程序一般有max/min.2. Yes/N ...

  8. [leetcode] Min Stack @ Python

    原题地址:https://oj.leetcode.com/problems/min-stack/ 解题思路:开辟两个栈,一个栈是普通的栈,一个栈用来维护最小值的队列. 代码: class MinSta ...

  9. [leetcode]Find Minimum in Rotated Sorted Array II @ Python

    原题地址:https://oj.leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 解题思路:这道题和上一道题的区别是,数组中 ...

随机推荐

  1. Financial Management

    Financial Management 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 Larry graduated this year and finally ...

  2. VBS基础篇 - 变量

    VBScript只有一种数据类型 —— Variant,它是根据上下文来判断是数字还是字符串.因为Variant是VBScript中唯一的数据类型,所以它也是VBScript中所有函数的返回值的数据类 ...

  3. SSH与EJB 比较

    SSH完全的开源产品,如果用SSH就必然会用到大量的开源的东东,从数据库到逻辑到控制到前端,开源产品大拼装, 其中SSH中的三大核心,Struts相当于JSF,spring相当于EJB,hiberna ...

  4. android 中设置HttpURLConnection 超时并判断是否超时

    设置超时: URL url1 = new URL(url); HttpURLConnection conn = (HttpURLConnection) url1.openConnection(); c ...

  5. 搭建Asp.Net MVC4

    启动vs2012,开始创建一个新的web应用程序.使用菜单:“文件”>“新建项目” 请在左侧选择 Visual C#,然后选择ASP.NET MVC 4 Web 应用程序.命名您的工程为&quo ...

  6. C# 客户端判断服务器连接已断开

    问题描述:        在C# Socket编程中,服务器端已经断开连接(发送数据方),客户端接收服务器端发送数据,在客户端使用client.Recieve()中,服务器端断开连接,客户端任然显示已 ...

  7. 解决Ubuntu开机自动挂载硬盘回收站不可用等权限问题

    1.修改fstab sudo gedit /etc/fstab 2.添加如下代码 #Entry for /dev/sdb7 : UUID=78A675EB46D703C4 /media/anseey/ ...

  8. Eclipse下PHP开发 插件安装

    PHPeclipse是什么? PHPeclipse是Eclipse的一个插件,它为php开发人员提供了一个集成的开发环境.Eclipse官方下载地址:http://www.eclipse.org/ P ...

  9. hdu 1275 两车追及或相遇问题

    思路:这里有2种情况: 一种是相遇:满足关系是 (va+vb)*t=L*(2*n-1) 一种是追及: 满足关系是 |va-vb|*t=L*(2*n-1) 这样求出2种情况的时间,在排序就可以了…… 链 ...

  10. java String 空指针异常

    如下代码中,第8行和第10行均会提示Exception in thread "main" java.lang.NullPointerException. 第12行的写法可行. im ...