一、来源: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. SpringCloud-02-Nacos注册中心

    Nacos注册中心 1.认识Nacos Nacos是阿里巴巴的产品,现在是SpringCloud中的一个组件.相比Eureka功能更加丰富,在国内受欢迎程度较高. 2.安装Nacos 1 1.下载安装 ...

  2. OpenGL的模板缓冲

      注意看,利用OpenGL的模板缓冲,可以轻松实现很多酷炫的效果.当然,它用起来也很简单.下面就跟着博主小编,一起来看看吧! 模板缓冲的使用   假设有个大小为800x600的窗口,那么模板缓冲也是 ...

  3. TStringList的IndexOfName

    IndexOfName这个方法用着很好,记录下,以后留意下 上个例子: procedure TForm1.Button1Click(Sender: TObject); var MyList: TStr ...

  4. NC23047 华华给月月出题

    题目链接 题目 题目描述 华华刚刚帮月月完成了作业.为了展示自己的学习水平之高超,华华还给月月出了一道类似的题: \(Ans=\oplus_{i=1}^N(i^N\mod(10^9+7))\) \(\ ...

  5. 问题解决:Ubuntu18.04显示器分辨率不正常

    在Ubuntu18.04下出现显示器分辨率不正确的情况,只能选择1024x768的分辨率,没有其它选项,显示器本身可以支持1920x1080的分辨率.经查询,采用cvt, xrandr的方法不成功,显 ...

  6. nginx 基于IP的多虚拟主机配置

    1.基于IP的多虚拟主机配置 1.1 网络配置 linux操作系统支持IP别名的添加. nginx 服务器提供的每台虚拟主机对应配置一个不同的IP,因此需要将网卡设置为同时能够监听多个IP地址. 先查 ...

  7. Ubuntu下SSH管理及SFTP下载工具Muon(Snowflake)

    简介 Muon其实更像是一个基于ssh的服务器管理工具, 界面中有PAC Manager的影子, 集成了文件管理, ssh命令行, 服务器性能监测和工具包等功能. 因为这个工具的编写语言是Java, ...

  8. 【Android】使用Exoplayer播放视频

    1 前言 ​ ExoPlayer 是 google 开源的应用级媒体播放器,github源码 → https://github.com/google/ExoPlayer.相较于 MediaPlayer ...

  9. Python之读取Excel

    介绍 现在交给你一份2010年美国各州县人口普查表:censuspopdata.xlsx.共72864条记录. 每一行代表一个县某统计区的人口数. 需要你统计出:各县统计区数量和人口数. 表格内容长这 ...

  10. 【Android逆向】IDA动态调试JNI_OnLoad 和 .init_array

    由于 JNI_OnLoad 和 .init_array 执行时间很早,so一加载到内存中就执行了,所以动态调试步骤会稍微要麻烦一些 1. 进入手机, 执行./android_server (如果是64 ...