AMAZING AUCTION
来源:互联网 发布:类似爱情2只有我知结局 编辑:程序博客网 时间:2024/05/16 12:45
AMAZING AUCTION
- 描述
Recently the auction house has introduced a new type of auction, the lowest price auction. In this new system, people compete for the lowest bid price, as opposed to what they did in the past. What an amazing thing! Now you could buy cool stuff with one penny. Your task is to write the software to automate this auction system.
First the auctioneer puts an upper limit on bid price for each item. Only positive price less than or equal to this price limit is a valid bid. For example, if the price limit is 100, then 1 to 100, inclusive, are all valid bid prices. Bidder can not put more than one bid for the same price on a same item. However they can put many bids on a same item, as long as the prices are different.
After all bids are set, the auctioneer chooses the winner according to the following rules:
(1). If any valid price comes from only one bidder, the price is a "unique bid". If there are unique bids, then the unique bid with the lowest price wins. This price is the winning price and the only bidder is the winning bidder.
(2). If there are no unique bids, then the price with fewest bids is the winning bid. If there are more than one price which has the same lowest bid count, choose the lowest one. This price is the winning price. The bidder who puts this bid first is the winning bidder.
Given the price limit and all the bids that happen in order, you will determine the winning bidder and the winning price.
- 输入
- There are multi test cases.EOF will terminate the input.
The first line contains two integers: U (1 <= U <= 1000), the price upper limit and M (1 <= M <= 100), the total number of bids. M lines follow, each of which presents a single bid. The bid contains the bidder's name (consecutive non-whitespace characters<=5) and the price P (1 <= P <= U), separated with a single space. All bids in the input are guaranteed to be valid ones. - 输出
- Print the sentence "The winner is W" on the first line, and "The price is P" on the second.
- 样例输入
30 7 Mary 10 Mary 20Mary 30Bob 10Bob 30Carl 30Alice 23
- 样例输出
The winner is MaryThe price is 20
来源
解题思路:简单题,一次AC
知道题意就很好做的:求价格出现一次且最少的
我的代码:
#include<bits/stdc++.h>#define inf 0x3f3f3f3fusing namespace std;struct node{ string name; int p; int id;}a[105];int main(){ int mp,n; while(scanf("%d%d",&mp,&n)!=EOF) { int i=0; for(i=0;i<n;i++) { cin>>a[i].name>>a[i].p; if(a[i].p>mp) a[i].id=1; else a[i].id=0; } for(i=0;i<n;i++) for(int j=i+1;j<n;j++) { if(a[i].p==a[j].p) { a[i].id=1; a[j].id=1; } } string m; int minp=10000; for(i=0;i<n;i++) { if(a[i].id==0&&a[i].p<minp) { m=a[i].name; minp=a[i].p; } } cout<<"The winner is "<<m<<endl; cout<<"The price is "<<minp<<endl; } return 0;}
- AMAZING AUCTION
- AMAZING AUCTION
- NYOJ 251 AMAZING AUCTION
- NYOJ 251 AMAZING AUCTION
- 第三届省赛题 AMAZING AUCTION
- NYOJ251 AMAZING AUCTION
- nysit 251—AMAZING AUCTION
- AMAZING AUCTION(简单模拟)
- 河南省第三届省赛 AMAZING AUCTION
- 河南省第三届acm省赛 AMAZING AUCTION
- (精)河南省第三届acm(AMAZING AUCTION)
- nyoj 251 AMAZING AUCTION 第三届河南省赛
- Auction
- Auction
- NYOJ-251-AMAZING AUCTION(第三届河南省程序设计大赛H题(模拟))
- Amazing
- amazing
- Amazing!
- RingtoneManager获取铃声uri返回空值的问题
- leetcode-338. Counting Bits
- Linux中环境变量文件及配置
- 51nod_1136 欧拉函数
- 如何给caffe添加新的层
- AMAZING AUCTION
- C/C++中 变量的存储位置
- spring4学习记录04-spring mvc实战之框架构建引入jpa
- java学习 十六、内部类
- Boolan C++面向对象高级编程(上)第二周笔记
- Lucene索引库的优化
- 在fragment中使用viewpager+fragment时,fragment页面消失的问题
- iOS 探讨之 IPA瘦身
- 数据清洗1