GYM 101572C(模拟)
要点
- 题意是:以颜色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(模拟)的更多相关文章
- C - Boss Gym - 101473C (模拟)
题目链接:https://cn.vjudge.net/contest/287775#problem/C 题目大意:给你n个人,然后m条关系,会有k次询问,每一次询问包括两种类型,第一种类型是交换两个人 ...
- Galactic Collegiate Programming Contest Gym - 101572G 模拟
#include<bits/stdc++.h> using namespace std; int n,m; struct node { int id; int slove; int pen ...
- 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...
- 【模拟】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扩展无穷项. 求每个序列各取一个数之后 ...
- 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...
- 【模拟】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 ...
- 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 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 ...
随机推荐
- sublime 3好用快捷键
sublime 3好用快捷键 自己常用 删除行 [ { "keys": ["ctrl+shift+d"], "command": " ...
- sass与compass实战(读书笔记)
// compass create myproject // compass compile // compass compile --force 重新编译未改动的 // compass compil ...
- liunx命令之:命令链接ftp服务器
1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密码 ...
- python爬虫知识点详解
python爬虫知识点总结(一)库的安装 python爬虫知识点总结(二)爬虫的基本原理 python爬虫知识点总结(三)urllib库详解 python爬虫知识点总结(四)Requests库的基本使 ...
- object类型转换为Array类型
var obj = {a: 1, b: 2, c: 3}; // .... var arr = []; for(var key in obj){ if(!obj.hasOwnProperty(key) ...
- B - Simple Game
B - Simple Game Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
- textarea的style="resize:none;"
<textarea class="form-control" id="gryj" rows="3" maxlength="3 ...
- 附近wifi都是你的
今天给大家介绍deauth攻击. 最终效果:附近你指定的任何wifi,别人都无法连接,即便连接上的也会断掉. 由于我在 “世界虽大,但没有破不了的wifi” 这篇文章中写的很详细,所以我在这里就步详 ...
- sqlserver2012——XML查询
1. CREATE TABLE STUDENT { S_ID INT, S_DATA xml } INSERT INTO STUDENT VALUES { 1, '<学生信息><姓名 ...
- Python之将Python字符串生成PDF
笔者在今天的工作中,遇到了一个需求,那就是如何将Python字符串生成PDF.比如,需要把Python字符串'这是测试文件'生成为PDF, 该PDF中含有文字'这是测试文件'. 经过一番检索, ...