一、来源:Problem - C - Codeforces

二、题面

三、思路

  1. 读题:

    • 其他人的胜场由位次决定,对于第i位,其胜场为i-1
    • 人数为\(5·10^5\),不是5(看错了)
    • 每个人和自己比较时,可能输可能赢,故其他人最终的胜场是i或i+1
  2. 迭代的思想:(二维不相关)本人最一开始的思路是自下而上遍历先决定胜场,再直接决定名次;(二维相关)事实上胜场与名次两者是无法割裂的,故我们每次和一个人比较,看看能不能打赢他,进而决定能不能到相同的名次n-i+1

  3. 集合的划分:(需要看到的是能否打赢第i位和到n-i+1位次需要的胜场是两个维度的划分)

    • 初次划分

    • 优化

四、代码

#include <bits/stdc++.h>
typedef long long ll; using namespace std; const int N=5e5+10; //经典错误,只看到5,没看到5*10^5 //考虑胜场与赢谁的关系:若两者之间没有关系,可以先后求;若两者直接有关系需要考虑变换进而一起求(两个思维的区别很重要) int arr[N],b[N],pre[N]; int main(){
int t;
cin >> t;
while(t--){
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++){
cin >> arr[i];
b[i]=arr[i]; //用于之后排序
}
sort(b+1,b+1+n);
pre[0]=0;
for(int i=1;i<=n;i++){
pre[i]=b[i]+pre[i-1];
//cout << "pre[" << i << "]=" << pre[i] << endl;
}
int ans=m>=b[1]?n:n+1; //这里不是m>=arr[1],因为第一个人只赢了0场
//以i=1为下标,若赢当前位,共胜i-1场可以到达同位置;若不赢当前位,胜i场可以到达同位置
for(int i=2;i<=n;i++){
//cout << "i:" << i << " arr[i]+pre[i-1]:" << arr[i]+pre[i-1] << " pre[i]" << pre[i] << endl;
if(m>=arr[i]){ //能赢当前位
else if(arr[i]<=b[i-1]){ //pre[i-1]中已经包含arr[i]
if(m>=pre[i-1]){
ans=n+1-i;
}
}else{
if(m>=arr[i]+pre[i-2]){
ans=n+1-i;
}
}
}
}
cout << ans << endl;
}
return 0;
}

Educational Codeforces Round 141:C. Yet Another Tournament的更多相关文章

  1. Educational Codeforces Round 141 解题报告

    Educational Codeforces Round 141 解题报告 \(\text{By DaiRuiChen007}\) \(\text{Contest Link}\) A. Make it ...

  2. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  3. Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压

    题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...

  4. Educational Codeforces Round 141 (Rated for Div. 2) A-E

    比赛链接 A 题意 给一个数组 \(a\) ,要求重排列以后 \(a[i] \neq a[1,i-1]\) ,其中 \(a[1,i-1]\) 是前 \(i-1\) 项和. 如果无解则输出 NO :否则 ...

  5. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  6. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  7. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  8. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  9. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  10. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

随机推荐

  1. PyTorch下,使用list放置模块,导致计算设备不一的报错

    报错 在复现 Transformer 代码的训练阶段时,发生报错: RuntimeError: Expected all tensors to be on the same device, but f ...

  2. .NET Core开发实战(第21课:中间件:掌控请求处理过程的关键)--学习笔记(下)

    21 | 中间件:掌控请求处理过程的关键 如果在 Map 的时候逻辑复杂一点,不仅仅判断它的 URL 地址,而且要做特殊的判断的话,可以这么做把判断逻辑变成一个委托 我们要判断当我们的请求地址包含 a ...

  3. kafka-Kafka3.4版本创建topic出现zookeeper is not a recognized option

    问题描述:在linux云服务器上搭建了一套kafka3.0集群,然后按照以前的创建topic指令: ./kafka-topics.sh --zookeeper hadoop01:2181,hadoop ...

  4. 探索C语言的内存魔法:动态内存管理解析

    欢迎大家来到贝蒂大讲堂 养成好习惯,先赞后看哦~ 所属专栏:C语言学习 贝蒂的主页:Betty's blog 1. 静态开辟内存 通过前面的学习,我们已经掌握了两种开辟内存的方法,分别是: #incl ...

  5. 【LGR-153-Div.2】梦熊联盟 8 月月赛 Ⅳ & Cfz Round 1 & 飞熊杯 #1

    [LGR-153-Div.2]梦熊联盟 8 月月赛 Ⅳ & Cfz Round 1 & 飞熊杯 #1 \(T1\) luogu P9577 「Cfz Round 1」Dead Cell ...

  6. NC13224 送外卖

    题目链接 题目 题目描述 n 个小区排成一列,编号为从 0 到 n-1 .一开始,美团外卖员在第0号小区,目标为位于第 n-1 个小区的配送站. 给定两个整数数列 a[0]~a[n-1] 和 b[0] ...

  7. 介绍 ComPDFKit 转换 SDK 1.5.0

    介绍 ComPDFKit 转换 SDK 1.5.0 了解有关 ComPDFKit PDF SDK 的更多信息:https ://www.compdf.com/ ComPDFKit Conversion ...

  8. Mobx与Redux的异同

    Mobx与Redux的异同 Mobx与Redux都是用来管理JavaScript应用的状态的解决方案,用以提供在某个地方保存状态.修改状态和更新状态,使我们的应用在状态与组件上解耦,我们可以从一个地方 ...

  9. 配置主机访问virtualbox中redhat7.3虚拟机网络(其他系统配置也类似)

    为什么默认无法访问? virtualbox默认分配一个NAT网络,这个是给虚拟机操作系统访问互联网用的,默认主机通过这个ip段无法直接访问虚拟机.[网卡1] 需要添加一块网卡 在虚拟机关闭状态下,点[ ...

  10. Python之猜数字游戏

    说明: 本例改编自<Python编程快速上手>.例子很简单我就不多说了 直接上代码,给初学python练手用. 给你6次机会猜对一个预先生成好的1-20之间的整数.覆盖一下知识点: 条件语 ...