每日刷题(2024年8月9日)

Problem - 2A - Codeforces

wa1

没有搞懂c++的pair的排序规则,之前tmd记错了,是先first,在second

wa2

没有弄清楚,题目需求(最后都是m分的玩家(m分为max),最先出现,大于等于m分的玩家)

todolist

1.最后为m分的玩家

2.最先出现大于等于m分的玩家 && 玩家最后得分为m(最大分数)

wa3

运用一下代码判断是否为m分玩家,导致没有输出

cpp 复制代码
while(i && sb[i].y == ans) isname[sb[i].x] = 1;

AC

cpp 复制代码
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc u << 1
#define rc u << 1 | 1

void solve();

const int N = 1e6 + 10;


signed main() {
    IOS;
    ll t = 1;
//    cin >> t;
    while (t--)
        solve();
    return 0;
}

bool cmp(pair<string,ll> a,pair<string,ll> b)
{
    return a.y < b.y;
}

void solve() {
    map<string,ll> mp,zan_mp;
    string s;
    ll n,score;
    cin >> n;
    vector<pair<string,ll>> zan;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> s >> score;
        zan.ps({s,score});
        mp[s] += score;
    }
    vector<pair<string,ll>> sb;
    for(auto [s,scorex]:mp)
    {
        sb.ps({s,scorex});
    }
    sort(all(sb),cmp);
//    for(int i = 0; i < sb.size(); ++ i) cout << i << ": " << sb[i].y << endl;
    ll f = sb.size() - 1;
    ll ans = sb[f].y;
    string anss;
    map<string,bool> isname;
    int i = f;
    for(int i = sb.size() - 1; i >= 0; -- i)
    {
        if(sb[i].y == ans)
            isname[sb[i].x] = 1;
        else break;
    }
    for(auto [s,scorex] : zan)
    {
        zan_mp[s] += scorex;
        if(zan_mp[s] >= ans && isname[s])
        {
            anss = s;break;
        }
    }
    cout << anss << endl;
}
相关推荐
小葡萄202537 分钟前
黑马程序员C++2024新版笔记 第三章 数组
笔记·算法·c++20
勇闯逆流河7 小时前
【数据结构】堆
c语言·数据结构·算法
pystraf8 小时前
LG P9844 [ICPC 2021 Nanjing R] Paimon Segment Tree Solution
数据结构·c++·算法·线段树·洛谷
飞川撸码8 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang
yuhao__z9 小时前
代码随想录算法训练营第六十六天| 图论11—卡码网97. 小明逛公园,127. 骑士的攻击
算法
Echo``9 小时前
3:OpenCV—视频播放
图像处理·人工智能·opencv·算法·机器学习·视觉检测·音视频
Nobkins9 小时前
2021ICPC四川省赛个人补题ABDHKLM
开发语言·数据结构·c++·算法·图论
88号技师9 小时前
2025年6月一区SCI-不实野燕麦优化算法Animated Oat Optimization-附Matlab免费代码
开发语言·算法·matlab·优化算法
ysy164806723910 小时前
03算法学习_977、有序数组的平方
学习·算法
codists11 小时前
《算法导论(第4版)》阅读笔记:p83-p85
算法