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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- C#/.NET/.NET Core优秀项目和框架2024年1月简报
前言 公众号每月定期推广和分享的C#/.NET/.NET Core优秀项目和框架(每周至少会推荐两个优秀的项目和框架当然节假日除外),公众号推文中有项目和框架的介绍.功能特点.使用方式以及部分功能截图 ...
- 制作包含最新更新的Windows 10 LTSC 2021 ISO
介绍 在制作桌面云windows 模板的时候,一般需要安装最新的更新.更新安装过程非常耗时,并且安装更新会导致桌面模板的磁盘空间膨胀.制作出的模板会占用很大的磁盘空间.如果不安装更新,模板大小约5G. ...
- Python脚本之批量复制文件并同时支持重命名
import os import shutil import time start_time = time.time() # 需要被复制的文件夹 old_path = r'C:\old_dir' ne ...
- Delphi-判断一个对象是否释放,改造官方的Assigned
直接上例子了,基础知识自己去了解,首先定义一个类: TPerson = class public name: string; age: Integer; constructor Create(name ...
- Mac上SnailSvn checkout报错
- 测试DHCP服务器
一:前期准备 1.准备三台虚拟机,不要配ip. 都改成仅主机模式,这样它们和DHCP才会相连 2.进入有DHCP服务器的虚拟机,更改虚拟网络编辑器 (编辑→虚拟网络编辑器(N)) 不勾选使用本地DHC ...
- Asp .Net Core 系列:Asp .Net Core 集成 NLog
简介 NLog是一个基于.NET平台编写的日志记录类库,它可以在应用程序中添加跟踪调试代码,以便在开发.测试和生产环境中对程序进行监控和故障排除.NLog具有简单.灵活和易于配置的特点,支持在任何一种 ...
- NC15065 小牛vs小客
题目链接 题目 题目描述 小牛和小客玩石子游戏,他们用n个石子围成一圈,小牛和小客分别从其中取石子,谁先取完谁胜,每次可以从一圈中取一个或者相邻两个,每次都是小牛先取,请输出胜利者的名字(小牛获胜输出 ...
- NC235247 Sramoc问题
题目链接 题目 题目描述 \(Sramoc(K ,M)\) 表示用数字 \(0,1,2,3,4,...,k-1\) 组成的自然数中能被M整除的最小数.给定 \(K,M\) \(2\leq K\leq ...
- ysoserial URLDNS利用链分析
在分析URLDNS之前,必须了解JAVA序列化和反序列化的基本概念.其中几个重要的概念: 需要让某个对象支持序列化机制,就必须让其类是可序列化,为了让某类可序列化的,该类就必须实现如下两个接口之一: ...