每日刷题(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;
}
相关推荐
程序员-King.1 小时前
day158—回溯—全排列(LeetCode-46)
算法·leetcode·深度优先·回溯·递归
月挽清风2 小时前
代码随想录第七天:
数据结构·c++·算法
小O的算法实验室2 小时前
2026年AEI SCI1区TOP,基于改进 IRRT*-D* 算法的森林火灾救援场景下直升机轨迹规划,深度解析+性能实测
算法·论文复现·智能算法·智能算法改进
小郭团队3 小时前
2_1_七段式SVPWM (经典算法)算法理论与 MATLAB 实现详解
嵌入式硬件·算法·硬件架构·arm·dsp开发
充值修改昵称3 小时前
数据结构基础:从二叉树到多叉树数据结构进阶
数据结构·python·算法
Deepoch3 小时前
Deepoc数学大模型:发动机行业的算法引擎
人工智能·算法·机器人·发动机·deepoc·发动机行业
浅念-4 小时前
C语言小知识——指针(3)
c语言·开发语言·c++·经验分享·笔记·学习·算法
Hcoco_me4 小时前
大模型面试题84:是否了解 OpenAI 提出的Clip,它和SigLip有什么区别?为什么SigLip效果更好?
人工智能·算法·机器学习·chatgpt·机器人
BHXDML4 小时前
第九章:EM 算法
人工智能·算法·机器学习
却道天凉_好个秋5 小时前
目标检测算法与原理(三):PyTorch实现迁移学习
pytorch·算法·目标检测