当前位置:网站首页>Codeforces Round #807 (Div 2.) AB
Codeforces Round #807 (Div 2.) AB
2022-07-17 04:21:00 【超级小何】
A

A. 标记摄影师每次测试的时间限制1 秒每次测试的内存限制为 256 MB输入标准输入输出标准输出马克被要求合影2n2n人。这我我-人身高h我hi单位。
为此,他命令这些人分成两排,前排和后排,每排由nn人。但是,为了确保正确看待每个人,jj-后排的第 个人必须至少xx单位高于jj-每人前排的第 0 个人jj之间11和nn包容。
帮助标记确定这是否可能。
输入第一行包含一个整数tt (1≤吨≤1001≤吨≤100) — 测试用例的数量。每个测试用例由两行组成。
每个测试用例的第一行包含两个正整数nn和xx (1≤n≤1001≤n≤100,1≤x≤1031≤x≤103) — 每行中的人数和 Mark 想要的最小差异。
每个测试用例的第二行包含2n2n正整数h1,h2,...,h2nh1,h2,...,h2n (1≤h我≤1031≤小时i≤103) — 每个人的身高(单位)。
请注意,总和nn在所有测试用例中都是无限制的。
输出对于每个测试用例,如果 Mark 可以安排满足其条件的人,请打印一行包含“YES”,否则打印“NO”。
您可以在任何情况下打印每个字母(例如,是,是,是的,是的,yE都将被识别为肯定的答案)。
例输入复制3 3 6 1 3 9 10 12 16 3 1 2 5 2 2 2 5 1 2 8 6输出复制YES NO YES注意在第一个测试用例中,一个可能的顺序是将第三、第五和第六人放在后排,第二、第一和第四人放在前排。人们的高度会是这样的。
返回 99 1212 1616 前面 33 11 1010 它的工作原理是因为
- h3−h2=9−3≥6h3−h2=9−3≥6,
- h5−h1=12−1≥6h5−h1=12−1≥6和
- h6−h4=16−10≥6h6−h4=16−10≥6.
在第二个测试用例中,可以证明没有办法以满足条件的方式对人员进行排序。
在第三个测试用例中,安排人们满足条件的唯一方法是让第一个人在后排,第二个人在前排。
#include<bits/stdc++.h>
using namespace std;
int main(){
int _;
cin>>_;
int a[1001],b[1001],c[1001];
while(_--){
bool ok = true;
int n,x;
cin>>n>>x;
for(int i = 1;i<=2*n;i++) cin>>a[i];
sort(a+1,a+1+2*n);
for(int i = 1;i<=n;i++){
b[i]=a[i];
}
int j = 1;
for(int i = n+1;i<=2*n;i++){
c[j]=a[i];
j++;
}
for(int i = 1;i<=n;i++){
if(c[i]-b[i]<x){
ok = false;
}
}
if(ok){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
return 0;
}
B

B. 标记扫尘器每次测试的时间限制为1.5秒每次测试的内存限制为 256 MB输入标准输入输出标准输出马克正在打扫一排nn房间。这我我- 房间有一个非负尘位一个我ai.他有一台神奇的清洗机,可以做以下三步操作。
马克的目标是让一个1=一个2=...=一个n−1=0a1=a2=...=an−1=0这样他就可以很好地扫除nn- 房间。确定实现目标所需的最小操作数。
- 选择两个指数i<ji<j使得粉尘水平一个我ai,一个i+1i+1,......,一个j−1aj−1都严格大于00.
- 设置一个我ai自一个我−1ai−1.
- 设置一个jaj自一个j+1aj+1.
输入第一行包含单个整数tt (1≤吨≤1041≤t≤104) — 测试用例的数量。
每个测试用例的第一行包含单个整数nn (2≤n≤2⋅1052≤n≤2⋅105) — 房间数。
每个测试用例的第二行包含nn整数一个1a1,一个2a2, ...,一个nan (0≤一个我≤1090≤ai≤109) — 每个房间的灰尘水平。
保证nn在所有测试用例中不超过2⋅1052⋅105.
输出对于每个测试用例,打印一行包含单个整数 ( 最小操作数)。可以证明有一系列操作符合目标。
例输入复制4 3 2 0 0 5 0 2 0 2 0 6 2 0 3 0 4 6 4 0 0 0 10输出复制3 5 11 0注意在第一种情况下,一个可能的操作序列如下所示。
此时,一个1=一个2=0a1=a2=0,完成该过程。
- 选择i=1i=1和j=2j=2,生成数组[1,1,0][1,1,0].
- 选择i=1i=1和j=3j=3,生成数组[0,1,1][0,1,1].
- 选择i=2i=2和j=3j=3,生成数组[0,0,2][0,0,2].
在第二种情况下,一个可能的操作序列如下所示。
- 选择i=4i=4和j=5j=5,生成数组[0,2,0,1,1][0,2,0,1,1].
- 选择i=2i=2和j=3j=3,生成数组[0,1,1,1,1][0,1,1,1,1].
- 选择i=2i=2和j=5j=5,生成数组[0,0,1,1,2][0,0,1,1,2].
- 选择i=3i=3和j=5j=5,生成数组[0,0,0,1,3][0,0,0,1,3].
- 选择i=4i=4和j=5j=5,生成数组[0,0,0,0,4][0,0,0,0,4].
在最后一种情况下,数组已经满足条件。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void ok(){
int n; cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++)
cin >> a[i];
ll ans = 0;
int pos = 0;
while(pos < n && a[pos] == 0)
pos++;
for(int i = pos; i < n-1; ++i){
ans += a[i];
if(a[i] == 0) ans++;
}
cout << ans << endl;
}
int main(){
int t; cin >> t;
while(t--) ok();
}
边栏推荐
- 51单片机一究到底输入模式
- T+0变T+1!快赎金额降至1万!又有银行调整现金理财产品申赎规则
- surging作者出具压测结果
- Apache22与opencms9.5集成配置
- About the problem of database, the concept of uniqueness and non repetition
- VB.NET插件开发- 提取文件
- kettle5.4问题记录
- Structure gets the address of the main structure (struct) through member variables
- C # explain out output parameters in detail
- C语言基础犄角旮旯的知识之数据类型
猜你喜欢

成熟的线程要懂得拒绝

Touchid and faceid~2

T + 0 to t + 1! The quick redemption amount is reduced to 10000! Another bank adjusted the rules for the application and redemption of cash wealth management products

Optimization and configuration of OSPF

Intel experts share: how to program efficiently on XPU architecture? Zhiqiang Research Institute

CAD video course recommendation station B

C# List 集合对象去重 Linq去重 带时间去重

Wechat e-book reading of small program graduation design (5) task book

Smart fan system based on STM32F103

Wechat e-book reading of applet completion works (7) Interim inspection report
随机推荐
【微信小程序】超易懂的条件渲染和列表渲染
Simple explanation of C constructors
微信附近的人小程序怎么开(开通附近小程序的方法)
leetcode977. 有序数组的平方
PowerDesigner显示Comment注释
Common methods of C string
donet framework4. X==windows form application new project, through system Data. SqlClient connects to sqlserver to query
WPF cannot find resource file problem
Week 2022/7/16
Simulation Implementation of library function
Swift 【Class】【struct】
High performance and economy: aoteng persistent memory helps mobile cloud cope with severe memory challenges
Wechat e-book reading of small program graduation design (5) task book
Apache22与opencms9.5集成配置
JS模态框
Cabasicanimation pause \ enterprise action
Xdc 2022 Intel technology special session: Intel Software and hardware technology builds the cornerstone of cloud computing architecture
LeetCode-移除元素
V4L2学习资料收集
Niuke 2021 training League warm-up training match interstellar love (and search Collection)