nyoj251 AMAZING AUCTION

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 20Mary 30Bob 10Bob 30Carl 30Alice 23
样例输出
The winner is MaryThe price is 20
来源

第三届河南省程序设计大赛

模拟题,估计是看懂他这种奇怪拍卖的规则。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include <vector>
using namespace std;
const int maxn = 1005;
int flag[maxn];
struct person{
	string name;
	int index, price;
	bool operator< (const person& para) const {
		if (price < para.price) return true;
		else  return index < para.index;
	}
};
vector<person> vec;
int main() {
//	freopen("in.txt", "r", stdin);
	int limit, t;
	while (cin>>limit>>t) {
		memset(flag, 0, sizeof(flag));
		vec.clear();
		for(int i=0; i<t; i++){
			string name;
			int pri;
			cin>>name>>pri;
			person tmp;
			tmp.index = i;
			tmp.price = pri;
			tmp.name = name;
			vec.push_back(tmp);
			flag[pri]++;
		}
		int mark = 0;
		int min_ct = 0xfffffff;
		int min_price = 0;
		for (int i=0; i<maxn; i++) {
			if (flag[i] == 1) mark = 1;
			if (mark == 1) break;
			if (flag[i] > 1 && min_ct > flag[i]){
				min_ct = flag[i];
				min_price = i;
			}
		}
		person min_person;
		min_person.price = 0xfffffff;
		if (mark == 1) {
			for (int i=0; i<vec.size(); i++) {
				if (flag[vec[i].price] != 1) continue;
				else if (min_person.price > vec[i].price) {
					min_person.price = vec[i].price;
					min_person.name = vec[i].name;
				}
			}
		} else {
			sort(vec.begin(), vec.end());
			for (int i=0; i<vec.size(); i++) {
//				cout<<vec[i].name<<" "<<vec[i].price<<endl;
				if (vec[i].price == min_price) {
					min_person.name = vec[i].name;
					min_person.price = vec[i].price;
					break;
				}
			}
		}
		cout<<"The winner is "<<min_person.name<<"\nThe price is "<<min_person.price<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值