NYOJ 251 AMAZING AUCTION

来源:互联网 发布:清华大学ipv6网络电视 编辑:程序博客网 时间:2024/05/16 03:13

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 <iostream>#include<cstdio>#include<cstring>#include<vector>#include<stack>#include<algorithm>#define maxn 110using namespace std;vector<int>g[1010];int rec[1010];int main(){    int n,m,p;    char name[maxn][10],s[10];    while(~scanf("%d%d",&n,&m))    {        int cnt=0;        memset(name,0,sizeof(name));        for(int i=1;i<1010;++i)            g[i].clear();        for(int j=0;j<m;++j)        {            scanf("%s%d",s,&p);            int flag=0;            for(int i=0;i<cnt;++i)            {                if(strcmp(name[i],s)==0)                {                    flag=i;                    break;                }            }            if(!flag)            {                g[p].push_back(cnt);                strcpy(name[cnt++],s);            }            else                g[p].push_back(flag);        }        int ansp=n,ansb=-1;        for(int i=1;i<n;++i)        {            int tem=g[i].size();            if(tem&&tem<g[ansp].size())                ansp=i;        }        ansb=g[ansp][0];        printf("The winner is %s\n",name[ansb]);        printf("The price is %d\n",ansp);    }    return 0;}


0 0
原创粉丝点击