山东省第六届ACM大学生程序设计竞赛-Lowest Unique Price(桶排序)
来源:互联网 发布:二胡软件 编辑:程序博客网 时间:2024/05/21 15:47
Lowest Unique Price
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Recently my buddies and I came across an idea! We want to build a website to sell things in a new way.
For each product, everyone could bid at a price, or cancel his previous bid, finally we sale the product to the one who offered the "lowest unique price". The lowest unique price is defined to be the lowest price that was called only once.
So we need a program to find the "lowest unique price", We'd like to write a program to process the customers' bids and answer the query of what's the current lowest unique price.
All what we need now is merely a programmer. We will give you an "Accepted" as long as you help us to write the program.
输入
The first line of input contains an integer T, indicating the number of test cases (T ≤ 60).
Each test case begins with a integer N (1 ≤ N ≤ 200000) indicating the number of operations.
Next N lines each represents an operation.
There are three kinds of operations:
"b x": x (1 ≤ x ≤ 106) is an integer, this means a customer bids at price x.
"c x": a customer has canceled his bid at price x.
"q" : means "Query". You should print the current lowest unique price.
Our customers are honest, they won\'t cancel the price they didn't bid at.
输出
Please print the current lowest unique price for every query ("q"). Print "none" (without quotes) if there is no lowest unique price.
示例输入
2 3 b 2 b 2 q 12 b 2 b 2 b 3 b 3 q b 4 q c 4 c 3 q c 2 q
示例输出
none none 4 3 2
提示
来源
题目意思:
b x 表示以x的价格参与竞标;
c x 表示取消价格为n的竞标;
q 表示查询只有一人出价的最低价格。
解题思路:
试着用了一下桶排序,没想到一下子就过了~
注意输入输出方式~纯用cin/cout回超时~
#include <iostream>#include <cstring>#include <set>using namespace std;#define MAXN 200002int a[MAXN];int main(){ ios::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--) { memset(a,0,sizeof(a)); int n,i,j,x; cin>>n; for(i=0; i<n; ++i) { char c; cin>>c; if(c=='b') { cin>>x; ++a[x]; } else if(c=='c') { cin>>x; --a[x]; } else if(c=='q') { int flag=0; for(j=0; j<MAXN; ++j) if(a[j]&&a[j]==1) { cout<<j<<endl; flag=1; break; } if(flag==0) cout<<"none"<<endl; } } } return 0;}/*23b 2b 2q12b 2b 2b 3b 3qb 4qc 4c 3qc 2q*/
0 0
- 山东省第六届ACM大学生程序设计竞赛-Lowest Unique Price(桶排序)
- 2015年山东省第六届ACM大学生程序设计竞赛-B-Lowest Unique Price
- 第六届山东省ACM竞赛 B题 Lowest Unique Price
- 山东省第六届ACM竞赛 Lowest Unique Price(set+map)分析,总结
- 【第六届山东省ACM竞赛】B题 Lowest Unique Price(SDUT3252)
- 2015山东省第六届ACM省赛 Lowest Unique Price
- 山东省ACM竞赛(2015)---B - Lowest Unique Price
- 山东省第七届ACM大学生程序设计竞赛
- 第四届 山东省ACM大学生程序设计竞赛
- 第七届 山东省ACM大学生程序设计竞赛
- Lowest Unique Price 第六届ACM省赛B题
- 【山东省第六届“浪潮杯”ACM大学生程序设计竞赛】赛后心情贴
- 山东省第六届ACM大学生程序设计竞赛-Square Number(完全平方数)
- 山东省第六届ACM大学生程序设计竞赛-Single Round Math(大数除法)
- SDUT 3258 Square Number(2015年山东省第六届ACM大学生程序设计竞赛)
- SDUT 3262 Colorful Cupcakes (2015年山东省第六届ACM大学生程序设计竞赛)
- SDUT3258Square Number(2015年山东省第六届ACM大学生程序设计竞赛)
- 山东省第六届ACM大学生程序设计竞赛 训练总结 [(7+1)/12] 待补
- hadoop集群搭建
- [GIT] 取消对某个文件的追踪
- JavaScript闭包中的this
- springMVC (五) annotation-driven
- java之九 基本输入输出流
- 山东省第六届ACM大学生程序设计竞赛-Lowest Unique Price(桶排序)
- Java中Vector ArrayList LinkedList之间的区别与联系
- 关于cmake is not able to compile a simple test program
- SpringMVC的表单验证方式
- (C++)int,char,string之间的一些转换
- C++中的STL中map用法详解(1)
- Hbase 1.2.1 Java API简单demo
- Android多用户模式的特性
- 六角幻方(DFS)