题目描述

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的更多相关文章

  1. 贪心/构造/DP 杂题选做Ⅱ

    由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...

  2. 【caffe】三种文件类别:solver,model和weights

    @tags: caffe 文件类别 solver文件 是一堆超参数,比如迭代次数,是否用GPU,多少次迭代暂存一次训练所得参数,动量项,权重衰减(即正则化参数),基本的learning rate,多少 ...

  3. 【BZOJ-4690】Never Wait For Weights 带权并查集

    4690: Never Wait for Weights Time Limit: 15 Sec  Memory Limit: 256 MBSubmit: 88  Solved: 41[Submit][ ...

  4. [codeforces 339]C. Xenia and Weights

    [codeforces 339]C. Xenia and Weights 试题描述 Xenia has a set of weights and pan scales. Each weight has ...

  5. Xenia and Weights(深度优先搜索)

    Xenia and Weights time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. 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. 出现这个错误,但是我记得昨天还好好的, ...

  7. 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 ...

  8. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

  9. Nested weights are bad for performance

    警告信息“Nested weights are bad for performance”的消除方法 原因分析:在布局进行嵌套使用时,父布局与子布局都使用了android:layout_weight,但 ...

  10. Why Everyone Should Lift Weights

    Why Everyone Should Lift Weights by James Clear I'll say it plain and simple: you should be lifting ...

随机推荐

  1. 《Linux基础》09. Shell 编程

    @ 目录 1:Shell 简介 2:Shell 脚本 2.1:规则与语法 2.2:执行方式 2.3:第一个 Shell 脚本 3:变量 3.1:系统变量 3.2:用户自定义变量 3.2.1:规则 3. ...

  2. [EasyExcel] 导出合并单元格

    前言 使用spring boot 对excel 进行操作在平时项目中要经常使用.常见通过jxl和poi 的方式进行操作.但他们都存在一个严重的问题就是非常的耗内存.这里介绍一种 Easy Excel ...

  3. 1-MySQL数据库的安装和基础语法介绍

    1.MySQL是什么? MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品.它是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最 ...

  4. PLC通过Modbus转Profinet网关与合康变频器Modbus通讯案例

    PLC通过Modbus转Profinet网关(XD-MDPN100)与合康变频器Modbus通讯,实现了两个设备之间的数据交互.Profinet是一种基于以太网的实时工控网络协议,而Modbus是一种 ...

  5. 深入理解RocketMQ 广播消费

    这篇文章我们聊聊广播消费,因为广播消费在某些场景下真的有奇效.笔者会从基础概念.实现机制.实战案例.注意事项四个方面一一展开,希望能帮助到大家. 1 基础概念 RocketMQ 支持两种消息模式:集群 ...

  6. 2023.09.29 入门级 J2 模拟赛 赛后总结(尝试第一篇总结)

    T1:变换(change) 一道大水题. 赛场上想都没想就切掉了 不难发现,转换的过程只和a 和b 的二进制位有关,且不同二进制位之间无关.我们可以将a 和b 转化为二进制表示,每一位分别判断,如果这 ...

  7. Langchain-Chatchat项目:1-整体介绍

      基于Langchain与ChatGLM等语言模型的本地知识库问答应用实现.项目中默认LLM模型改为THUDM/chatglm2-6b[2],默认Embedding模型改为moka-ai/m3e-b ...

  8. Insert a scratch project into a ppt (MSPowerPoinT file)在powerpoint中播放Scratch动画

    Insert a scratch project into a ppt (MSPowerPoinT file)在powerpoint中播放Scratch动画 Contributed by liu pe ...

  9. ELK+ filebeat

    ELK 企业级日志分析系统 ELK 概述 1.ELK 简介 ELK平台是一套完整的日志集中处理解决方案,将 ElasticSearch.Logstash 和 Kiabana 三个开源工具配合使用, 完 ...

  10. Little Victor and Set 题解

    Little Victor and Set 题目大意 在 \([l,r]\) 中选不超过 \(k\) 个相异的数使得异或和最小,输出方案. 思路分析 分类讨论: 当 \(k=1\) 时: 显然选 \( ...