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 ...
随机推荐
- SpringMVC 后台从前端获取单个参数
1.编写web.xml(模板) 2.springmvc配置文件 3.编写对应数据库字段的pojo实体类 @Data @AllArgsConstructor @NoArgsConstructor pub ...
- JavaScript原型与原型链深入理解
原型: 每一个js 对象(null除外)都会和另一个对象相关联,"另一个"对象就被我们称之为'原型', 而每一个原型拥有一个prototype 属性指向原型对象(就是原型的实例)的 ...
- GIT多场景下使用
git对于大家应该都不太陌生,熟练使用git已经成为程序员的一项基本技能,尽管在工作中有诸如 Sourcetree这样牛X的客户端工具,使得合并代码变的很方便.但找工作面试和一些需彰显个人实力的场景, ...
- 烂怂if-else代码优化方案
0.问题概述 代码可读性是衡量代码质量的重要标准,可读性也是可维护性.可扩展性的保证,因为代码是连接程序员和机器的中间桥梁,要对双边友好.Quora 上有一个帖子: "What are so ...
- 文档在线预览(三)使用js前端实现word、excel、pdf、ppt 在线预览
@ 目录 实现方案 一.docx文件实现前端预览 1.docx-preview 2.Mammoth 二.PDF文件实现前端预览 1.pdf.js 2.pdfobject.js 3.vue-pdf 4. ...
- hw面试常见中间件漏洞
apache漏洞 未知扩展名解析漏洞 漏洞原理:Apache对文件名后缀的识别是从后往前进行的,当遇到不认识的后缀时,继续往前,直到识别 影响版本:使用module模式与php结合的所有版本,apac ...
- R 包 pathview 代谢通路可视化
pathview R 包是一个集成 pathway 通路数据与可视化的工具集.它用于把用户的数据映射并渲染到相关的 pathway 通路图上,用户只需要提供基因或者化合物数据(gene or comp ...
- shell工具和脚本
Shell脚本 shell 脚本是一种更加复杂度的工具. 大多数shell都有自己的一套脚本语言,包括变量.控制流和自己的语法.shell脚本 与其他脚本语言不同之处在于,shell 脚本针对 she ...
- std::aligned_alloc
定义于头文件 <cstdlib> (c++) void * aligned_alloc ( std::size_t alignment, std::size_t size); (c++17 ...
- 3. IOC相关内容
1. bean 相关配置 对于 bean 的配置中,主要会讲解bean基础配置,bean的别名配置,bean的作用范围配置(重点),这三部分内容: 1.1 bean 基础配置(id 与 c ...