题目描述

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. 1、Spring简介

    1.1.概述 Spring 是轻量级的框架,其基础版本只有 2 MB 左右的大小. Spring 框架是一个开源的 Java 平台,它最初是由 Rod Johnson 编写的,并且于 2003 年 6 ...

  2. 【Windows】KMS 激活命令记录

    目录 KMS 服务器激活 Office.Visio 推荐使用 office tool plus 部署并配置 KMS 激活 什么是 KMS? KMS 正版与否的区别 总结 KMS 服务器激活 利用 KM ...

  3. Excel中的数值四舍五入方法详解

    在日常工作和数据处理中,我们经常需要对数值进行四舍五入操作.Excel作为一款强大的电子表格软件,提供了多种方法来实现数值的四舍五入.本文将介绍Excel中常用的四舍五入函数及其基本使用方法. ROU ...

  4. C# 异步执行操作

    为了方便测试异步,先加个计时 计时相关(可以直接跳过该部分) //开始计时 Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 停 ...

  5. QA|4个数据打开了4个页面,怎么实现只打开一个页面?单例模式|网页计算器自动化测试实战

    如下图,代码中4个数据,产生了4个页面,怎么实现只打开一个页面?可使用单例模式 查询得知 单例模式实现有5种方法,参照链接下: https://blog.csdn.net/SixStar_FL/art ...

  6. Nomad 系列-快速上手

    系列文章 Nomad 系列文章 Nomad 重要术语 Nomad 安装设置相关术语 agent - 代理.Agent 是在 Server(服务器) 或 Client(客户端) 模式下运行的 Nomad ...

  7. MySQL 表分区使用实践

    在使用 MySQL 8.0 表分区时,需要注意以下一些关键事项和最佳实践: 支持的存储引擎: MySQL 8.0 表分区仅支持一些特定的存储引擎,如 InnoDB 和 NDB(NDB 是 MySQL ...

  8. ClickHouse(15)ClickHouse合并树MergeTree家族表引擎之GraphiteMergeTree详细解析

    GraphiteMergeTree该引擎用来对Graphite数据(图数据)进行瘦身及汇总.对于想使用ClickHouse来存储Graphite数据的开发者来说可能有用. 如果不需要对Graphite ...

  9. IDEA工具第一篇:细节使用-习惯设置

    安装好Idea后,直接上手clone代码进入编码时代,有没有那么一刻你会觉用起来没有那么顺手流畅呢? 下面是关于 [Windows] 下安装idea的一些习惯设置[ Mac大致一样 ] 一.修改系统文 ...

  10. 归并排序 nO(lgn) 审核中

    大家好,我是蓝胖子,我一直相信编程是一门实践性的技术,其中算法也不例外,初学者可能往往对它可望而不可及,觉得很难,学了又忘,忘其实是由于没有真正搞懂算法的应用场景,所以我准备出一个系列,囊括我们在日常 ...