思路:

从左到右贪心放置数字,要注意判断这个数字能否放置在当前位。

实现:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[], buf[]; bool check(ll t, ll b)
{
memcpy(buf, cnt, sizeof(int) * );
for (int i = ; i <= ; i++)
{
while (buf[i]) { t *= ; t += i; buf[i]--; }
}
return t <= b;
} int main()
{
string a, b;
while (cin >> a >> b)
{
int x = a.length(), y = b.length();
for (int i = ; i < ; i++) cnt[i] = ;
for (int i = ; i < x; i++) cnt[a[i] - '']++;
ll ans = ;
bool flg = x < y ? true : false;
for (int j = y - ; j > y - x - ; j--)
{
int k = flg ? : b[y - - j] - '';
for (; k >= ; k--)
{
if (!cnt[k]) continue;
cnt[k]--;
if (check(ans + k, stoll(b)))
{
ans += k;
if (k < b[y - - j] - '') flg = true;
if (j != y - x) ans *= ;
break;
}
cnt[k]++;
}
}
cout << ans << endl;
}
return ;
}

CF915C Permute Digits的更多相关文章

  1. CF915C Permute Digits 字符串 贪心

    You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...

  2. CodeForces-915C Permute Digits

    C. Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces 915 C. Permute Digits (dfs)

    题目链接:Permute Digits 题意: 给出了两个数字a,b(<=1e18),保证a,b都不带前缀0.用a的字符重组一个数字使这个值最大且小于b.(保证这个值存在) 题解: 这题遇到了不 ...

  4. cf Permute Digits(dfs)

    C. Permute Digits You are given two positive integer numbers a and b. Permute (change order) of the ...

  5. 【CodeForces 915 C】Permute Digits(思维+模拟)

    You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...

  6. Permute Digits 915C

    You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...

  7. Permute Digits

    You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...

  8. C. Permute Digits dfs大模拟

    http://codeforces.com/contest/915/problem/C 这题麻烦在前导0可以直接删除,比如 1001 100 应该输出11就好 我的做法是用dfs,每一位每一位的比较. ...

  9. 【Educational Codeforces Round 36 C】 Permute Digits

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...

随机推荐

  1. conda安装速度慢解决办法

    注意,清华已经撤掉其ananconda源, 下面的方法已经失效,中科大源好像也不行,如果有解决办法烦请评论告诉我. conda config --add channels https://mirror ...

  2. 转载 Url编码

    http://www.cnblogs.com/artwl/archive/2012/03/07/2382848.html 混乱的URI编码 JavaScript中编码有三种方法:escape.enco ...

  3. SQL Server 2012 从备份中还原数据库

    1.首先把原数据库备份,检查原数据库的日志文件是否太大,如果过于大应该先收缩数据库日志 2.把备份的数据库文件在目标SQL Server还原,点击数据库,选择“还原文件或文件组” 3.如果需要修改还原 ...

  4. bzoj1934: [Shoi2007]Vote 善意的投票&&bzoj2768:[JLOI2010]冠军调查

    get到新姿势,最小割=最大流,来个大佬的PPT 这道题的做法是将st和1的xpy连,0的xpy和ed连,xpy之间jy连双向边,然后呢答案就是最小割. #include<cstdio> ...

  5. 什么叫强类型的DATASET ?对DATASET的操作处理?强类型DataSet的使用简明教程

    强类型DataSet,是指需要预先定义对应表的各个字段的属性和取值方式的数据集.对于所有这些属性都需要从DataSet, DataTable, DataRow继承,生成相应的用户自定义类.强类型的一个 ...

  6. 使用C#开发HTTP服务器系列之访问主页

    各位朋友大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是http://qinyuanpei.com.在这个系列文章的第一篇中,我们着重认识和了解了HTTP协议,并在此基础上实现了一个可交互的W ...

  7. [Usaco2009 MAR] Earthquake Damage 2

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1585 [算法] 一个最小割的经典模型 , 详见代码 时间复杂度 : O(dinic( ...

  8. 【USACO 2011】 道路和航线

    [题目链接] 点击打开链接 [算法] SPFA + SLF / LLL 优化 [代码] #include<bits/stdc++.h> using namespace std; #defi ...

  9. Java-Runoob-高级教程-实例-数组:01. Java 实例 – 数组排序及元素查找

    ylbtech-Java-Runoob-高级教程-实例-数组:01. Java 实例 – 数组排序及元素查找 1.返回顶部 1. Java 实例 - 数组排序及元素查找  Java 实例 以下实例演示 ...

  10. SetWindowPos

    SetWindowPos函数改变一个子窗口,弹出式窗口或顶层窗口的尺寸,位置和Z序.子窗口,弹出式窗口,及顶层窗口根据它们在屏幕上出现的顺序排序.顶层窗口设置的级别最高,并且被设置为Z序的第一个窗口. ...