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 第二轮: ...
随机推荐
- Nohup后台运行程序
场景:我现在需要跑脚本批量处理一些数据,但是我又不想盯着控制台看这个脚本的输出结果,想把这些输出结果记录到一个日志文件里面 方案:可以使用 Linux 的 nohup 命令,把进程挂起,后台执行 用法 ...
- Angular JS ng-repeat 报错 Error: [ngRepeat:dupes]
ng-repeat常用情况: <div class="form-group" ng-repeat="item in items"></div& ...
- Vue.js-----轻量高效的MVVM框架(二、Vue.js的简单入门)
1.hello vue.js! (1)引入vue.js <script type="text/javascript" src="js/vue.js"> ...
- Jquery ValidationEngine 修改验证提示框的位置
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CTeX里面CTRL-Space和中文输入法的冲突问题解决
我使用的是windows xp,相信下面的方法也能应用到win7等windows系统上. 我希望在CTex套件的WinEdt 6.0里使用模板自动插入内容时,想快速从上到下遍历” * “并修改. 通过 ...
- [引]雅虎日历控件 Example: Two-Pane Calendar with Custom Rendering and Multiple Selection
本文转自:http://yuilibrary.com/yui/docs/calendar/calendar-multipane.html This example demonstrates how t ...
- Qt 学习
Qt 学习 C++ 模版 QObject 提供一个十分有用的 api,T findChild(QString, Qt::FindChildOptions),这个函数接收一个模版参数,返回模版参数的类型 ...
- System.Net.Mail
System.Net.Mail命名空间包含用于将电子邮件发送到简单邮件传输协议(SMTP)服务器进行传送的类. 在此命名空间中,有两个很重要的类: MailMessage 表示可以使用SmtpCli ...
- 异步对象(XMLHttpRequest)的帮助脚本
异步对象五部曲 这是post请求的. //1.00创建异步对象 var xhr = new XMLHttpRequest(); //2.0 xhr.open("post", url ...
- Mysql远程连接授权IP
新增法 我们现在增加一个'username'用户,密码为'password',让其能够从外部访问MYSQL. grant all on * to 'username' identified by ...