Compass Card Sales(模拟)
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.
输入
输出
样例输入
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(模拟)的更多相关文章
- HDU 2319 Card Trick (模拟)
题目链接 Problem Description The magician shuffles a small pack of cards, holds it face down and perform ...
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
A. Airport Coffee 设$f_i$表示考虑前$i$个咖啡厅,且在$i$处买咖啡的最小时间,通过单调队列优化转移. 时间复杂度$O(n)$. #include<cstdio> ...
- 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; ...
- Urozero Autumn 2016. NCPC 2016
A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...
- iOS 非ARC基本内存管理系列 3-循环retain和@class
1.@class 使用场景:对于循环依赖关系来说,比方A类引用B类,同时B类也引用A类: 可以看出Person和Card互相引用,此时如果使用#import编译报错!因此当使用@class在两个类中相 ...
- hdu 2629 Identity Card (字符串解析模拟题)
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...
- 2017-9-3模拟赛T1 卡片(card)
题目 [题目描述] lrb 喜欢玩卡牌.他手上现在有n张牌,每张牌的颜色为红绿蓝中的一种.现在他有两种操作.一是可以将两张任意位置的不同色的牌换成一张第三种颜色的牌:二是可以将任意位置的两张相同颜色的 ...
- Card Stacking 队列模拟
题目链接:https://ac.nowcoder.com/acm/contest/993/ABessie is playing a card game with her N-1 (2 <= N ...
- SPOJ 1108 Card Trick 暴力模拟
解释一下样例,因为我觉得这个题意表述的不是很清楚.以第二组样例为例. 牌序为:3 1 4 5 2 第一轮:把 3 放到末尾:1 4 5 2 3,最顶上的牌是1,把1拿走.剩余 4 5 2 3 第二轮: ...
随机推荐
- 基于Visual Studio .NET2015的单元测试 OpenCover
https://www.cnblogs.com/XiaoRuLiang/p/10095723.html 基于Visual Studio .NET2015的单元测试 1. 在Visual Stud ...
- 1.1 Rust安装
从今天起,坚持每天学习10分钟Rust...这是一个刚兴起几年的语言,希望深入地进行学习,为什么呢,因为以下这些让人辛酸的理由..... 最开始学习的是C++,没学太懂,之后又学了C,这时还完全对计算 ...
- nginx 资源重定向
背景:有时候我一些资源(.js .css etc.)等不想访问我本地的,我想重定向到其他 URL 解决:直接修改 nginx 的配置文件 conf,添加下面的代码 #avoid processing ...
- mapreduce统计总数
现有某电商网站用户对商品的收藏数据,记录了用户收藏的商品id以及收藏日期,名为buyer_favorite1. buyer_favorite1包含:买家id,商品id,收藏日期这三个字段,数据以“\t ...
- c++中代理类的学习
https://blog.csdn.net/lcg910978041/article/details/51468680 C++代理类是为了解决这样的问题: 容器通常只能包含一种类型的对象,所以很难在容 ...
- MongoDB系列—— Window 搭建Mongodb 集群
Mongodb的集群方式的搭建有三种:Replica Set / Sharding / Master-Slaver.这里只说明最简单的集群搭建方式(Replica Set) Replica Set M ...
- (转)Python作业day2购物车
Python作业day2购物车 原文:https://www.cnblogs.com/spykids/p/5163108.html 流程图: 实现情况: 可自主注册, 登陆系统可购物,充值(暂未实现) ...
- Python高级数据类型
除了python中默认提供的几种基本数据类型 collections模块还提供了几种特别好用的类型! 1.Conters //计数器 2.Orderdict // 有序字典 3.defalutdict ...
- 1.字符串池化(intern)机制及拓展学习
1.字符串intern机制 用了这么久的python,时刻和字符串打交道,直到遇到下面的情况: a = "hello" b = "hello" print(a ...
- 实现AB值对换的两种方法
package com.smbea.demo.exchange; /** * AB对换 * @author hapday * @2017年1月22日 @上午12:36:24 */ public cla ...