思路:

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

实现:

 #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. android 不同进程间的调用 AIDL 实现通讯服务

    android 不同进程间的调用  AIDL 实现通讯服务       近期对aidl android 不同进程间的调用,不同运用间的调用做了一些尝试: 过程例如以下: 1:首先在要被调用的程序里写好 ...

  2. C语言将10进制转为2进制

    第一种方法: #include<stdio.h> void dectobin(int n); int main() { int x=0; scanf("%d",& ...

  3. 10 逻辑完善以及bug修复

    进行到这里,我们应用开发已经接近尾声,我这里基本就是应用开发的记录过程,讲解的东西很少,有问题可以在评论区讨论呦.下面进入最后调整的阶段. 预览我们的应用,会发现首页的职位列表,也会显示收藏的星星图标 ...

  4. Android-shareSDK

    1.当数据: 地址:http://sharesdk.mob.com/Download 2.集成数据: DOS命令: java -jar QuickIntegrater.jar    (输入自己的项目名 ...

  5. BZOJ 2460: [BeiJing2011]元素 线性基

    2460: [BeiJing2011]元素 Description 相传,在远古时期,位于西方大陆的 Magic Land 上,人们已经掌握了用魔法矿石炼制法杖的技术.那时人们就认识到,一个法杖的法力 ...

  6. Codeforces 755 F. PolandBall and Gifts 多重背包+贪心

    F. PolandBall and Gifts   It's Christmas time! PolandBall and his friends will be giving themselves ...

  7. Latex 2: 解决WinEdt和TexWorks用久之后忽然不能正反向搜索

    说明:下面说的WinEdt版本是10.1,TexWorks是texlive2016中自带的texworks,如果情况不一样请自行测试,原理一样 1.不能正向搜索: 解决:① 确定路径名是英文名(实际上 ...

  8. 在调试状态查看DateTable里的数据信息

  9. 并不对劲的bzoj4817:loj2001:p3703:[SDOI2017]树点涂色

    题目大意 有一棵\(n\)(\(n\leq10^5\))个节点的树,每个点有颜色\(c\),一开始所有颜色互不相同 要进行\(m\)(\(m\leq10^5\))次操作,每次操作是以下三种中的一种: ...

  10. 【181】IDL 代码从 Windows 转移到 Linux

    文件夹分隔符,Windows 是“/”,Linux 是“\”,按照程序,需要修改 通过 bash 运行 *.pro 文件,貌似只能运行没有参数的,有参数的需要写入到文件中 idl 的文件不能用大写字母 ...