cf 1367D

题目: 传送门

想了很多思路,都不太好写。。。

思路:每次找到b数组中 bi == 0 的位置,然后填上最大的字符,再暴力删除这些位置对其他位置的贡献值即可。

 1 #include<bits/stdc++.h>
 2 /*
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<cstring>
 6 #include<vector>
 7 #include<cctype>
 8 #include<queue>
 9 #include<algorithm>
10 #include<map>
11 #include<set>
12 */
13 #pragma GCC optimize(2)
14 using namespace std;
15 typedef long long LL;
16 typedef pair<int,int> pii;
17 typedef pair<double,double> pdd;
18 const int N=1e4+5;
19 const int M=1e4+5;
20 const int inf=0x3f3f3f3f;
21 const LL mod=1e9+7;
22 const double eps=1e-9;
23 const long double pi=acos(-1.0L);
24 #define ls (i<<1)
25 #define rs (i<<1|1)
26 #define fi first
27 #define se second
28 #define pb push_back
29 #define mk make_pair
30 #define mem(a,b) memset(a,b,sizeof(a))
31 LL read()
32 {
33     LL x=0,t=1;
34     char ch;
35     while(!isdigit(ch=getchar())) if(ch=='-') t=-1;
36     while(isdigit(ch)){ x=10*x+ch-'0'; ch=getchar(); }
37     return x*t;
38 }
39 char s[N],ans[N];
40 int b[N];
41 int main()
42 {
43     int T=read();
44     while(T--)
45     {
46         int cnt[30]={0};
47         scanf("%s",s+1);
48         int m=strlen(s+1);
49         int n=read();
50         for(int i=1;i<=n;i++) b[i]=read();
51         for(int i=1;i<=m;i++) cnt[s[i]-'a']++;
52         int tot=25,k=n;
53         while(k){
54             vector<int> a;
55             for(int i=1;i<=n;i++)
56                 if(b[i]==0) a.pb(i);
57             while(a.size()>cnt[tot]) tot--;
58             for(int i=1;i<=n;i++)
59                 for(auto x:a)
60                     if(b[i]>0) b[i]-=abs(i-x);
61             for(auto x:a) ans[x]='a'+tot,b[x]=-1;
62             k-=a.size();
63             tot--;
64         }
65         for(int i=1;i<=n;i++) printf("%c",ans[i]);
66         printf("
");
67     }
68 }
View Code
原文地址:https://www.cnblogs.com/DeepJay/p/13218189.html