当前位置:网站首页>AcWing1800. 不做最后一个(枚举)
AcWing1800. 不做最后一个(枚举)
2022-04-21 15:22:00 【岁忧】
题目:1800. 不做最后一个!


题解:先用map记录下每只牛的产奶量,然后再读出mp中的键值对到PII里,然后排序。找到第二小的位置,不存在or第二小的位置后面一个位置值和它一样,则输出Tie。否则输出对应的牛名字即可。
#include<bits/stdc++.h>
#define x first`在这里插入代码片`
#define y second
using namespace std;
typedef long long LL;
typedef pair<int ,string> PII;
const int N=1e5+10;
const int mod=100000007;
unordered_map<string ,int>mp={
{
"Bessie",0},{
"Elsie",0},{
"Daisy",0},{
"Gertie",0},
{
"Annabelle",0},{
"Maggie",0},{
"Henrietta",0}
};
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
string s;
int t;
cin>>s>>t;
mp[s]+=t;
}
PII p[10];
int k=0;
for(auto i:mp){
p[k].x=i.y;
p[k].y=i.x;
k++;
}
sort(p,p+k);
int i=1;
while(p[i].x==p[i-1].x&&i<k) i++;
if(i>=k){
cout<<"Tie";
}else{
if(i+1<k&&p[i+1].x==p[i].x){
cout<<"Tie";
}else{
cout<<p[i].y;
}
}
return 0;
}
版权声明
本文为[岁忧]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46028214/article/details/124319540
边栏推荐
- [binary search - medium] 540 A single element in an ordered array
- 冬天到了,给你的网站下个雪吧
- 返璞归真,多方安全计算要回归到“安全”的本源考虑
- 客户端邮件同步到webmail如何操作,电子邮件地址怎么注册?
- [binary search - simple] 278 First wrong version
- OpenHarmony3. 1 H264 video playback Road
- 使用konvajs三步实现一个小球游戏
- 【二分查找-简单】LCP 18. 早餐组合
- [binary search - simple] LCP 28 Procurement scheme
- SQL performance optimization and performance test
猜你喜欢

Introduction to openlayers (II)

数据库基础知识详解五:MySQL中的索引和其两种引擎、主从复制以及关系型/非关系型数据库

Huawei power PON distribution network solution

企业邮箱如何申请?如何用手机号注册邮箱?

机器学习方法创建可学习的化学语法,构建可合成的单体和聚合物

客户端邮件同步到webmail如何操作,电子邮件地址怎么注册?

产业园区数字孪生规划方案

SAP UI5 應用開發教程之七十 - 如何使用按鈕控件觸發頁面路由跳轉試讀版

Installation and uninstallation of MySQL

什么是电子邮件的格式?企业邮箱地址是什么?
随机推荐
干货 | 录制你的第一个web 自动化测试用例
SAP ui5 application development tutorial 70 - how to use button controls to trigger page routing jump trial version
Introduction to openlayers (I)
EL&JSTL
[binary search - simple] 367 Effective complete square
【二分搜索-中等】剑指 Offer II 070. 排序数组中只出现一次的数字
How to synchronize client email to webmail and how to register email address?
【二分查找-简单】LCP 18. 早餐组合
51页数字转型与“十四五”信息化规划
OpenHarmony3.1 H264视频播放之路
Dry goods | record your first web automation test case
Page 92 group informatization planning scheme enterprise application integration solution
终极套娃 2.0|云原生 PaaS 平台的可观测性实践分享
On the import and export of browser bookmarks
OpenHarmony相机用户态驱动框架
Dry goods | environmental problems or chronic difficulties in testing? It's easy to do it in two steps
外贸公司一般用什么邮箱,电子邮件如何群发?
SAP ui5 application development tutorial 70 - how to trigger page route jump using button control
Introduction to openlayers (II)
使用konvajs三步实现一个小球游戏