题意:http://codeforces.com/problemset/problem/915/C

举个例子:假使排好序后a字符串是123456,b是456456,按照上述方法遍历,
213456 ->312456->412356->(这是第一个字符的最大值,再往下变的话只能是5了,但不满足题意)—–>(这是就会发现原本最小的字符1在第二位了,这样的话就不会使你的遍历中间有漏项,因为第一位是当前最大的,第二位是当前最小的)—>再往下的同理,就不具体细推了
https://blog.csdn.net/yiqzq/article/details/79692352

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
#include <cassert>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
const ll INF=(1LL<<);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; char a[],b[];
ll get(char x[],int n)
{
ll temp=;
for(int i=;i<=n;++i)
temp*=,temp+=x[i]-'';
return temp;
} int main()
{
sc("%s%s",a+,b+);
int la=strlen(a+);
int lb=strlen(b+);
if(la<lb)
{
sort(a+,a++la,greater<int>());
pr("%s\n",a+);
}
else if(la>lb)
{
pr("-1\n");
}
else
{
sort(a+,a++la);
ll Val=get(b,lb);
for(int i=;i<=la;++i)
{
for(int j=i+;j<=la;++j)
{
char temp[];
strcpy(temp+,a+);
swap(temp[i],temp[j]);
ll val=get(temp,la);
if(val<=Val)
swap(a[i],a[j]);
else
break;
}
}
ll ans=get(a,la);
pr("%lld\n",ans);
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

最新文章

  1. 电脑装的是office2013,右键新建却是2007,或者右键新建菜单中没有excel2013问题解决办法。
  2. 输入输出流(IO)
  3. 通过DIV+span方式模拟进度条的实现方法
  4. Django 分页2 (Pagination)
  5. 系统架构师JD
  6. 诡异的问题“该字符串未被识别为有效的 DateTime”
  7. Android开发系列之按钮事件的4种写法
  8. Android:Toast简单消息提示框
  9. 虚拟机配置网络 vmware 【nat方式】
  10. WCF部署到IIS异常(详细: 不能加载类型System.ServiceModel.Activation.HttpModule )
  11. jsxtransformer.js 和browser.js有什么关系?
  12. C# 实现客户端程序自动更新
  13. AIO5岗位桌面主页【我的收藏夹】只显示8行,怎样增加显示行?
  14. “Excel-建议不可用于您所选择的数据”错误提示
  15. mysql如何卸载完全
  16. CSS中层叠和CSS的7阶层叠水平(上篇)
  17. javascript DOM document属性
  18. Crystal Reports报表使用 [一]
  19. springmvc-mybatis整合出错: Invalid bound statement (not found)
  20. apache ab 压力测试工具

热门文章

  1. Java面向对象6(AA ~ AE)
  2. 十三、LVM 逻辑卷管理
  3. CSP2019懵逼记
  4. Vue图片浏览组件v-viewer,支持旋转、缩放、翻转等操作
  5. 理解了这些异常现象才敢说真正懂了TCP协议
  6. nginx配置不当引起的错误
  7. oracle 常用工具类及函数
  8. 安装vue模板时,选择webpack-simple还是Webpack?
  9. Facebook币Libra学习-6.发行属于自己的代币Token案例(含源码)
  10. 003-多线程-JUC线程池-几种特殊的ThreadPoolExecutor【newFixedThreadPool、newCachedThreadPool、newSingleThreadExecutor、newScheduledThreadPool】