CodeForces 1367D Task On The Board
题意
给一个字符串\(t\),和一个长度为\(m\)的数组\(b[]\),要求构造一个字符串\(s\),\(s\)中的字符都出现在\(t\)中,对于\(s[i]\)而言,对于任意\(j\),如果有\(s[i]<s[j]\),则\(\sum abs(i-j)=b[i]\),即\(i\)到所有比\(s[i]\)大的下标距离之和等于\(b[i]\)
分析
字符串\(t\)提供的就是每个字符的数量,我们发现对于字符最大的位置,\(b[i]\)肯定为\(0\),然后次大的位置,\(b[i]\)被这些最大的位置影响,以此类推,我们保存一个已经填进去的数组,然后每一次枚举的时候将这个位置与数组中的数求绝对值之和,因为已经填进去的字符肯定比当前位置字符要大,所以如果这个和等于\(b[i]\),则这个数这一轮是可以填的,然后就是从大到小枚举字符,如果字符数比当前填的个数大,则选择,否则选小的字符
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
char s[maxn];
int a[maxn];
int num[maxn];
char ans[maxn];
bool vis[maxn];
void solve() {
int n;
cin >> (s + 1) >> n;
rep(i, 1, n)cin >> a[i], vis[i] = false;
rep(i, 0, 26)num[i] = 0;
rep(i, 1, strlen(s + 1))++num[s[i] - 'a'];
vector<int> v;
int m = n;
int now = 25;
while (m > 0) {
int tot = 0;
vector<int> pos;
rep(i, 1, n) {
if (vis[i])
continue;
int sum = 0;
for (auto &to:v)
sum += abs(to - i);
if (sum == a[i])
pos.push_back(i);
}
for (auto &to:pos) {
vis[to] = true;
++tot;
v.push_back(to);
}
while (num[now] < tot)
--now;
m -= tot;
for (auto &to:pos)
ans[to] = (char) (now + 'a');
--now;
}
rep(i, 1, n)cout << ans[i];
cout << '\n';
}
signed main() {
start;
cin >> T;
while (T--)
solve();
return 0;
}
CodeForces 1367D Task On The Board的更多相关文章
- Codeforces Round #650 (Div. 3) D. Task On The Board (构造,贪心)
题意:有一个字符串和一组数,可以对字符串删去任意字符后为数组的长度,且可以随意排序,要求修改后的字符串的每个位置上的字符满足:其余大于它的字符的位置减去当前位置绝对值之和等于对应序列位置上的数. 题解 ...
- Codeforces 1511G - Chips on a Board(01trie/倍增)
Codeforces 题面传送门 & 洛谷题面传送门 一道名副其实的 hot tea 首先显然可以发现这俩人在玩 Nim 游戏,因此对于一个 \(c_i\in[l,r]\) 其 SG 值就是 ...
- 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task
E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...
- codeforces 70D Professor's task(动态二维凸包)
题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...
- Codeforces Gym 100002 D"Decoding Task" 数学
Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...
- Codeforces 558E A Simple Task (计数排序&&线段树优化)
题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...
- Codeforces Round #312 (Div. 2) E. A Simple Task 线段树
E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- Codeforces Round #248 (Div. 1) B. Nanami's Digital Board 暴力 前缀和
B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami i ...
- Codeforces Round #312 (Div. 2) E. A Simple Task 线段树+计数排序
题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsme ...
随机推荐
- ssh,socat端口转发
ssh隧道 我们将要研究的第一个协议是SSH,因为它已经内置了通过SSH隧道进行端口转发的功能.虽然SSH曾经是与Linux系统相关联的协议,但现在Windows默认安装了OpenSSH客户端,因此您 ...
- CSI架构和原理
CSI CSI简介 CSI的诞生背景 K8s 原生支持一些存储类型的 PV,如 iSCSI.NFS.CephFS 等等,这些 in-tree 类型的存储代码放在 Kubernetes 代码仓库中.这里 ...
- shell编程-文件归档
需求说明:设置定时任务,每天凌晨1点进行将指定目录(/root/scripts)下文件按照archive_目录名_年月日.tar.gz的格式归档存放到/root/archive 路径下. 1.编写脚本 ...
- JUC同步锁原理源码解析五----Phaser
JUC同步锁原理源码解析五----Phaser Phaser Phaser的来源 A reusable synchronization barrier, similar in functionalit ...
- 2021/1/10例会 academy of management journal 2014vol 57 No.2,484-514
这次的论文由于考试周的原因看的不是很细,但大概还是浏览过一遍了.然后这次我的拓展又神奇的匹配到了教授想让我们接下来想看的论文. perfect! 但不足的是,没有进行相关论文的检索,自己的拓展没有理论 ...
- PHP支付接口签名生成数据
<?php //作者主页 https://www.woailunwen.com $pay_memberid = '商户号'; $pay_orderid = '订单号'; $pay_amount ...
- FFmpeg+SDL实时解码和渲染H264视频流
前言 之前实现了Android手机摄像头数据的TCP实时传输,今天接着聊聊,如何在PC端把接收到的H264视频流实时解码并渲染出来.这次使用的语言是C++,框架有FFmpeg和SDL2. 解码 解码部 ...
- 脚手架服务运行 报错 error:03000086:digital envelope routines::initialization error
报错图片 解决方法: 降低版本 https://nodejs.org/zh-cn/ 安装后(安装前先卸载高版本,点击左下放大镜搜索"卸载程序" 进行卸载) 安装完成后,再次回到vu ...
- 【git】基于JGit通过ssh-url拉取指定commit-id的代码
实现 1️⃣ pom依赖: <dependency> <groupId>org.eclipse.jgit</groupId> <artifactId>o ...
- linux内核Makefile中的变量build--- 过渡篇(五)
一. kbuild系统主要涉及的几个文件 文件名 作用 Makefile 内核源代码顶层目录的Makefile文件 scripts/Makefile.build 通常在进行递归make时会用到的Mak ...