每日刷题(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;
}
相关推荐
CoovallyAIHub19 分钟前
方案 | 动车底部零部件检测实时流水线检测算法改进
深度学习·算法·计算机视觉
CoovallyAIHub21 分钟前
方案 | 光伏清洁机器人系统详细技术实施方案
深度学习·算法·计算机视觉
lxmyzzs25 分钟前
【图像算法 - 14】精准识别路面墙体裂缝:基于YOLO12与OpenCV的实例分割智能检测实战(附完整代码)
人工智能·opencv·算法·计算机视觉·裂缝检测·yolo12
洋曼巴-young26 分钟前
240. 搜索二维矩阵 II
数据结构·算法·矩阵
楼田莉子2 小时前
C++算法题目分享:二叉搜索树相关的习题
数据结构·c++·学习·算法·leetcode·面试
pusue_the_sun2 小时前
数据结构——栈和队列oj练习
c语言·数据结构·算法··队列
大锦终3 小时前
【算法】模拟专题
c++·算法
Xの哲學3 小时前
Perf使用详解
linux·网络·网络协议·算法·架构
想不明白的过度思考者3 小时前
数据结构(排序篇)——七大排序算法奇幻之旅:从扑克牌到百亿数据的魔法整理术
数据结构·算法·排序算法
小七rrrrr3 小时前
动态规划法 - 53. 最大子数组和
java·算法·动态规划