Educational Codeforces Round 141:C. Yet Another Tournament
一、来源:Problem - C - Codeforces
二、题面

三、思路
读题:
- 其他人的胜场由位次决定,对于第i位,其胜场为i-1
- 人数为\(5·10^5\),不是5(看错了)
- 每个人和自己比较时,可能输可能赢,故其他人最终的胜场是i或i+1
迭代的思想:(二维不相关)本人最一开始的思路是自下而上遍历先决定胜场,再直接决定名次;(二维相关)事实上胜场与名次两者是无法割裂的,故我们每次和一个人比较,看看能不能打赢他,进而决定能不能到相同的名次
n-i+1集合的划分:(需要看到的是能否打赢第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的更多相关文章
- Educational Codeforces Round 141 解题报告
Educational Codeforces Round 141 解题报告 \(\text{By DaiRuiChen007}\) \(\text{Contest Link}\) A. Make it ...
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
- Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压
题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...
- 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 :否则 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [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 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- 26岁的超经典音乐播放器Winamp归来!UI彻底重构:支持iOS/安卓
快科技4月18日讯,还记得Winamp吗? 这款1997年首发的媒体播放器,已经走过了26年的历史.它凭借高度简洁.大量的皮肤.丰富的定制性.多元的格式支持等成为有史以来最好的音乐播放器之一. 当年的 ...
- PostgreSQL-可以通过localhost连接,无法通过IP地址连接。
(1)如果PostgreSQL配置文件中没有允许访问该服务器的IP地址,则需要先添加允许访问的IP地址,并在防火墙中开放相应的端口.(2)在PostgreSQL配置文件postgresql.conf中 ...
- Linux离线安装MySQL(5.7.22)
1.下载tar包 (1)Window PC下载(PC需要联网) MySQL官网地址:https://www.mysql.com/ MySQL社区版下载地址: https://dev.mysql.com ...
- LLM研究之-NVIDIA的CUDA
一.什么是NVIDIA的CUDA CUDA(Compute Unified Device Architecture)是由NVIDIA公司开发的一个并行计算平台和应用程序编程接口(API),它允许软件开 ...
- FUN GAME 一款普通的C++游戏
凑合看吧,不是完整版. #include<bits/stdc++.h> #include<windows.h> #include<conio.h> using na ...
- NC20284 [SCOI2011]糖果
题目链接 题目 题目描述 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比他 ...
- 【framework】InputChannel创建流程
1 前言 IMS启动流程 中介绍了 IMS 在 Java 层和 Native 层的初始化流程,以及创建 NativeInputManager.InputManager.InputReader.Inpu ...
- postgresql常见开发技巧
1.数据类型 名字 描述 bigint 有符号 8 字节整数 bigserial 自增八字节整数 bit [ (n) ] 定长位串 bit varying [ (n) ] 变长位串 boolean 逻 ...
- 启动MySQL5.7服务无法启动或Table 'mysql.plugin' doesn't exist
首先说一下我这个是mysql5.7.16免安装版,不过这个问题对于5.7版本应该都适用. 问题重现: 安装过程也说一下吧: 1.将下载的压缩文件解压到指定目录, 我的是:E:\program\ ...
- win32 - 在进程之间获取事件通知(CreateEvent)
只需要记住使用OpenEvent来同步Event对象. Project A: #define _CRT_SECURE_NO_WARNINGS #include <Windows.h> #i ...