CF915C Permute Digits
思路:
从左到右贪心放置数字,要注意判断这个数字能否放置在当前位。
实现:
#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的更多相关文章
- CF915C Permute Digits 字符串 贪心
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...
- CodeForces-915C Permute Digits
C. Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 915 C. Permute Digits (dfs)
题目链接:Permute Digits 题意: 给出了两个数字a,b(<=1e18),保证a,b都不带前缀0.用a的字符重组一个数字使这个值最大且小于b.(保证这个值存在) 题解: 这题遇到了不 ...
- cf Permute Digits(dfs)
C. Permute Digits You are given two positive integer numbers a and b. Permute (change order) of the ...
- 【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 ...
- Permute Digits 915C
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...
- Permute Digits
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...
- C. Permute Digits dfs大模拟
http://codeforces.com/contest/915/problem/C 这题麻烦在前导0可以直接删除,比如 1001 100 应该输出11就好 我的做法是用dfs,每一位每一位的比较. ...
- 【Educational Codeforces Round 36 C】 Permute Digits
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...
随机推荐
- VTMagic的使用
// VTMagic的使用 // CFOrderViewController.m // qifuyuniOS //// /** * @author 李洪强, 16-08-30 10:08:50 ...
- 百度接口通过ip获取用户所在地
/** * 百度接口 * 通过用户ip获取用户所在地 * @param userIp * @return */ public static String get ...
- 树莓派 mongodb 安装&报错处理
树莓派 mongodb 安装&报错处理 编译过的源码下载地址: http://files.cnblogs.com/files/xueshanshan/mongodb-rpi.zip addus ...
- md5 js
js-md5 - npm https://www.npmjs.com/package/js-md5 var rotateLeft = function(lValue, iShiftBits) { re ...
- 通过fsharp 使用Enterprise Library Unity 3 - 三种拦截模式的探索
这篇就三种拦截模式进行一下探索. 特性总结 类型 特点 其它 InterfaceInterceptor Innstance 仅单接口 类内部函数互相引用无法引起拦截行为 TransparentPr ...
- CRM 插件奇怪的报错
CRM插件,数据库方式注册.报错 找不到方法:“Void Microsoft.Xrm.Sdk.Entity..ctor(System.String, System.Guid)”. 这个错误让人摸不着头 ...
- POJ3177 Redundant Paths —— 边双联通分量 + 缩点
题目链接:http://poj.org/problem?id=3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total ...
- HTML5、javascript写的craps游戏
1. [代码][HTML]代码 <!DOCTYPE HTML><html><head><meta charset="utf-8"> ...
- Mac 中安装 Apache Ant
1.下载Apache Ant:http://ant.apache.org/bindownload.cgi 2.解压apache-ant-1.9.6-bin.zip,把解压好的apache-ant-1. ...
- C# ref和out总结
C# 中ref 与 out 总结 参数的传递一般分为两种:一种是“值传递”即:传递实参的拷贝,既然是拷贝那么在函数中对这个形参所作的任何动作都不会反映到原来的实参中.另外一种是“引用传递”即:传递 ...