zoukankan      html  css  js  c++  java
  • Codeforces Round #541 (Div. 2) B.Draw!

    链接:https://codeforces.com/contest/1131/problem/B

    题意:

    给n次足球比分,求存在平局的机会。

    思路:

    结构体存储,unique后,判断是否有分数交叉。

    一方当前分数小的时候,下一次分数小于当前对方时不存在平局,

    下一次分数介于对方当前分数和下次分数之间时根据下次分数和当前对方分数。

    否则表示对方分数被完全包含,反之同理。

    代码:

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    
    const int MAXN = 1e4 + 10;
    struct Node
    {
        int _l, _r;
        bool operator == (const Node & that){
            return this->_l == that._l && this->_r == that._r;
        }
    }node[MAXN];
    
    int main()
    {
        int n;
        cin >> n;
        node[1]._l = 0;
        node[1]._r = 0;
        for (int i = 2;i <= n + 1;i++)
            cin >> node[i]._l >> node[i]._r;
        int res = 1;
        int x = unique(node + 1,node + n + 2) - (node + 1);
        for (int i = 1;i < x;i++)
        {
            if (node[i]._l == node[i]._r)
                res += min(node[i + 1]._l, node[i + 1]._r) - node[i]._l;
            else if (node[i]._l < node[i]._r)
            {
                if (node[i + 1]._l < node[i]._r)
                    continue;
                if (node[i + 1]._l <= node[i + 1]._r)
                    res += node[i + 1]._l - node[i]._r + 1;
                else
                    res += node[i + 1]._r - node[i]._r + 1;
            }
            else if (node[i]._l > node[i]._r)
            {
                if (node[i + 1]._r < node[i]._l)
                    continue;
                if (node[i + 1]._r <= node[i + 1]._l)
                    res += node[i + 1]._r - node[i]._l + 1;
                else
                    res += node[i + 1]._l - node[i]._l + 1;
            }
        }
        cout << res << endl;
    
        return 0;
    }
    /*
    3
    1 1
    2 2
    3 3
     */
    

      

  • 相关阅读:
    NOIP2009 pj
    数星星(POJ2352 star)
    洛谷 p3372 模板-线段树 1
    Luogu P1198 [JSOI2008]最大数 线段树
    Bestcoder#92&HDU 6017 T3 Girl loves 233 DP
    NOIP2008pj & luoguP1058 立体图 模拟
    NOIP2003TG 加分二叉树 区间DP
    Redis Jedis lua脚本
    Mac Ideal 常用快捷键
    Mysql慢查询explain
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10425068.html
Copyright © 2011-2022 走看看