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

相关文章

基于Python实现一个简单的题库与在线考试系统

《基于Python实现一个简单的题库与在线考试系统》在当今信息化教育时代,在线学习与考试系统已成为教育技术领域的重要组成部分,本文就来介绍一下如何使用Python和PyQt5框架开发一个名为白泽题库系... 目录概述功能特点界面展示系统架构设计类结构图Excel题库填写格式模板题库题目填写格式表核心数据结构

C/C++ chrono简单使用场景示例详解

《C/C++chrono简单使用场景示例详解》:本文主要介绍C/C++chrono简单使用场景示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友... 目录chrono使用场景举例1 输出格式化字符串chrono使用场景China编程举例1 输出格式化字符串示

Python使用pynput模拟实现键盘自动输入工具

《Python使用pynput模拟实现键盘自动输入工具》在日常办公和软件开发中,我们经常需要处理大量重复的文本输入工作,所以本文就来和大家介绍一款使用Python的PyQt5库结合pynput键盘控制... 目录概述:当自动化遇上可视化功能全景图核心功能矩阵技术栈深度效果展示使用教程四步操作指南核心代码解析

windows和Linux安装Jmeter与简单使用方式

《windows和Linux安装Jmeter与简单使用方式》:本文主要介绍windows和Linux安装Jmeter与简单使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Windows和linux安装Jmeter与简单使用一、下载安装包二、JDK安装1.windows设

Python模拟串口通信的示例详解

《Python模拟串口通信的示例详解》pySerial是Python中用于操作串口的第三方模块,它支持Windows、Linux、OSX、BSD等多个平台,下面我们就来看看Python如何使用pySe... 目录1.win 下载虚www.chinasem.cn拟串口2、确定串口号3、配置串口4、串口通信示例5

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Mysql表的简单操作(基本技能)

《Mysql表的简单操作(基本技能)》在数据库中,表的操作主要包括表的创建、查看、修改、删除等,了解如何操作这些表是数据库管理和开发的基本技能,本文给大家介绍Mysql表的简单操作,感兴趣的朋友一起看... 目录3.1 创建表 3.2 查看表结构3.3 修改表3.4 实践案例:修改表在数据库中,表的操作主要

springboot简单集成Security配置的教程

《springboot简单集成Security配置的教程》:本文主要介绍springboot简单集成Security配置的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录集成Security安全框架引入依赖编写配置类WebSecurityConfig(自定义资源权限规则

如何使用Python实现一个简单的window任务管理器

《如何使用Python实现一个简单的window任务管理器》这篇文章主要为大家详细介绍了如何使用Python实现一个简单的window任务管理器,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起... 任务管理器效果图完整代码import tkinter as tkfrom tkinter i

C++中函数模板与类模板的简单使用及区别介绍

《C++中函数模板与类模板的简单使用及区别介绍》这篇文章介绍了C++中的模板机制,包括函数模板和类模板的概念、语法和实际应用,函数模板通过类型参数实现泛型操作,而类模板允许创建可处理多种数据类型的类,... 目录一、函数模板定义语法真实示例二、类模板三、关键区别四、注意事项 ‌在C++中,模板是实现泛型编程