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 ...
随机推荐
- python操作cad
from pyautocad import Autocad # 自動連接上cad,只要cad是開着的,就創建了一個<pyautocad.api.Autocad> 對象.這個對象連接最近打開 ...
- 局域网扫描IP
今天有朋友去面试,被问到一个“如何扫描局域网IP”的问题(即找出局域网中当前已使用的IP),朋友回答的不好,回来问我,我首先想到的就是使用ping命令将局域网可分配的IP地址逐个遍历一遍,能ping通 ...
- 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 ...
- codevs 2144 砝码称重2
传送门 2144 砝码称重 2 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 有n个砝码,现在要称一个质量为m ...
- 基于bootsplash的嵌入式linux启动画面定制
来源: ChinaUnix博客 作者: ChinaUnix博客 发布时间:2007-01-01 16:29:00 摘 要:在基于linux的嵌入式仿真平台研发中,利用开源工具bootsplash能够定 ...
- Poj_1088_滑雪(DP)
一.Description(poj1088) Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载 ...
- CentOS下编写shell脚本来监控MySQL主从复制的教程
这篇文章主要介绍了在CentOS系统下编写shell脚本来监控主从复制的教程,文中举了两个发现故障后再次执行复制命令的例子,需要的朋友可以参考下 目的:定时监控MySQL主从数据库是否同步,如果不同步 ...
- [poj2955/nyoj15]括号匹配(区间dp)
解题关键:了解转移方程即可. 转移方程:$dp[l][r] = dp[l + 1][r - 1] + 2$ 若该区间左右端点成功匹配.然后对区间内的子区间取max即可. nyoj15:求需要添加的最少 ...
- FZU 2059 MM (并查集+排序插入)
Problem 2059 MM Accept: 109 Submit: 484Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...
- Mathematics Base - Tensor
以下是我对张量的理解,备注是具体解释,Xmind导出的图片没法显示出来,主要还是将张量间的关系画出来,方便理解. 图1 张量