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 //如果是的话. //说 ...
随机推荐
- Unable to find a team with the given Team ID或者Failed to code sign的问题解决
Unable to find a team with the given Team ID或者Failed to code sign的问题解决 1:问题描述(注:这种情况一般是下载并打开别人项目时) F ...
- XMU 1611 刘备闯三国之卖草鞋 【贪心】
1611: 刘备闯三国之卖草鞋 Time Limit: 1000 MS Memory Limit: 64 MBSubmit: 90 Solved: 48[Submit][Status][Web B ...
- BZOJ_3172_[Tjoi2013]单词_AC自动机
BZOJ_3172_[Tjoi2013]单词_AC自动机 Description 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. ...
- 377D
树形dp 就是求每个点到标记的点的最大距离 一个经典模型 有一个巧妙的方法,我们求出以这些关键点的直径,然后每个点到关键点的最大距离就是到直径两端的距离 #include<bits/stdc++ ...
- 02_电话拨号器intent说明
怎么在第一个Activity打开第二个Activity?在一个Activity中打开另外一个Activity,实际上之前已经做过,就是电话拨号器. package com.itheima.callne ...
- vs2008添加消息函数方法
开发MFC时,开发工具VS2008不能像开发工具VC++6.0那样,直接在类文件上右击选择“Add Window Message Handles”来添加消息映射.对于我这个初学者,刚开始一直没找到可以 ...
- Ruby Time类和Date类
Time类 更新: 2017/06/23 更新了Data/Time在model模式下的便利方法 更新: 2018/10/12 修改了%Y相关描述防止误解 年月日时分秒,时区 生成 获取当前时 ...
- Hibernate对集合属性的操作---基础学习
1:Set集合属性操作 1).Hibernate3以后支持大部分重要的JDK集合接口映射,Set集合接口的配置: >在xxx.hbm.xml文件中使用<set>标签 2).< ...
- python 面向对象一 OOP
一.面向对象和面相过程 面向对象编程——Object Oriented Programming,简称OOP,是一种程序设计思想.OOP把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数. 面 ...
- thinkphp 中 dump 函数调试数组时显示不全解决方法
在php.ini里的 xdebug 节点中,加入如下 xdebug.var_display_max_children=128 #子级节点最多显示的的字符数xdebug.var_display_max_ ...