您的位置:首页 > 其它

NYOJ 251 AMAZING AUCTION

2016-04-30 19:00 281 查看



AMAZING AUCTION

时间限制:3000 ms | 内存限制:65535 KB
难度:4

描述
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 20
Mary 30
Bob 10
Bob 30
Carl 30
Alice 23


样例输出
The winner is Mary
The price is 20


来源第三届河南省程序设计大赛
上传者ACM_赵铭浩

题意:
在多位出价者中找到出价 1. 不重复的 2.在不重复的情况下出价最低的出价者输出来,没有则不输出。将数据存入结构体中,对价格进行排序,然后进行逐一判断。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct A
{
char s[6];
int pri;
}a[110];
bool cmp(A a,A b)
{
return a.pri < b.pri;  //从小到大排
}
int main()
{
int u,m;
while(~scanf("%d%d",&u,&m))
{
for(int i = 0;i < m;i++)
{
scanf("%s %d",a[i].s,&a[i].pri);
}
sort(a,a + m,cmp);
a[m].pri = 0x3f3f3f3f;
if(a[0].pri != a[1].pri && a[0].pri <= u)  //如果排序后第 0个跟第 1个不同,直接输出
{
printf("The winner is %s\nThe price is %d\n",a[0].s,a[0].pri);
}
else
{
for(int i = 1;i < m;i ++)
{
if(a[i].pri <= u && a[i].pri != a[i - 1].pri && a[i].pri != a[i + 1].pri) //既不和前面相同又不和后面相同时,有可能最低出价者出的已超过要求的价格u
{
printf("The winner is %s\nThe price is %d\n",a[i].s,a[i].pri);
break;
}
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: