BZOJ3799 : 字符串重组
从大到小枚举答案与T串的lcp,然后贪心
#include<cstdio>
#include<cstring>
char s[5010],t[5010],ans[5010];
int n,m,i,j,a[128],b[128],flag;
int main(){
scanf("%s%s",s,t);
n=std::strlen(s),m=std::strlen(t);
for(i=0;i<n;i++)a[s[i]]++;
for(i=m;~i;i--){
for(j=0;j<128;j++)b[j]=a[j];
for(j=flag=0;j<i;j++){ans[j]=t[j];if((--b[t[j]])<0)flag=1;}
if(flag)continue;
for(flag=1,j=t[i]+1;j<128;j++)if(b[j]){flag=0;break;}
if(flag)continue;
b[ans[i]=j]--;
for(j=0;j<=i;j++)putchar(ans[j]);
for(j=0;j<128;j++)while(b[j]--)putchar(j);
return 0;
}
return puts("-1"),0;
}
BZOJ3799 : 字符串重组的更多相关文章
- 小白学开发(iOS)OC_ 字符串重组(2015-08-13)
// // main.m // 字符串重组 // // Created by admin on 15/8/13. // Copyright (c) 2015年 admin. All right ...
- nsstring字符串重组
// // main.m // 05-字符串重组 // // Created by apple on 14-3-20. // Copyright (c) 2014年 apple. All ri ...
- 【转】解决jsp参数传递乱码的问题
解决jsp参数传递乱码的问题 计算机生于美国,英语是他的母语,而英语以外的其它语言对他来说都是外语.他跟我们一样,不管外语掌握到什么程度,也不会像母语那样使用得那么好,时常也会出一些“拼写错误”问题. ...
- leetcode409
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- 第三十节,正则表达式re模块
正则表达式 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序员们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引 ...
- 安全性测试入门:DVWA系列研究(二):Command Injection命令行注入攻击和防御
本篇继续对于安全性测试话题,结合DVWA进行研习. Command Injection:命令注入攻击. 1. Command Injection命令注入 命令注入是通过在应用中执行宿主操作系统的命令, ...
- pager-taglib2.0中文传参乱码问题
1.重现问题 在web项目中有时会用到pager-taglib来作为分页的标签,如上图红色框标识所示,当我们需要把页面参数保持的时候我们会在<pg:param />标签中把参数进行传递. ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【iOS开发】-NSString的扩展使用
第一:基本数据类型与字符串转换 //基本数据类型(int float,double char) 1)基本数据类型->NSString //1.int类型换换成字符串 int a = 88; NS ...
随机推荐
- Linux下tomcat服务
一:Linux下tomcat服务的启动.关闭与错误跟踪,使用PuTTy远程连接到服务器以后,通常通过以下几种方式启动关闭tomcat服务:切换到tomcat主目录下的bin目录(cd usr/loca ...
- Android程序启动加载动画实现
package com.example.bmob_test.ui;//程序启动动画,图片颜色由浅到深,方法一 import com.example.bmob_test.LogActivity; imp ...
- Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
- A + B Problem
Write a function that add two numbers A and B. You should not use + or any arithmetic operators. 分析: ...
- Java for LeetCode 049 Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- Greedy:Stripes(POJ 1826)
新生物 题目大意:给你一堆数,两两结合,答案为2*sqrt(x1*x2),问组合成一个数时,最小的量? 超级无敌大水题,排序或者用堆都可以,反正就是优先组合大的,让根号一直把大数开根降低整体的大小 # ...
- border-box
box-sizing属性可以为三个值之一:content-box(default),border-box,padding-box. content-box,border和padding不计算入wi ...
- July 23rd, Week 30th Saturday, 2016
A day is a miniature of eternity. 一天是永恒的缩影. For a man, the eternity is his lifetime which is measure ...
- rdesktop remember
整个地球都知道rdesktop,有了它,我们可以从Solaris或者Linux使用Windows,当然Windows要开启Windows Terminal Service.虽然也有基于GTK+的tsc ...
- 强制JSP页面刷新,防止被服务器缓存(可用于静态include强制刷新)
对于jsp页面,为了防止页面被服务器缓存.始终返回同样的结果. 通常的做法是在客户端的url后面加上一个变化的参数,比如加一个当前时间. 我现在使用的方法是在jsp头部添加以下代码: <% ...