zoukankan      html  css  js  c++  java
  • [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的话,那说明出现了交集,这些题是没法正常分配的。

     1 /*
     2 ━━━━━┒ギリギリ♂ eye!
     3 ┓┏┓┏┓┃キリキリ♂ mind!
     4 ┛┗┛┗┛┃\○/
     5 ┓┏┓┏┓┃ /
     6 ┛┗┛┗┛┃ノ)
     7 ┓┏┓┏┓┃
     8 ┛┗┛┗┛┃
     9 ┓┏┓┏┓┃
    10 ┛┗┛┗┛┃
    11 ┓┏┓┏┓┃
    12 ┛┗┛┗┛┃
    13 ┓┏┓┏┓┃
    14 ┃┃┃┃┃┃
    15 ┻┻┻┻┻┻
    16 */
    17 #include <algorithm>
    18 #include <iostream>
    19 #include <iomanip>
    20 #include <cstring>
    21 #include <climits>
    22 #include <complex>
    23 #include <fstream>
    24 #include <cassert>
    25 #include <cstdio>
    26 #include <bitset>
    27 #include <vector>
    28 #include <deque>
    29 #include <queue>
    30 #include <stack>
    31 #include <ctime>
    32 #include <set>
    33 #include <map>
    34 #include <cmath>
    35 using namespace std;
    36 #define fr first
    37 #define sc second
    38 #define cl clear
    39 #define BUG puts("here!!!")
    40 #define W(a) while(a--)
    41 #define pb(a) push_back(a)
    42 #define Rlf(a) scanf("%llf", &a);
    43 #define Rint(a) scanf("%d", &a)
    44 #define Rll(a) scanf("%I64d", &a)
    45 #define Rs(a) scanf("%s", a)
    46 #define Cin(a) cin >> a
    47 #define FRead() freopen("in", "r", stdin)
    48 #define FWrite() freopen("out", "w", stdout)
    49 #define Rep(i, len) for(int i = 0; i < (len); i++)
    50 #define For(i, a, len) for(int i = (a); i < (len); i++)
    51 #define Cls(a) memset((a), 0, sizeof(a))
    52 #define Clr(a, x) memset((a), (x), sizeof(a))
    53 #define Full(a) memset((a), 0x7f7f, sizeof(a))
    54 #define lrt rt << 1
    55 #define rrt rt << 1 | 1
    56 #define pi 3.14159265359
    57 #define RT return
    58 #define lowbit(x) x & (-x)
    59 #define onenum(x) __builtin_popcount(x)
    60 typedef long long LL;
    61 typedef long double LD;
    62 typedef unsigned long long ULL;
    63 typedef pair<int, int> pii;
    64 typedef pair<string, int> psi;
    65 typedef map<string, int> msi;
    66 typedef vector<int> vi;
    67 typedef vector<LL> vl;
    68 typedef vector<vl> vvl;
    69 typedef vector<bool> vb;
    70 
    71 const int maxn = 100100;
    72 int n, m;
    73 
    74 int main() {
    75     // FRead();
    76     int u, v;
    77     Rint(n); Rint(m);
    78     int l = 1, r = n;
    79     Rep(i, m) {
    80         Rint(u); Rint(v);
    81         if(u > v) swap(u, v);
    82         l = max(u, l); r = min(v, r);
    83     }
    84     if(r - l < 0) printf("0
    ");
    85     else printf("%d
    ", r-l);
    86     RT 0;
    87 }
  • 相关阅读:
    Ubuntu配置sublime text 3的c编译环境
    ORA-01078错误举例:SID的大写和小写错误
    linux下多进程的文件拷贝与进程相关的一些基础知识
    ASM(四) 利用Method 组件动态注入方法逻辑
    基于Redis的三种分布式爬虫策略
    Go语言并发编程总结
    POJ2406 Power Strings 【KMP】
    nyoj 会场安排问题
    Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.
    Java的String、StringBuffer和StringBuilder的区别
  • 原文地址:https://www.cnblogs.com/kirai/p/5549199.html
Copyright © 2011-2022 走看看