Codeforces Round #541 (Div. 2) B.Draw!

今天药忘吃喽~ 2021-12-23 11:29 343阅读 0赞

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

题意:

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

思路:

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

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

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

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

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MAXN = 1e4 + 10;
  5. struct Node
  6. {
  7. int _l, _r;
  8. bool operator == (const Node & that){
  9. return this->_l == that._l && this->_r == that._r;
  10. }
  11. }node[MAXN];
  12. int main()
  13. {
  14. int n;
  15. cin >> n;
  16. node[1]._l = 0;
  17. node[1]._r = 0;
  18. for (int i = 2;i <= n + 1;i++)
  19. cin >> node[i]._l >> node[i]._r;
  20. int res = 1;
  21. int x = unique(node + 1,node + n + 2) - (node + 1);
  22. for (int i = 1;i < x;i++)
  23. {
  24. if (node[i]._l == node[i]._r)
  25. res += min(node[i + 1]._l, node[i + 1]._r) - node[i]._l;
  26. else if (node[i]._l < node[i]._r)
  27. {
  28. if (node[i + 1]._l < node[i]._r)
  29. continue;
  30. if (node[i + 1]._l <= node[i + 1]._r)
  31. res += node[i + 1]._l - node[i]._r + 1;
  32. else
  33. res += node[i + 1]._r - node[i]._r + 1;
  34. }
  35. else if (node[i]._l > node[i]._r)
  36. {
  37. if (node[i + 1]._r < node[i]._l)
  38. continue;
  39. if (node[i + 1]._r <= node[i + 1]._l)
  40. res += node[i + 1]._r - node[i]._l + 1;
  41. else
  42. res += node[i + 1]._l - node[i]._l + 1;
  43. }
  44. }
  45. cout << res << endl;
  46. return 0;
  47. }
  48. /*
  49. 3
  50. 1 1
  51. 2 2
  52. 3 3
  53. */

  

转载于:https://www.cnblogs.com/YDDDD/p/10425068.html

发表评论

表情:
评论列表 (有 0 条评论,343人围观)

还没有评论,来说两句吧...

相关阅读

    相关 codeforces-round375-div2

    题目链接:[codeforces round 375 div2][] A题: 读一遍题目就知道是超级水的题目,,就是给你三个坐标,求三个坐标汇集到一个点所走的路程