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 //如果是的话. //说 ...
随机推荐
- poj 2585 Window Pains 暴力枚举排列
题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...
- Spring AOP监控SQL运行
对数据库连接池Proxool比較熟悉的读者,都知道Proxool能够记录SQL运行内容和时间等信息日志. 我们能够将该日志记录专门的SQL日志文件.对于查找运行特别耗时的SQL起了不小的作用. 对于一 ...
- udhcp源码详解(一)之文件组织结构(dhcp server) --转
udhcp目录下有十几个源文件,一个源文件相对应一个模块,完成一系列相关的功能,例如在static_leases.c主要针对static_lease链表增删查找等操作. dhcpd.c—— 整个d ...
- scikit-learn:class and function reference(看看你究竟掌握了多少。。)
http://scikit-learn.org/stable/modules/classes.html#module-sklearn.decomposition Reference This is t ...
- NoSQL之Redis探析
下载地址:wget http://download.redis.io/releases/redis-2.8.8.tar.gz安装steps:1 下载Official Website : http:// ...
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)<转>
MVC 默认 Request 方式为 Post. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三&qu ...
- oracle连接串的一种写法
我在.NET项目里访问oracle,向来是规规矩矩地这样写: DATA SOURCE=PDBGZFBC;PASSWORD=test;PERSIST SECURITY INFO=True;USER ID ...
- 怎样快速刪除Word中超链接?
有时我们从网上down了一些资料,存到Word文档里,会发现一些文字和图片带有超链接.这其实是Word自动修改功能引起的麻烦,那么,有什么办法可以把这些超链接快速批量删掉吗? 步骤/方法 1 按键盘上 ...
- 织梦万能调用LOOP标签!
1,安装DEDE织梦程序时候,数据库名称设置独立的一个. 2,雨田SEOER这里用的是在织梦本地文件夹中新建myblog文件夹,然后里面装入emlog_5.3.0的安装文件.URL地址栏输入htt ...
- 《Perceptual Losses for Real-Time Style Transfer and Super-Resolution》论文笔记
参考 http://blog.csdn.net/u011534057/article/details/55052304 代码 https://github.com/yusuketomoto/chain ...