[CF1599A] Weights
题目描述
You are given an array $ A $ of length $ N $ weights of masses $ A_1 $ , $ A_2 $ ... $ A_N $ . No two weights have the same mass. You can put every weight on one side of the balance (left or right). You don't have to put weights in order $ A_1 $ ,..., $ A_N $ . There is also a string $ S $ consisting of characters "L" and "R", meaning that after putting the $ i-th $ weight (not $ A_i $ , but $ i-th $ weight of your choice) left or right side of the balance should be heavier. Find the order of putting the weights on the balance such that rules of string $ S $ are satisfied.
输入格式
The first line contains one integer $ N $ ( $ 1 \leq N \leq 2*10^5 $ ) - the length of the array $ A $ The second line contains $ N $ distinct integers: $ A_1 $ , $ A_2 $ ,..., $ A_N $ ( $ 1 \leq A_i \leq 10^9 $ ) - the weights given The third line contains string $ S $ of length $ N $ consisting only of letters "L" and "R" - string determining which side of the balance should be heavier after putting the $ i-th $ weight of your choice
输出格式
The output contains $ N $ lines. In every line, you should print one integer and one letter - integer representing the weight you are putting on the balance in that move and the letter representing the side of the balance where you are putting the weight. If there is no solution, print $ -1 $ .
由于样例没有 -1,所以大概率不存在无解情况。
神奇的,考虑把 \(a\) 排序后,对于所有 \(a_i\),将 \(i\) 为偶数的丢一堆, \(i\) 为奇数丢一堆。
具体哪堆丢左边哪堆丢右边看 \(S_n\),因为发现将其从大到小放时,一定是最后丢的那个所在的堆更大,可以用差分证明。
然后考虑把 \(n\) 的问题化为 \(n-1\) 的问题。正着不好做,反着做。发现此时如果拿掉最大的那个砝码所在的地方,天平情况一定会反转,如果拿掉最小的那个砝码,天平情况一定不变。就能从 \(n\) 变为 \(n-1\)。
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
const char g[]={'L','R'};
char s[N];
int a[N],n,l=1,r,p[N];
int read()
{
int s=0;
char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9')
s=s*10+ch-48,ch=getchar();
return s;
}
int main()
{
r=n=read();
for(int i=1;i<=n;i++)
a[i]=read();
sort(a+1,a+n+1);
scanf("%s",s+1);
for(int i=n;i^1;i--)
{
if(s[i]==s[i-1])
p[i]=l++;
else
p[i]=r--;
}
p[1]=l;
for(int i=1;i<=n;i++)
printf("%d %c\n",a[p[i]],g[(p[i]&1)^(s[n]=='R')^(n&1)]);
}
[CF1599A] Weights的更多相关文章
- 贪心/构造/DP 杂题选做Ⅱ
由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...
- 【caffe】三种文件类别:solver,model和weights
@tags: caffe 文件类别 solver文件 是一堆超参数,比如迭代次数,是否用GPU,多少次迭代暂存一次训练所得参数,动量项,权重衰减(即正则化参数),基本的learning rate,多少 ...
- 【BZOJ-4690】Never Wait For Weights 带权并查集
4690: Never Wait for Weights Time Limit: 15 Sec Memory Limit: 256 MBSubmit: 88 Solved: 41[Submit][ ...
- [codeforces 339]C. Xenia and Weights
[codeforces 339]C. Xenia and Weights 试题描述 Xenia has a set of weights and pan scales. Each weight has ...
- Xenia and Weights(深度优先搜索)
Xenia and Weights time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- caffe: test code 执行出问题: Check failed: FLAGS_weights.size() > 0 (0 vs. 0) Need model weights to score.
Check failed: FLAGS_weights.size() > 0 (0 vs. 0) Need model weights to score. 出现这个错误,但是我记得昨天还好好的, ...
- UVa 10154 - Weights and Measures
UVa 10154 - Weights and Measures I know, up on top you are seeing great sights, But down at the bot ...
- codeforces 339C Xenia and Weights(dp或暴搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Weights Xenia has a set of weig ...
- Nested weights are bad for performance
警告信息“Nested weights are bad for performance”的消除方法 原因分析:在布局进行嵌套使用时,父布局与子布局都使用了android:layout_weight,但 ...
- Why Everyone Should Lift Weights
Why Everyone Should Lift Weights by James Clear I'll say it plain and simple: you should be lifting ...
随机推荐
- 三维模型OSGB格式轻量化顶点压缩主要技术方法分析
三维模型OSGB格式轻量化顶点压缩主要技术方法分析 在三维模型应用中,轻量化处理是提高数据传输效率.减少渲染时间和优化用户体验的重要手段.而OSGB格式是一种常见的三维模型格式,在进行轻量化处理时,顶 ...
- js调起android安卓与ios苹果方法 vue3.0 + ts
let shareSelect = (ev :any) => { const u :any= navigator.userAgent; const win :any = window const ...
- Java开发面试--nacos专区
1. Nacos是什么? 请简要介绍Nacos是什么以及它的主要功能和用途. 答: 简介: Nacos是一个开源的.高性能.动态服务发现.配置和服务管理平台,通常用于微服务架构中.Nacos的名称来源 ...
- 为不断增长的Go生态系统扩展gopls
原文在这里. 由 Robert Findley and Alan Donovan 发布于 2023年9月8日 今年夏天初,Go团队发布了gopls的v0.12版本,这是Go语言的语言服务器,它进行了核 ...
- 【krpano】KRPano自动缩略图分组插件
该插件可以展示场景缩略图,并支持场景分组. 下载地址:http://pan.baidu.com/s/1dFj7v0l 使用说明: 插件共有两个文件,auto_thumbs.xml和tooltip.xm ...
- 使用docker搭建seafile服务器
工作需要在单位和家里的不同电脑上同步指定文件夹及其内容.对比了一些解决方案,最终还是选择熟悉的seafile来做. 需要按照官方文档进行seafile的安装,选择官方推荐的docker方式快速部署. ...
- Gitbook Android App
最有用Ionic 2 做了一个Gitbook 混合app, 上线google play的时候提醒我触犯了假冒行为,可能是logo和名字问题吧,放弃: 上线腾讯被认为是h5 app,不是native a ...
- 什么是 x10 开发工具?「GitHub 热点速览」
都听过 10x 工程师,一个人顶得过十个人.但是并不是每个人都是 10x 工程师,但是有些效率工具可能让你变成 2x.3x 的工程师.比如,这周火爆的 3D 游戏引擎 FlaxEngine 有着强大的 ...
- Python的23种设计模式
文章目录 Python与设计模式--前言 一 什么是设计模式 二 为什么要有设计模式 三 有那些设计模式 创建类设计模式(5种) 结构类设计模式(7种) 行为类设计模式(11种) 四 设计模式与架构, ...
- Java流程控制10道题_上机
Java流程控制10道题 计算出1-100之间所有不能被3整除的整数的和大于(或等于)2000的数字. package day01; public class Lab01 { public stati ...