AMAZING AUCTION(简单模拟)

2024-09-08 02:38
文章标签 简单 模拟 auction amazing

本文主要是介绍AMAZING AUCTION(简单模拟),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

AMAZING AUCTION

时间限制: 3000 ms  |  内存限制: 65535 KB
难度:4
描述

Recently the auction house hasintroduced 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 taskis to write the software to automate this auction system. 

First the auctioneer puts an upper limiton bid price for each item. Only positive price less than or equal to thisprice limit is a valid bid. For example, if the price limit is 100, then 1 to100, inclusive, are all valid bid prices. Bidder can not put more than one bidfor the same price on a same item. However they can put many bids on a sameitem, as long as the prices are different. 

After all bids are set, the auctioneerchooses the winner according to the following rules:

(1). If any valid price comes from onlyone 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 priceand the only bidder is the winning bidder.

(2). If there are no unique bids, thenthe price with fewest bids is the winning bid. If there are more than one pricewhich has the same lowest bid count, choose the lowest one. This price is thewinning price. The bidder who puts this bid first is the winning bidder. 

Giventhe price limit and all the bids that happen in order, you will determine thewinning 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


题意:

模拟一个拍卖活动,要求你找到拍卖赢家,买家可以对一个物品出多次价格但不能相同,你需要判断的赢家,赢家有两种判断方式

如果有唯一的竞猜价格,找到最小的价格即为该竞猜价格,该人为获奖的人,如果没有唯一的竞猜价格,这找最小的价格输出竞猜次数最少的人:

思路:

用vector容器储存字符串,将相同竞猜价格的人放在一起,,用一个一维数组统计各个竞猜价格的个数,寻找只有一个数的值,寻找到的第一个就是最小的值,如果不存在唯一的值,那就找最小的那个输出!

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;#define inf 0x3f3f3f3f
struct point
{string name;int money;
}people[1005];
int main()
{int u,t,flag[1005];int peice;vector<string>p[1005];int ans;while(cin>>u>>t){for(int i=0;i<=u;i++)p[i].clear();memset(flag,0,sizeof flag);for(int i=0;i<t;i++){cin>>people[i].name>>people[i].money;p[people[i].money].push_back(people[i].name);flag[people[i].money]++;}      //输入且初始化,统计个数,将价格相同的人放入一个数组int ans=inf;string ansname;bool flag1=0;vector<string>::iterator it;for(int i=0;i<=u;i++){if(flag[i]==1){ans=i;it=p[i].begin();ansname=*it;flag1=1;·break;}}//第一个查询不存在if(!flag1){for(int i=0;i<=u;i++){if(flag[i]>1){it=p[i].begin();ansname=*it;ans=i;break;}}}//第二个查找cout<<"The winner is "<<ansname<<endl;cout<<"The price is "<<ans<<endl;}
}



这篇关于AMAZING AUCTION(简单模拟)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1146878

相关文章

C++初始化数组的几种常见方法(简单易懂)

《C++初始化数组的几种常见方法(简单易懂)》本文介绍了C++中数组的初始化方法,包括一维数组和二维数组的初始化,以及用new动态初始化数组,在C++11及以上版本中,还提供了使用std::array... 目录1、初始化一维数组1.1、使用列表初始化(推荐方式)1.2、初始化部分列表1.3、使用std::

redis群集简单部署过程

《redis群集简单部署过程》文章介绍了Redis,一个高性能的键值存储系统,其支持多种数据结构和命令,它还讨论了Redis的服务器端架构、数据存储和获取、协议和命令、高可用性方案、缓存机制以及监控和... 目录Redis介绍1. 基本概念2. 服务器端3. 存储和获取数据4. 协议和命令5. 高可用性6.

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

利用Python编写一个简单的聊天机器人

《利用Python编写一个简单的聊天机器人》这篇文章主要为大家详细介绍了如何利用Python编写一个简单的聊天机器人,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 使用 python 编写一个简单的聊天机器人可以从最基础的逻辑开始,然后逐步加入更复杂的功能。这里我们将先实现一个简单的

使用IntelliJ IDEA创建简单的Java Web项目完整步骤

《使用IntelliJIDEA创建简单的JavaWeb项目完整步骤》:本文主要介绍如何使用IntelliJIDEA创建一个简单的JavaWeb项目,实现登录、注册和查看用户列表功能,使用Se... 目录前置准备项目功能实现步骤1. 创建项目2. 配置 Tomcat3. 项目文件结构4. 创建数据库和表5.

使用PyQt5编写一个简单的取色器

《使用PyQt5编写一个简单的取色器》:本文主要介绍PyQt5搭建的一个取色器,一共写了两款应用,一款使用快捷键捕获鼠标附近图像的RGB和16进制颜色编码,一款跟随鼠标刷新图像的RGB和16... 目录取色器1取色器2PyQt5搭建的一个取色器,一共写了两款应用,一款使用快捷键捕获鼠标附近图像的RGB和16

四种简单方法 轻松进入电脑主板 BIOS 或 UEFI 固件设置

《四种简单方法轻松进入电脑主板BIOS或UEFI固件设置》设置BIOS/UEFI是计算机维护和管理中的一项重要任务,它允许用户配置计算机的启动选项、硬件设置和其他关键参数,该怎么进入呢?下面... 随着计算机技术的发展,大多数主流 PC 和笔记本已经从传统 BIOS 转向了 UEFI 固件。很多时候,我们也

基于Qt开发一个简单的OFD阅读器

《基于Qt开发一个简单的OFD阅读器》这篇文章主要为大家详细介绍了如何使用Qt框架开发一个功能强大且性能优异的OFD阅读器,文中的示例代码讲解详细,有需要的小伙伴可以参考一下... 目录摘要引言一、OFD文件格式解析二、文档结构解析三、页面渲染四、用户交互五、性能优化六、示例代码七、未来发展方向八、结论摘要

MyBatis框架实现一个简单的数据查询操作

《MyBatis框架实现一个简单的数据查询操作》本文介绍了MyBatis框架下进行数据查询操作的详细步骤,括创建实体类、编写SQL标签、配置Mapper、开启驼峰命名映射以及执行SQL语句等,感兴趣的... 基于在前面几章我们已经学习了对MyBATis进行环境配置,并利用SqlSessionFactory核

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个