Compass Card Sales

时间限制: 3 Sec  内存限制: 128 MB
提交: 35  解决: 13
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Katla has recently stopped playing the collectible card game Compass. As you might remember, Compass is a game where each card has a red, a green and a blue angle, each one between 0 and 359, as well as an ID. Since she has stopped playing, Katla has decided to sell all her cards. However, she wants to keep her deck as unique as possible while selling off the cards.
Can you help her figure out the order in which she should sell the cards?
To decide how unique a card is in the deck, she proceeds as follows. For each of the three colors she finds the closest other card in both directions, and then computes the angle between these two other cards. 
For instance if she has three cards with red angles 42,90 and 110, then the uniqueness values of their red angles are 340, 68, and 312, respectively. If two cards A and B have the same angle, B is considered the closest to A in both directions so that the uniqueness value of A (and B) for that color is 0.
By summing the uniqueness values over the three colours, Katla finds how unique each card is. When selling a card, Katla sells the currently least unique card (smallest uniqueness value). 
If two cards have the same uniqueness value, she will sell the one with the higher ID first. After each card is sold, the uniqueness values of the remaining cards are updated before selling the next card.

输入

The first line of input contains an integer n, the number of cards (1 ≤ n ≤ 105 ). Then follows n lines. Each of these n lines contains 4 integers r, g, b, id (0 ≤ r, g, b < 360, 0 ≤ id < 231 ),giving the red, green and blue angles as well as the ID of a card. No two cards have the same ID

输出

Output n lines, containing the IDs of the cards in the order they are to be sold, from first (least unique) to last (most unique).

样例输入

3
42 1 1 1
90 1 1 2
110 1 1 3

样例输出

2
3
1
思路:模拟!!!
 #include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
struct node
{
int score,id;
node() {};
node(int score,int id):score(score),id(id) {};
bool operator<(const node &rhs)const
{
if(score!=rhs.score) return score<rhs.score;
return id>rhs.id;
} };
map<int,int> ma;
set<node> ans;
set<int> res[][];
vector<int> angle[];
int tmp[maxn],ele[maxn][],vis[][];
int l[][],r[][],sc[][];
int cal_ang(int c,int x)
{
if(vis[c][x]>=) return ;
int ang=,ll=l[c][x],rr=r[c][x];
ang+=ll<x?x-ll:+x-ll;
ang+=rr>x?rr-x:+rr-x;
return ang;
}
int cal(int x)
{
int ans=;
for(int i=;i<;i++) ans+=sc[i][ele[x][i]];
return ans;
}
void update(int x)
{
for(int i=;i<;i++)
{
int ang=ele[x][i];
--vis[i][ang];
if(vis[i][ang]==)
{
int ll=l[i][ang],rr=r[i][ang];
l[i][rr]=ll,r[i][ll]=rr;
int tp=cal_ang(i,ll);
if(sc[i][ll]!=tp)
{
sc[i][ll]=tp;
for(auto v:res[i][ll])
{
ans.erase(ans.find(node(tmp[v],ele[v][])));
tmp[v]=cal(v);
ans.insert(node(tmp[v],ele[v][]));
}
}
tp=cal_ang(i,rr);
if(sc[i][rr]!=tp)
{
sc[i][rr]=tp;
for(auto v:res[i][rr])
{
ans.erase(ans.find(node(tmp[v],ele[v][])));
tmp[v]=cal(v);
ans.insert(node(tmp[v],ele[v][]));
}
}
}
if(vis[i][ang]==)
{
for(auto v:res[i][ang])
{
sc[i][ang]=cal_ang(i,ang);
if(tmp[v]!=cal(v))
{
ans.erase(ans.find(node(tmp[v],ele[v][])));
ans.insert(node(tmp[v]=cal(v),ele[v][]));
}
}
}
}
}
int main()
{
int n,cnt;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
for(int j=;j<;j++) scanf("%d",&ele[i][j]);
for(int j=;j<;j++)
{
if(!vis[j][ele[i][j]]) angle[j].push_back(ele[i][j]);
res[j][ele[i][j]].insert(i);
vis[j][ele[i][j]]++;
}
ma[ele[i][]]=i;
}
for(int i=;i<;i++)
{
sort(angle[i].begin(),angle[i].end());
for(int j=;j+<angle[i].size();j++)
{
l[i][angle[i][j+]]=angle[i][j];
r[i][angle[i][j]]=angle[i][j+];
}
l[i][angle[i][]]=angle[i][angle[i].size()-];
r[i][angle[i][angle[i].size()-]]=angle[i][];
for(int j=;j<angle[i].size();j++)
{
sc[i][angle[i][j]]=cal_ang(i,angle[i][j]);
}
}
for(int i=;i<=n;i++)
{
tmp[i]=cal(i);
ans.insert(node(tmp[i],ele[i][]));
}
while(ans.size())
{
auto it=ans.begin();
cnt=ma[it->id];
printf("%d\n",ele[cnt][]);
ans.erase(it);
for(int i=;i<;i++) res[i][ele[cnt][i]].erase(cnt);
update(cnt);
}
return ;
}

Compass Card Sales(模拟)的更多相关文章

  1. HDU 2319 Card Trick (模拟)

    题目链接 Problem Description The magician shuffles a small pack of cards, holds it face down and perform ...

  2. 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)

    A. Airport Coffee 设$f_i$表示考虑前$i$个咖啡厅,且在$i$处买咖啡的最小时间,通过单调队列优化转移. 时间复杂度$O(n)$. #include<cstdio> ...

  3. 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) Solution

    A - Airport Coffee 留坑. B - Best Relay Team 枚举首棒 #include <bits/stdc++.h> using namespace std; ...

  4. Urozero Autumn 2016. NCPC 2016

    A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...

  5. iOS 非ARC基本内存管理系列 3-循环retain和@class

    1.@class 使用场景:对于循环依赖关系来说,比方A类引用B类,同时B类也引用A类: 可以看出Person和Card互相引用,此时如果使用#import编译报错!因此当使用@class在两个类中相 ...

  6. hdu 2629 Identity Card (字符串解析模拟题)

    这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...

  7. 2017-9-3模拟赛T1 卡片(card)

    题目 [题目描述] lrb 喜欢玩卡牌.他手上现在有n张牌,每张牌的颜色为红绿蓝中的一种.现在他有两种操作.一是可以将两张任意位置的不同色的牌换成一张第三种颜色的牌:二是可以将任意位置的两张相同颜色的 ...

  8. Card Stacking 队列模拟

    题目链接:https://ac.nowcoder.com/acm/contest/993/ABessie is playing a card game with her N-1 (2 <= N ...

  9. SPOJ 1108 Card Trick 暴力模拟

    解释一下样例,因为我觉得这个题意表述的不是很清楚.以第二组样例为例. 牌序为:3 1 4 5 2 第一轮:把 3 放到末尾:1 4 5 2 3,最顶上的牌是1,把1拿走.剩余 4 5 2 3 第二轮: ...

随机推荐

  1. 3 不用IDE开发groovy

    1       不用IDE开发groovy 1.1  不用IDE开发的方法 可以在IDE中运行Groovy类或者脚本,但是Groovy也提供了其他运行途径.你能运行Groovy代码基于以下: ·    ...

  2. npm常用技巧

    npm中内置了大量的实用技巧,如何高效的使用它们是一件充满挑战的事情.学会下面11个技巧,将会让你在任何项目中使用npm都会事半功倍. 1.如何打开package的主页 npm home $packa ...

  3. Could not read settings.xml

    这个问题为什么会发生? 其实不要想太多, 1.文件格式是utf-8 2.其中的报文格式非常重要,千万不能弄错,如果多了一处注释,就会发生以上问题,拼写的时候多注意语义

  4. 数据结构---Java---数组

    **************************************************************前言************************************ ...

  5. leetcode 182. Duplicate Emails having的用法 SQL执行顺序

    https://leetcode.com/problems/duplicate-emails/description/ 首先sql的执行顺序是 from-->where-->group b ...

  6. inventor卸载不干净

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  7. 性能测试工具LoadRunner18-LR之Controller 集合点

    含义 当通过controller虚拟多个用户执行该脚本时.用户的启动或运行步骤不一定是同步的.集合点是在脚本的某处设置一个标记.当有虚拟用户运行到这个标记时,停下等待,直到所有用户都达到这个标记时,再 ...

  8. 对象池2(方法功能)Pools

    对象池Pools(主要调用方法功能) namespace kernal { public class Pools : MonoBehaviour { [HideInInspector] public ...

  9. CentOS7安装Nginx实现API网关

    参考 http://nginx.org/ http://nginx.org/en/linux_packages.html#stable https://www.npmjs.com/package/js ...

  10. git合并分支上的commit为一条commit到master

    标签: git 缘由? 有一次被人问到怎么把一个分支的所有commit按一个commit合并到主分支上,当时一脸蒙B,平时开发都是直接merge,很少考虑到这种问题,于是特意搜索了相关资料. 场景 其 ...