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. Dev Express Report 学习总结(八)Dev Express Reports 常见问题总结

    1. 在新建ASP.NET Dev Express Report时的两种方式: A. 右键Add DevExpress Item->New Item->All->从Web Repor ...

  2. hdfs shell命令及java客户端编写

    一. hdfs shell命令 可以通过hadoop fs 查看所有的shell命令及其用法. 传文件到hdfs: hadoop fs -put /home/koushengrui/Downloads ...

  3. JAVA HTTP请求和HTTPS请求

    HTTP与HTTPS区别:http://blog.csdn.net/lyhjava/article/details/51860215 URL发送 HTTP.HTTPS:http://blog.csdn ...

  4. Unity Transform

    public class PlayerControll : MonoBehaviour { Transform playerTransform; Animation playerAnimation; ...

  5. g++ 出现 undefined reference to ......

    g++ 出现 undefined reference to ...... 检查/usr/local/lib  /usr/lib 发现已经存在相应的库文件 那么,问题可能出现在g++链接次序上,即先链接 ...

  6. Zookeeper配置Kafka

    Zookeeper安装 解压:tar -zxvf zookeeper-3.4.5-cdh5.7.0.tar.gz -C ~/app/ 配置到环境变量: vi ~/.bash_profile expor ...

  7. Bootsrap Table表格分页

    一 bootsrap简介 Bootstrap,来自 Twitter,是目前很受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加 ...

  8. (转)Entity Framework4.1实现动态多条件查询、分页和排序

    原文:http://www.cnblogs.com/ahui/archive/2011/08/04/2127282.html EF通用的分页实现: 1 2 3 4 5 6 7 8 9 10 11 12 ...

  9. Hibernate课程 初探多对多映射3-1 课程总结

    如何通过添加中间表实现多对多? 1 在双方实体中添加一个保存对方的集合. 2 在双方映射文件中 使用<set>和<many-to-many>元素进行关联关系配置(注意此处)

  10. springmvc+spring+mybatis+sqlserver----插入一条新数据

    <insert id="addOneMsg" parameterType="java.util.Map"> INSERT INTO PDA_JWL_ ...