河南省第三届acm省赛 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 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;

}

时间: 2024-10-15 07:57:52

河南省第三届acm省赛 AMAZING AUCTION的相关文章

Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)

本文出处:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2411 题意:给你一个串,让你依据那个串来输出ppi.坑特别多.ppi的计算方法是dp / inches; dp = sqrt(wp*wp + hp * hp); 现在我来说说这个题目有多坑: 给你的串的格式是这样: name + inches+ "inches"

Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

Time Limit: 5000MS Memory limit: 65536K 题目描写叙述 Haveyou ever played a popular game named "Fruit Ninja"? Fruit Ninja (known as Fruit Ninja HD on the iPad and Fruit Ninja THD for NvidiaTegra 2 based Android devices) is a video game developed by Hal

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

光说不练是假把式,先给各大巨巨们一个刷题链接:戳我进入刷题OJ 这届比赛水题有点多,想拿奖保证好手速即可.但是想拿高名次并不太容易 A.常规做法我不太会,但是根据题目的数据发现,可以开个这么大的数组哈哈,那么万能的暴力保证1A. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=500; int num[maxn]; int main(){

河南省第四届acm省赛 表达式求值(栈的应用)

表达式求值 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min(20,23)的值是20 ,add(10,98) 的值是108等等.经过训练,Dr.Kong设计的机器人卡多甚至会计算一种嵌套的更复杂的表达式. 假设表达式可以简单定义为: 1. 一个正的十进制数 x 是一个表达式. 2. 如果 x 和 y 是 表达式,则 函数min(x,y )也是表达式,其值为x,y

Pick apples 第三届acm省赛

Description Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because she has never seen so many apples before. Each ki

sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛

本文出自:http://blog.csdn.net/svitter/ 题意:三种苹果,每种都有对应的Size,Value,给你一个背包空间,求最大的价值. 本题目的关键就在于非常大的背包空间 依据indicates the size (1 <= S<= 100) 我们可以考虑在1000000(100^3)之外的空间放性价比最高的苹果.为什么时100^3? 要知道背包如果正好填满,而填满空间相应价值的苹果大于不填满的价值的苹果,那么就选择能填满空间而使价值最大的苹果,而非性价比最高的苹果--性价

AMAZING AUCTION (第三届省赛)

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 oppos

Mine Number(搜索,暴力) ACM省赛第三届 G

1 安装及下载client 端 2 什么是SVN(Subversion)? 3 为甚么要用SVN? 4 怎么样在Windows下面建立SVN Repository? 5 建立一个Working目录 6 新增档案及目录到Repository中 7 更新档案及目录 8 更新至特定版本 9 复制档案及目录 10 制作Tag或是Release 11 快速参考 11.1 取得(Checkout)Repository 11.2 更新(Update)档案或目录 11.3 新增(Add)档案或目录 11.4 提

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst