要点

  • 题意是:以颜色red举例,逆时针找最近的,顺时针找最近的,相减得到val;对三种颜色都做这事然后求和,卖掉最小的,更新,继续。
  • 360度很小所以就像365天一样可以暴力前后扫。每次更新最多6个所以就是模拟题了。
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <map>
  6. #include <set>
  7. using namespace std;
  8. const int maxn = 1e5 + 5;
  9. int n;
  10. struct Card {
  11. int c[3], id;
  12. }a[maxn];
  13. struct node {
  14. int val, id;
  15. bool operator < (const node &rhs) const {
  16. if (val != rhs.val) return val < rhs.val;
  17. return id > rhs.id;
  18. }
  19. };
  20. set<int> s[3][360];
  21. set<node> S;
  22. map<int, int> mp;
  23. int V[maxn];
  24. int getval(int i) {
  25. int sum = 0;
  26. for (int j = 0; j < 3; j++) {
  27. int cur = a[i].c[j];
  28. if (s[j][cur].size() >= 2) continue;
  29. int l = cur;
  30. do {
  31. l = (l - 1 + 360) % 360;
  32. } while (s[j][l].size() == 0);
  33. int r = cur;
  34. do {
  35. r = (r + 1) % 360;
  36. } while (s[j][r].size() == 0);
  37. if (l > cur) l -= 360;
  38. if (r < cur) r += 360;
  39. sum += r - l;
  40. }
  41. return sum;
  42. }
  43. void deal(int j, int pos) {
  44. if (s[j][pos].size() >= 2) return;
  45. int id = *s[j][pos].begin();
  46. int val = getval(mp[id]);
  47. S.erase({V[mp[id]], id});
  48. S.insert({V[mp[id]] = val, id});
  49. }
  50. int main() {
  51. scanf("%d", &n);
  52. for (int i = 0; i < n; i++) {
  53. for (int j = 0; j < 3; j++) {
  54. scanf("%d", &a[i].c[j]);
  55. }
  56. scanf("%d", &a[i].id);
  57. int id = a[i].id;
  58. mp[id] = i;
  59. for (int j = 0; j < 3; j++) {
  60. s[j][a[i].c[j]].insert(id);
  61. }
  62. }
  63. for (int i = 0; i < n; i++) {
  64. V[i] = getval(i);
  65. S.insert({V[i], a[i].id});
  66. }
  67. while (n--) {
  68. int id = S.begin()->id;
  69. printf("%d\n", id);
  70. S.erase(S.begin());
  71. int t = mp[id];
  72. for (int j = 0; j < 3; j++) {
  73. int k = a[t].c[j];
  74. if (s[j][k].size() >= 2) {
  75. s[j][k].erase(s[j][k].find(id));
  76. int iid = *s[j][k].begin(), vval = getval(mp[iid]);
  77. S.erase({V[mp[iid]], iid});
  78. S.insert({V[mp[iid]] = vval, iid});
  79. } else if (n >= 1) {
  80. s[j][k].erase(s[j][k].begin());
  81. int l = k;
  82. do {
  83. l = (l - 1 + 360) % 360;
  84. } while (s[j][l].size() == 0);
  85. deal(j, l);
  86. int r = k;
  87. do {
  88. r = (r + 1) % 360;
  89. } while (s[j][r].size() == 0);
  90. deal(j, r);
  91. }
  92. }
  93. }
  94. }

GYM 101572C(模拟)的更多相关文章

  1. C - Boss Gym - 101473C (模拟)

    题目链接:https://cn.vjudge.net/contest/287775#problem/C 题目大意:给你n个人,然后m条关系,会有k次询问,每一次询问包括两种类型,第一种类型是交换两个人 ...

  2. Galactic Collegiate Programming Contest Gym - 101572G 模拟

    #include<bits/stdc++.h> using namespace std; int n,m; struct node { int id; int slove; int pen ...

  3. 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...

  4. 【模拟】NEERC15 G Generators(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: n个序列.每个序列有4个值x,a,b,c,之后按照x=(a*x+b)%c扩展无穷项. 求每个序列各取一个数之后 ...

  5. 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...

  6. 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...

  7. 【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和.C c ...

  8. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  9. Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】

    C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...

随机推荐

  1. python操作cad

    from pyautocad import Autocad # 自動連接上cad,只要cad是開着的,就創建了一個<pyautocad.api.Autocad> 對象.這個對象連接最近打開 ...

  2. 局域网扫描IP

    今天有朋友去面试,被问到一个“如何扫描局域网IP”的问题(即找出局域网中当前已使用的IP),朋友回答的不好,回来问我,我首先想到的就是使用ping命令将局域网可分配的IP地址逐个遍历一遍,能ping通 ...

  3. AndyQsmart ACM学习历程——ZOJ3872 Beauty of Array(递推)

    Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...

  4. codevs 2144 砝码称重2

    传送门 2144 砝码称重 2  时间限制: 1 s  空间限制: 16000 KB  题目等级 : 钻石 Diamond 题解   题目描述 Description 有n个砝码,现在要称一个质量为m ...

  5. 基于bootsplash的嵌入式linux启动画面定制

    来源: ChinaUnix博客 作者: ChinaUnix博客 发布时间:2007-01-01 16:29:00 摘 要:在基于linux的嵌入式仿真平台研发中,利用开源工具bootsplash能够定 ...

  6. Poj_1088_滑雪(DP)

    一.Description(poj1088) Michael喜欢滑雪百这并不奇怪,  因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载 ...

  7. CentOS下编写shell脚本来监控MySQL主从复制的教程

    这篇文章主要介绍了在CentOS系统下编写shell脚本来监控主从复制的教程,文中举了两个发现故障后再次执行复制命令的例子,需要的朋友可以参考下 目的:定时监控MySQL主从数据库是否同步,如果不同步 ...

  8. [poj2955/nyoj15]括号匹配(区间dp)

    解题关键:了解转移方程即可. 转移方程:$dp[l][r] = dp[l + 1][r - 1] + 2$ 若该区间左右端点成功匹配.然后对区间内的子区间取max即可. nyoj15:求需要添加的最少 ...

  9. FZU 2059 MM (并查集+排序插入)

    Problem 2059 MM Accept: 109    Submit: 484Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem ...

  10. Mathematics Base - Tensor

    以下是我对张量的理解,备注是具体解释,Xmind导出的图片没法显示出来,主要还是将张量间的关系画出来,方便理解. 图1 张量