每日刷题(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;
}
相关推荐
埃菲尔铁塔_CV算法6 小时前
基于扩张卷积与双分支参数调控的低光照图像增强算法完整研究与工程解析
人工智能·神经网络·算法·机器学习·计算机视觉
迈巴赫车主6 小时前
优先队列(PriorityQueue)
数据结构·算法
hai3152475436 小时前
有规则的AI编制操作系统演进过程展示
人工智能·程序人生·算法·逻辑回归·创业创新
数据仓库搬砖人6 小时前
SHAP 详解:从博弈论原理到 XGBoost 实战
算法
老鱼说AI6 小时前
统计学习方法第七章:支持向量机精讲(超硬核长文深入预警!)
人工智能·深度学习·神经网络·算法·机器学习·支持向量机·学习方法
容器魔方6 小时前
KubeEdge SIG AI: 基于KubeEdge-Ianvs的大模型联邦微调算法
大数据·人工智能·算法·云原生·容器·云计算
列星随旋6 小时前
矩阵快速幂
java·算法·矩阵
z200509306 小时前
今日算法(回溯全排列)
c++·算法·leetcode
Boom_Shu6 小时前
构造函数程序
数据结构·算法
MicroTech20256 小时前
微算法科技(NASDAQ: MLGO)量子安全与区块链:量子神经网络QNN赋能动态共识与量子密钥分发
科技·算法·安全