每日刷题(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;
}
相关推荐
梭七y12 分钟前
【力扣hot100题】(105)三数之和
数据结构·算法·leetcode
WhereIsMyChair2 小时前
DPO 核心损失函数β调大可以控制不偏离ref模型太远
人工智能·算法·机器学习
智者知已应修善业2 小时前
【组合数】2024-3-16
c语言·c++·经验分享·笔记·算法
l1t3 小时前
将利用30行X算法求解数独的python程序转成DuckDB自定义函数并比较性能
数据库·python·算法·duckdb
花间流风3 小时前
【王阳明代数讲义】2025年CSDN花间流风博文技术汇总
算法·年终总结·模型·情感分析·王阳明代数
DuHz3 小时前
亚毫米波FMCW脉冲多普勒雷达:粒子云动态特性表征技术深度解析
论文阅读·物联网·算法·信息与通信·毫米波雷达
hz_zhangrl3 小时前
CCF-GESP 等级考试 2025年12月认证C++二级真题解析
c++·算法·gesp·gesp2025年12月·c++二级
量子炒饭大师4 小时前
Cyber骇客的层级霸权——【优化算法】之【排序算法】堆排序
c语言·c++·算法·排序算法
cpp_25014 小时前
P8597 [蓝桥杯 2013 省 B] 翻硬币
数据结构·c++·算法·蓝桥杯·题解
前端小L4 小时前
双指针专题(四):像毛毛虫一样伸缩——「长度最小的子数组」
javascript·算法·双指针与滑动窗口