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 第二轮: ...
随机推荐
- java——修改txt文件中某一行的内容
今天无意间看到java.io中有一个类:RandomAccessFile,可以在文件的任意位置进行读写操作,想到我之前写的一个小项目,想在txt中修改某一行的内容,都是从头遍历txt文件,修改这一行的 ...
- SQL SEVER 数据库日志(Log)文件增长过快的处理
SQL SERVER 2016数据库,50GB+的数据.有大量的增删和插入操作,数据库log文件变得异常的大,而且增长速度特别的快.周五log文件20GB,周一上班就成了200+GB了 因为数据库恢复 ...
- awk, sed, xargs, bash
http://ryanstutorials.net/ awk: split($1, arr, “\t”) sed: sed -n '42p' file sed '42d' file sed ' ...
- java 数字进制之间转换
//10进制转换 16进制 System.out.println(Integer.toHexString(val)); System.out.println(String.format("% ...
- jquery中load()加载页面,刷新之后,加载的页面不显示的解决办法
<script language="javascript" type="text/javascript"> $(function(){ $(&quo ...
- $.get和$.post实例
get和post用法一样,我只写个$.get的. [HTML] <input type="text" id="myFishName" name=" ...
- HDU 5532——Almost Sorted Array——————【技巧】
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- HDU 5352——MZL's City——————【二分图多重匹配、拆点||网络流||费用流】
MZL's City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- winfrom C#树勾选等
AfterCheck /// <summary> /// 树勾选 /// </summary> /// <param name="sender"> ...
- EF框架
Linq to EF 添加: //用户注册int IUserDAO.Register(Users user) { ; using (EF.ddgwDBEntities context = new EF ...