码迷,mamicode.com
首页 > 其他好文 > 详细

AMAZING AUCTION (第三届省赛)

时间:2015-05-04 19:29:55      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

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.

 

输入

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







 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 #include<ctype.h>
 5 #define N 1010
 6 #define max(a, b)(a > b ? a : b)
 7  
 8 typedef struct node
 9 {
10     char s[10];
11     int p;
12 } node;
13  
14 int cmp(const void *a, const void *b)
15 {
16     node *s1 = (node *)a, *s2 = (node *)b;
17     return s1->p - s2->p;
18 }
19 int main()
20 {
21     node node[N];
22     int m, n, i, x, a[N];
23     char str[N];
24     while(scanf("%d%d", &m, &n) != EOF)
25     {
26         memset(a, 0, sizeof(a));
27         for(i = 0 ; i < n ; i++)
28         {
29             scanf("%s%d", node[i].s, &node[i].p);
30             a[node[i].p]++;
31         }
32         qsort(node, n, sizeof(node[0]), cmp);
33         for(i = 0 ; i < n ; i++)
34         {
35             if(node[i].p <= m && a[node[i].p] == 1)
36             {
37                 strcpy(str, node[i].s);
38                 x = node[i].p;
39                 break;
40             }
41         }
42         printf("The winner is %s\nThe price is %d\n", str, x);
43     }
44     return 0;
45 }

 

AMAZING AUCTION (第三届省赛)

标签:

原文地址:http://www.cnblogs.com/yishilin/p/4476641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!