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

河南省第三届acm省赛 AMAZING AUCTION

时间:2016-05-12 15:40:16      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

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次的有多个,那么输出较小的那个

如果出现次数大于一个的话,就输出较小的那个。



#include <cstdio>


int a[1006];
struct node
{
    char name[100];
    int price;


}e[200];
int u, m;
int main()
{
    while(~scanf("%d %d", &u, &m))
    {
        for(int i = 1; i <= u; i++)
            a[i] = 0;
        for(int i = 1; i <= m; i++)
        {
            scanf("%s %d", e[i].name, &e[i].price);
            a[e[i].price]++;//统计价钱出现的次数
        }
        int pos = 0, P = -1;
        for(int i = 1; i <= u; i++)
        {
            if(a[i] == 1)
            {
                 pos = 1;
                P = i;
                break;
            }
        }
        if(pos == 1)
            for(int i = 1; i <= m; i++)
            {
                if(e[i].price == P)//
                {
                    printf("The winner is %s\n", e[i].name);
                    printf("The price is %d\n", e[i].price);
                    break;
                }
            }
        else
        {
            int KKK = -1;
            for(int i = 1; i <= u; i++)
            {
                if(a[i] >= 2)
                {
                    KKK = i;//记录下表。
                }
            }//找出现多次价钱最小的一次。
            for(int i = 1; i <= m; i++)
            {
                if(e[i].price == KKK)//
                {
                    printf("The winner is %s\n", e[i].name);
                    printf("The price is %d\n", e[i].price);
                    break;
                }
            }
        }
    }


    return 0;
}

河南省第三届acm省赛 AMAZING AUCTION

标签:

原文地址:http://blog.csdn.net/zs520ct/article/details/51360343

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