1367D 1800
题意:给你一段字符串,你可以从中选取字母,然后一个长度为n的数组,每个数字表示对于某个字符串s来说,为大于当前字母的位置为i,abs(当前位置-i)之和,问你s的字符串,保证s存在
思路:对于s从最大的字母开始计算,因为最大即贡献肯定是0,然后计算这个字母对这个字符串每个位置的贡献,然后会出现第二大的字母,且值为0,依次递推下去就行,因为题目保证了存在s。具体可看代码实现。(有好多地方容易出错)
代码如下:

#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define fopen freopen("file.in","r",stdin);freopen("file.out","w",stdout);
#define fclose fclose(stdin);fclose(stdout);
const int inf = 1e9;
const ll onf = 1e18;
const int maxn = 1e5+10;
inline int read(){int x=0,f=1;char ch=getchar();while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}return x*f;
}
inline void cf(){int t = read();while(t--){char s[60], str[60];scanf("%s", s);int sum[30], a[60];for(int i = 0; i < 30; i++) sum[i]=0;    //sum的初始化,不是宏定义for(int i = 0; i < (int)strlen(s); i++) sum[s[i]-'a']++;int n = read();for(int i = 0; i < n; i++) a[i]=read();int pos = 26, ans = n;while(ans){std::vector<int> v;int cnt = 0;for(int i = 0; i < n; i++) if(a[i]==0) cnt++, a[i]=-1, v.push_back(i);    // 当前a[i]==0计算之后要更改,不然会重复计算for(int i = 0; i < n; i++){if(a[i]>0){for(int j = 0; j < cnt; j++){a[i]-=abs(i-v[j]);   // 这里是abs(i-v[j])}}}for(int i = pos-1; i >= 0; i--) if(sum[i]>=cnt){pos=i;break;} // i=pos-1,因为pos已经是用过的了for(int i = 0; i < cnt; i++) str[v[i]]=pos+'a';ans-=cnt; // 计数,当ans==0时,即表示所有的位置都更新完了}str[n]='\0';    // 最后加一个终止符号printf("%s\n", str);}return ;
}
signed main(){cf();return 0;
}

codeforces1367D 思维模拟相关推荐

  1. 【HRBUST - 1623】Relation(思维模拟,拆解字符串)

    题干: 一天,ikki在看书的时候发现书上有个类似于家谱状的插图,突然ikki想到了一个有趣的现象:有时候用某个人一连串 的关系描述另一个人的时候,最后可能还是他本身.例如:小明的爸爸的爸爸和小明的爷 ...

  2. 【ZOJ - 2968 】Difference Game (贪心,思维模拟)

    题干: Now you are going to play an interesting game. In this game, you are given two groups of distinc ...

  3. 【CodeForces - 260C】Balls and Boxes (思维模拟,有坑,时光倒流)

    题干: Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with ...

  4. 【CodeForces - 349C】Mafia(思维模拟,优秀的二分)

    题干: One day n friends gathered together to play "Mafia". During each round of the game som ...

  5. 【Codeforces 631C 】Report(单调栈,思维模拟)

    题干: Each month Blake gets the report containing main economic indicators of the company "Blake ...

  6. 【CodeForces - 1042A】Benches (优先队列,思维模拟,maxmin问题)

    题干: There are nn benches in the Berland Central park. It is known that aiai people are currently sit ...

  7. 计算思维模拟题参考答案-单选题

    1.磁盘驱动器属于(C)设备. A.输入 B.输出 C.输入和输出 D.以上均不是 2.下列存储器中存取速度最快的是( A   ). A.内存 B.硬盘 C.光盘 D.U盘 3.下列叙述中,正确的是( ...

  8. 5809: 傻瓜电梯(思维模拟)

    5809: 傻瓜电梯 时间限制: 1 Sec  内存限制: 128 MB 提交: 196  解决: 35 [提交][状态][讨论版][命题人:admin] 题目描述 所谓傻瓜电梯指的是在响应用户请求时 ...

  9. 科大讯飞杯F题:思维模拟 排列计算

    https://ac.nowcoder.com/acm/contest/5477/F 牛客网的提交地址 真的是好久没打了,最近学校有个比赛想去玩玩的,所以提前半个月准备一下,俗话说的好,临阵磨枪不快也 ...

最新文章

  1. 吊打一切的YOLOv4的tricks汇总!附参考论文下载
  2. 谷歌AI公布新项目:未来你的宠物可能真的会是“机器”狗!
  3. 计算机算法设计与分析之----- 递归与分治策略
  4. Java的agent机制简述
  5. JavaScript 常见的六种继承方式
  6. 剑指 Offer 44. 数字序列中某一位的数字
  7. pytorch报错RuntimeError: error in LoadLibraryA
  8. h2o中模型存储与加载
  9. Mysql 命令行控制事务
  10. php rsa2 微博,微博登录分析
  11. 17_购物车删除商品与清空购物车
  12. 微信抽奖系统源码 v3.0
  13. 常用背景色RGB配色如下:
  14. 阿里云centos7.4安装并部署svn1.10.0版本(配置多仓库,加入开机自启动)
  15. 新增用户时输入账号已存在(全局异常处理)
  16. 冰柱图分析:学习笔记
  17. 大数据测试是什么意思?测试分析方法有哪些?
  18. 把PDF转换成PPT有哪些方法
  19. Windows10系统VC++6.0安装教程
  20. Python csv 跳过第一行

热门文章

  1. CGI, FCGI, SCGI, WSGI
  2. 应用程序无法正常启动(0xc000007b)解决办法
  3. 【STM32学习】基于STM32F411CEU6的USB储存设备
  4. 冲突域和碰撞域的理解
  5. OSChina 端午节乱弹 ——假期余额不足,大家端午快乐
  6. python爬虫实战小项目
  7. 解决麒麟系统安装mysql后登录错误:‘Access denied for user ‘root‘@‘localhost‘
  8. 数字信号处理随堂笔记(2)ᝰ离散时间信号与系统的频域分析
  9. python读取20万数据Excel文件+拆分数据
  10. uefi启动 多硬盘gtp_关于UEFI启动+GPT分区的一些经验