要点

  • 题意是:以颜色red举例,逆时针找最近的,顺时针找最近的,相减得到val;对三种颜色都做这事然后求和,卖掉最小的,更新,继续。
  • 360度很小所以就像365天一样可以暴力前后扫。每次更新最多6个所以就是模拟题了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std; const int maxn = 1e5 + 5;
int n;
struct Card {
int c[3], id;
}a[maxn];
struct node {
int val, id;
bool operator < (const node &rhs) const {
if (val != rhs.val) return val < rhs.val;
return id > rhs.id;
}
};
set<int> s[3][360];
set<node> S;
map<int, int> mp;
int V[maxn]; int getval(int i) {
int sum = 0;
for (int j = 0; j < 3; j++) {
int cur = a[i].c[j];
if (s[j][cur].size() >= 2) continue;
int l = cur;
do {
l = (l - 1 + 360) % 360;
} while (s[j][l].size() == 0);
int r = cur;
do {
r = (r + 1) % 360;
} while (s[j][r].size() == 0);
if (l > cur) l -= 360;
if (r < cur) r += 360;
sum += r - l;
}
return sum;
} void deal(int j, int pos) {
if (s[j][pos].size() >= 2) return;
int id = *s[j][pos].begin();
int val = getval(mp[id]);
S.erase({V[mp[id]], id});
S.insert({V[mp[id]] = val, id});
} int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
scanf("%d", &a[i].c[j]);
}
scanf("%d", &a[i].id);
int id = a[i].id;
mp[id] = i;
for (int j = 0; j < 3; j++) {
s[j][a[i].c[j]].insert(id);
}
}
for (int i = 0; i < n; i++) {
V[i] = getval(i);
S.insert({V[i], a[i].id});
}
while (n--) {
int id = S.begin()->id;
printf("%d\n", id);
S.erase(S.begin());
int t = mp[id];
for (int j = 0; j < 3; j++) {
int k = a[t].c[j];
if (s[j][k].size() >= 2) {
s[j][k].erase(s[j][k].find(id));
int iid = *s[j][k].begin(), vval = getval(mp[iid]);
S.erase({V[mp[iid]], iid});
S.insert({V[mp[iid]] = vval, iid});
} else if (n >= 1) {
s[j][k].erase(s[j][k].begin());
int l = k;
do {
l = (l - 1 + 360) % 360;
} while (s[j][l].size() == 0);
deal(j, l);
int r = k;
do {
r = (r + 1) % 360;
} while (s[j][r].size() == 0);
deal(j, r);
}
}
}
}

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. 勤于思考: ASP.NET MVC 注销后 使用浏览器 【后退】 不使用缓存页面

    经过自己和朋友一起探讨,总结出三种方法实现. 方法一: <script type="text/javascript"> $(function () { window.h ...

  2. hdu-5858 Hard problem(数学)

    题目链接: Hard problem Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Othe ...

  3. numpy中的tile函数

    tile()函数可以很方便的生成多维数组.它有两个参数,第一个数是原始数组;第二个表示如何来生成,第一个数字表示生成几行,第二个表示每行有多少个原始数组(如果只写一个数字,那么就默认是一行). fro ...

  4. struct tm 和 time_t 时间和日期的使用方法(转

    关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch(时间点),clock tick(时钟计时单元) .概念 在C/C++中,对字符串的操作有很多值得注意的问题,同样,C ...

  5. lwip【5】 lwIP配置文件opt.h和lwipopts.h初步分析之二

    如何去配置lwip,使它去适合不同大小的脚,这就是本贴的主题lwIP的配置问题.尤其是内存的配置,配置多了浪费,配置少了跑不了或者不稳定(会出现的一大堆莫名奇妙的问题,什么打开网页的速度很慢啊?什么丢 ...

  6. asp.net mvc Model验证总结及常用正则表达式【转载】

    关于Model验证官方资料: http://msdn.microsoft.com/zh-cn/library/system.componentmodel.dataannotations.aspx AS ...

  7. POJ-3280

    Cheapest Palindrome Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10301   Accepted: 4 ...

  8. bootstrap的popover()的使用

    有一些选项是通过 Bootstrap 数据 API(Bootstrap Data API)添加或通过 JavaScript 调用的.下表列出了这些选项: 选项名称 类型/默认值 Data 属性名称 描 ...

  9. POJ 1064 Cable master (二分)

    题意:给定 n 条绳子,它们的长度分别为 ai,现在要从这些绳子中切出 m 条长度相同的绳子,求最长是多少. 析:其中就是一个二分的水题,但是有一个坑,那么就是最后输出不能四舍五入,只能向下取整. 代 ...

  10. [poj]1050 To the Max dp

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...