日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Task On The Board CodeForces - 1367D(思维)

發(fā)布時(shí)間:2023/12/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Task On The Board CodeForces - 1367D(思维) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Polycarp wrote on the board a string s containing only lowercase Latin letters (‘a(chǎn)’-‘z’). This string is known for you and given in the input.

After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information.

Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b1,b2,…,bm, where bi is the sum of the distances |i?j| from the index i to all such indices j that tj>ti (consider that ‘a(chǎn)’<‘b’<…<‘z’). In other words, to calculate bi, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than ti and sums all the values |i?j|.

For example, if t = “abzb”, then:

since t1=‘a(chǎn)’, all other indices contain letters which are later in the alphabet, that is: b1=|1?2|+|1?3|+|1?4|=1+2+3=6;
since t2=‘b’, only the index j=3 contains the letter, which is later in the alphabet, that is: b2=|2?3|=1;
since t3=‘z’, then there are no indexes j such that tj>ti, thus b3=0;
since t4=‘b’, only the index j=3 contains the letter, which is later in the alphabet, that is: b4=|4?3|=1.
Thus, if t = “abzb”, then b=[6,1,0,1].

Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously:

t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order;
the array, constructed from the string t according to the rules above, equals to the array b specified in the input data.
Input
The first line contains an integer q (1≤q≤100) — the number of test cases in the test. Then q test cases follow.

Each test case consists of three lines:

the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters;
the second line contains positive integer m (1≤m≤|s|), where |s| is the length of the string s, and m is the length of the array b;
the third line contains the integers b1,b2,…,bm (0≤bi≤1225).
It is guaranteed that in each test case an answer exists.

Output
Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any.

Example
Input
4
abac
3
2 1 0
abc
1
0
abba
3
1 0 1
ecoosdcefr
10
38 13 24 14 11 5 3 24 17 0
Output
aac
b
aba
codeforces
Note
In the first test case, such strings t are suitable: "aac’, “aab”.

In the second test case, such trings t are suitable: “a”, “b”, “c”.

In the third test case, only the string t equals to “aba” is suitable, but the character ‘b’ can be from the second or third position.

思路:對(duì)于一個(gè)字符串,肯定有最大的字母和次大的字母等等,對(duì)于一開始的b數(shù)組來(lái)說,如果為0的話,那么這個(gè)位置一定是最大字母,然后再減去這個(gè)位置對(duì)于其他位置的貢獻(xiàn),下一個(gè)為0的位置一定就是次大的字母,一直這樣弄下去直到所有的位置都弄完。
思路很好想,但是實(shí)現(xiàn)起來(lái)有些困難。
①對(duì)于很多個(gè)0,怎么計(jì)算所有的0的貢獻(xiàn)。
②對(duì)于一個(gè)字母來(lái)說,這個(gè)字母用完之后,大于等于這個(gè)字母的字母?jìng)€(gè)數(shù)都要清零。
這是我遇到的兩個(gè)坑點(diǎn)。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=1e2+10; int vis[maxx],b[maxx]; char s1[maxx]; string s; int n;inline bool cmp(char a,char b) {return a>b; } int main() {int t;scanf("%d",&t);while(t--){cin>>s;scanf("%d",&n);for(int i=0;i<26;i++) vis[i]=0;for(int i=1;i<=n;i++) scanf("%d",&b[i]);for(int i=0;i<s.length();i++) vis[s[i]-'a']++;sort(s.begin(),s.end());int cnt=0;while(cnt<n){int num=0;for(int i=1;i<=n;i++) if(b[i]==0) num++;int pos;for(int i=25;i>=0;i--){if(vis[i]>=num){pos=i;break;}}int rr=num;for(int i=pos;i<26;i++) vis[i]=0;num=0;for(int i=1;i<=n;i++){if(b[i]==0){num+=i;s1[i]=(char)('a'+pos);}}int zz=0,z1=0;for(int i=1;i<=n;i++){if(b[i]==0) zz+=i,z1++,b[i]=-1,cnt++;else if(b[i]==-1) continue;else{b[i]-=((i*z1-zz)+(num-zz)-i*(rr-z1));}}//for(int i=1;i<=n;i++) cout<<b[i]<<" ";cout<<endl;}for(int i=1;i<=n;i++) cout<<s1[i];cout<<endl;}return 0; }

努力加油a啊,(o)/~

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的Task On The Board CodeForces - 1367D(思维)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。