Auction
来源:互联网 发布:mac桌面文件不能拖动 编辑:程序博客网 时间:2024/05/17 06:45
Description
THE 30th ACM/ICPC ASIA REGIONAL 2005 HANGZHOU SITE
Onsite Contest Session
Problem A: 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.
Input Description
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.
The first line of each test case contains two integers: U (1 <= U <= 10,000), the price upper limit and M (1 <= M <= 100,000), 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) and the price P (1 <= P <= U), separated with a single space. All bids in the input are guaranteed to be valid ones.
Output Description
Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.
For each test case, print the sentence "The winner is W." on the first line, and "The price is P." on the second. Replace W and P with the winning bidder��s name and the winning price.
Sample Input
23 3Alice 1Bob 2Carl 33 6Alice 1Alice 2Alice 3Bob 1Bob 3Carl 3
Sample Output
Case 1:The winner is Alice.The price is 1.Case 2:The winner is Alice.The price is 2.注意把那句话看懂就会做了,开一个数组做标记就ok了。#include <stdio.h>#include <string.h>#include <string>#include <iostream>using namespace std;const int maxn = 10005;int vis[maxn]; //标记那些数字出现过struct node{ string s; int v;} a[maxn*10];int main ( ){ int T, U, M, ans, pos, cas = 0; scanf ( "%d", &T ); while ( T -- ) { memset ( vis, 0, sizeof ( vis ) ); scanf ( "%d%d", &U, &M ); for ( int i = 0; i < M; i ++ ) { cin >> a[i].s >> a[i].v; vis[ a[i].v ] ++; } ans = maxn; for ( int i = 0; i < maxn; i ++ ) if ( vis[i] == 1 ) //先找一个的 { ans = i; break ; } if ( ans >= maxn ) { int mn = maxn*10; for ( int i = 0; i < maxn; i ++ ) if ( vis[i] && vis[i] < mn ) //找个数最少的 { ans = i; mn = vis[i]; } } for ( int i = 0; i < M; i ++ ) if ( a[i].v == ans ) //找下标 { pos = i; break ; } if ( cas ++ ) printf ( "\n" ); printf ( "Case %d:\nThe winner is ", cas ); cout << a[pos].s << "." << endl; printf ( "The price is %d.\n", a[pos].v ); } return 0;}
- Auction
- Auction
- AMAZING AUCTION
- AMAZING AUCTION
- ???Auction Bidding
- Second-price Auction
- Second-price Auction
- Codeforces386A. Second-Price Auction
- codeforces Second-Price Auction
- Second-price Auction
- package auction.model;
- zoj3202 Second-price Auction
- Hrbust 1041 Chocolate Auction
- NYOJ 251 AMAZING AUCTION
- NYOJ 251 AMAZING AUCTION
- [转]Auction算法介绍
- ZOJ3202-Second-price Auction
- A. Second-price Auction
- 《leetCode》:Unique Paths
- 漫谈以太网交换机
- Html CSS
- Coursera Course: Programming Languages
- 从PDF中提取信息----PDFMiner
- Auction
- c++输入
- JSP防盗链接
- POJ 2255Tree Recovery 二叉树重建(根据前序遍历和中序遍历写出后序遍历)
- 脑子短路瞬间
- 给大家推荐几个NotePad++的插件
- 如何使用Clementine获得混淆矩阵
- Unity3D 处于Camera跟随游戏对象后面拍摄的方法
- Altium Designer学习: 原理图和PCB对应元器件交叉查找