当前位置:网站首页>A. Doremy‘s IQ-- Codeforces Round #808 (Div. 1)
A. Doremy‘s IQ-- Codeforces Round #808 (Div. 1)
2022-08-01 22:42:00 【秦小咩】
A. Doremy's IQ
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Doremy is asked to test nn contests. Contest ii can only be tested on day ii. The difficulty of contest ii is aiai. Initially, Doremy's IQ is qq. On day ii Doremy will choose whether to test contest ii or not. She can only test a contest if her current IQ is strictly greater than 00.
If Doremy chooses to test contest ii on day ii, the following happens:
- if ai>qai>q, Doremy will feel she is not wise enough, so qq decreases by 11;
- otherwise, nothing changes.
If she chooses not to test a contest, nothing changes.
Doremy wants to test as many contests as possible. Please give Doremy a solution.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. The description of the test cases follows.
The first line contains two integers nn and qq (1≤n≤1051≤n≤105, 1≤q≤1091≤q≤109) — the number of contests and Doremy's IQ in the beginning.
The second line contains nn integers a1,a2,⋯,ana1,a2,⋯,an (1≤ai≤1091≤ai≤109) — the difficulty of each contest.
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
Output
For each test case, you need to output a binary string ss, where si=1si=1 if Doremy should choose to test contest ii, and si=0si=0 otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less.
If there are multiple solutions, you may output any.
Example
input
Copy
5 1 1 1 2 1 1 2 3 1 1 2 1 4 2 1 4 3 1 5 2 5 1 2 4 3
output
Copy
1 11 110 1110 01111
Note
In the first test case, Doremy tests the only contest. Her IQ doesn't decrease.
In the second test case, Doremy tests both contests. Her IQ decreases by 11 after testing contest 22.
In the third test case, Doremy tests contest 11 and 22. Her IQ decreases to 00 after testing contest 22, so she can't test contest 33.
=========================================================================
贪心
正确性证明 设 1..2.....pos .....................n 设我们在pos,位置遇到一个大于当前p的,如果我们执行了减1操作,今后再也遇不见大于p的话,没有什么影响。然而一旦遇见一个pos1大于当前p
1..2.....pos ........pos1.............n
pos1+1----n之间,无论我们执行pos,还是pos1,所得结果都是一样的,因为p都变成了p-1
而pos-pos1之间,如果我们先执行了pos,操作,那么显然不如执行pos1操作更优
所以我们要尽可能的吧-1操作留在末尾,取p能够满足最长的末尾段,全部涂上1,之前的在p之内的再涂上1.
用二分比较容易理解,网上普遍做法是二分的逆,也就是从最末尾往前推连续一段,设p最初为0,遇见比p大的就加1,一直加到p=p0即可。其实这里的p没有任何实际意义,更多的是一种数学表示,是抽象出来的一个数。按照这样我们推导p=p0时,p就完全覆盖了后面的这一段。很多题解说p就是当前p,其实并不准确
例如
p0=5
序列为 5 4 3 2 1 p从0一直变到5,并不代表我们p0的变化,即p仅仅是一个没有意义抽象出来的概念。
#include <bits/stdc++.h>
using namespace std;
int a[100000+10];
bool book[100000+10];
int main()
{
int t;
cin>>t;
while(t--)
{
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a[i];
book[i]=0;
}
int num=0;
for(int i=n;i>=1;i--)
{
if(num<a[i])
{
if(num+1<=q)
{
num++;
book[i]=1;
}
}
else
{
book[i]=1;
}
}
for(int i=1;i<=n;i++)
{
cout<<book[i];
}
cout<<endl;
}
return 0;
}
边栏推荐
- Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
- 隔离和降级
- Advanced Algebra_Proof_The algebraic multiplicity of any eigenvalue of a matrix is greater than or equal to its geometric multiplicity
- 从0到1:图文投票小程序设计与研发笔记
- APP专项测试:流量测试
- JS prototype hasOwnProperty in 加方法 原型终点 继承 重写父类方法
- 华为无线设备配置全局双链路冷备份(AC全局配置方式)
- From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
- vscode hide menu bar
- 基于 OData 模型和 JSON 模型的 SAP UI5 表格控件行项目的添加和删除实现
猜你喜欢

【数据分析03】

2022 edition of MySQL tutorial, top collection good, take your time

Postman batch test interface detailed tutorial

数据增强--学习笔记(图像类,cnn)

下载安装 vscode(含汉化、插件的推荐和安装)

Use Jenkins for continuous integration, this knowledge point must be mastered

华为无线设备配置全局双链路冷备份(AC全局配置方式)

Deep Learning Course2 Week 2 Optimization Algorithms Exercises

xctf攻防世界 Web高手进阶区 web2

xctf攻防世界 Web高手进阶区 webshell
随机推荐
杭电多校3 1012. Two Permutations dp*
图论——强连通分量缩点+拓扑排序
[ASM] Bytecode Operation MethodWriter
xss相关知识点以及从 XSS Payload 学习浏览器解码
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D 题解
如何使用pywinauto和pyautogui将动漫小姐姐链接请回家
美赞臣EDI 940仓库装运订单详解
JS prototype hasOwnProperty in Add method Prototype end point Inherit Override parent class method
Error creating bean with name ‘dataSource‘:Unsatisfied dependency expressed through field ‘basicPro
Wechat Gymnasium Reservation Mini Program Graduation Design Finished Work Mini Program Graduation Design Finished Product (2) Mini Program Function
selenium无头,防检测
excel vertical to horizontal
论文解读(GSAT)《Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism》
PAM 回文自动机
Advanced Algebra_Proof_The algebraic multiplicity of any eigenvalue of a matrix is greater than or equal to its geometric multiplicity
1391D. 505 状压dp
Interpretation of the paper (GSAT) "Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism"
How to prevent governance attacks in DAOs?
When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
如何给 UE4 场景添加游戏角色