sdutoj 3252 Lowest Unique Price
2016-05-09 10:25
567 查看
题目链接:点击打开链接
题目大意:
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.
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.
思路:用哈希存储,遍历查找
题目大意:
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
思路:用哈希存储,遍历查找
#include <iostream> 02.#include<cstdio> 03.#include<cstdlib> 04.#include<cstring> 05. 06.using namespace std; 07.int a[1000005]; 08.int main() 09.{ 10. int t; 11. int n; 12. 13. scanf("%d",&t); 14. char s[2]; 15. int x; 16. int mx=-1; 17. while(t--) 18. { 19. mx=-1; 20. memset(a,0,sizeof(a)); 21. scanf("%d",&n); 22. for(int i=0;i<n;i++) 23. { 24. scanf("%s",s); 25. if(s[0]=='b') 26. { 27. scanf("%d",&x); 28. if(x>mx)mx=x; 29. a[x]++; 30. } 31. else if(s[0]=='c') 32. { 33. scanf("%d",&x); 34. a[x]--; 35. } 36. else if(s[0]=='q') 37. { 38. int f=0; 39. int j; 40. for(j=0;j<=mx;j++) 41. { 42. if(a[j]==1) 43. { 44. f=1; 45. break; 46. } 47. } 48. if(f==1)printf("%d\n",j); 49. else printf("none\n"); 50. } 51. } 52. } 53. return 0; 54.}
相关文章推荐
- Android UI 优化 使用<include/>和 <merge />标签
- QtGuid4.dll处有未经处理的异常,0xsdddddd5写入位置错误
- om.android.builder.model.SourceProvider.getShadersDirectories() not found
- Moqui学习之代码分析mantle priceServices.xml
- TabBar高度修改以及UITabBarItem坐标移动
- 界面设计,事件处理--GUI编程的核心--
- Implement Stack using Queues
- CRM开发要点(三)
- MUI卸载动画——粒子爆炸
- sudo: must be setuid root
- php 获取提交的数据 $_REQUEST = $_GET + $_POST + $_COOKIE
- Message Queue vs. Web Services?
- osg中的事件适配器GUIEventAdapter的含义
- UIViewController的生命周期
- uva 3485 Optimal Array Multiplication Sequence
- paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之fsm summary
- BlueTooth聊天软件(支持表情和语音)
- Implement Queue using Stacks
- paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之全0/1/z/x的SV写法
- hdu1423Greatest Common Increasing Subsequence(最长公共递增子序列)