Codeforces Round #650 (Div. 3) D. Task On The Board(思维,模拟)

题目链接

思路:0是个特殊值,只有最大的字母才会在零的位置上,我们先把最大的字母填到0的位置上,然后把其他不是0的位置的值减去0位置给他们的贡献值,比如此时0位置的下标为num,那么其他位置a[i]的贡献就变成a[i]=a[i]-abs(num-i),内次更新一轮就会有新的0位置出现,再去填入第二大的字母,一直循环到都为0就可以了 (脑子不太好使的我写的比较麻烦)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false)
#define space putchar(' ')
#define enter putchar('\n')
typedef pair<int,int> PII;
const int mod=1e4+7;
const int N=2e6+10;
const int inf=0x7f7f7f7f;


ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}

template <class T>
void read(T &x)
{
    char c;
    bool op = 0;
    while(c = getchar(), c < '0' || c > '9')
        if(c == '-')
            op = 1;
    x = c - '0';
    while(c = getchar(), c >= '0' && c <= '9')
        x = x * 10 + c - '0';
    if(op)
        x = -x;
}
template <class T>
void write(T x)
{
    if(x < 0)
        x = -x, putchar('-');
    if(x >= 10)
        write(x / 10);
    putchar('0' + x % 10);
}
int a[150],b[150],vis[150];
char str[150];
map<char,int> mp,has;

int n;
bool judge()
{
    for(int i=1;i<=n;i++)
        if(!vis[i])return false;
    return true;
}
int main()
{
    SIS;
    int t;
    cin>>t;
    while(t--)
    {
        mp.clear();
        has.clear();
      memset(vis,0,sizeof vis);
      memset(str,0,sizeof str);
      string s;
      cin>>s;
      cin>>n;
      int len=s.size();
      sort(s.begin(),s.end());
      for(int i=0;i<len;i++)
        mp[s[i]]++;
      len--;
      for(int i=1;i<=n;i++)
      {
          cin>>a[i];
      }
      while(1)
      {
          memset(b,0,sizeof b);
          int bcnt=0;
          if(judge())break;
          int sum=0;
          int c=0;
          for(int i=1;i<=n;i++)
          {
              if(!vis[i]&&a[i]==0)
              {
                  vis[i]=1;
                  c++;
                  b[++bcnt]=i;
              }
          }
          while(1)
          {
            // cout<<"c="<<c<<' '<<s[len]<<endl;
              if(mp[s[len]]>=c&&!has[s[len]]){
                for(int i=1;i<=n;i++)
                {
                    if(vis[i]==1&&a[i]==0)
                    {
                        str[i]=s[len];vis[i]++;

                    }

                }
                has[s[len]]++;
                mp[s[len]]-=c;
                len--;break;
              }
              len--;
          }

         for(int i=1;i<=bcnt;i++)
         {
             for(int j=1;j<=n;j++)
             {
                 if(!vis[j]){
                    a[j]-=abs(b[i]-j);
                 }
             }
         }



      }
      for(int i=1;i<=n;i++)
        cout<<str[i];
        cout<<endl;


    }

    return 0;
}








  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值