构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
/*
构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值。
另外,最多len-1次循环
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f; int get_len(ll x) {
int ret = ;
while (x) {
x /= ; ret++;
}
return ret;
} int get_nine(ll x) {
int ret = ;
while (x) {
ll y = x % ; x /= ;
if (y != ) break;
ret++;
}
return ret;
} int main(void) { //Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
//freopen ("C.in", "r", stdin); ll p, d;
while (scanf ("%I64d%I64d", &p, &d) == ) {
int len = get_len (p); ll now = p;
int mx = get_nine (p); ll ans = p;
ll cut = ;
while (true) {
ll y = now / cut % ;
if (y != ) {
now = now - cut * ; now = now / cut + cut - ;
}
cut *= ;
if (now < p - d) break;
int cnt = get_nine (now);
if (cnt > mx) ans = now;
} printf ("%I64d\n", ans);
} return ;
}
构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!的更多相关文章
- CodeForces 219B Special Offer! Super Price 999 Bourles!
Special Offer! Super Price 999 Bourles! Time Limit:1000MS Memory Limit:262144KB 64bit IO For ...
- Special Offer! Super Price 999 Bourles!
Description Polycarpus is an amateur businessman. Recently he was surprised to find out that the mar ...
- Codeforces Round #135 (Div. 2)
A. k-String 统计每个字母出现次数即可. B. Special Offer! Super Price 999 Bourles! 枚举末尾有几个9,注意不要爆掉\(long\ long\)的范 ...
- 树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计 ...
- 贪心 Codeforces Round #135 (Div. 2) C. Color Stripe
题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #incl ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
随机推荐
- 逆袭指数-——杭电校赛(dfs)
逆袭指数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- (入门SpringBoot)SpringBoot来临(一)
.创建独立的Spring应用程序. .嵌入tomcat,Jetty或者Undertow,无需部署war文件; .允许通过Maven来获取starter; .尽可能的自动配置Spring. .提供生产就 ...
- php配置(php7.3)
[PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; PHP's initialization file, general ...
- 类的operator new与operator delete的重载【转】
http://www.cnblogs.com/luxiaoxun/archive/2012/08/11/2633423.html 为什么有必要写自己的operator new和operator del ...
- Ubuntu14.04 忘记rootpassword的解决方法
对于windows操作系统,假设忘记管理员password,事实上还是蛮好解决的. 最简单的一种方式就是使用PE--电脑店,老毛桃等等,都能够非常完美的解决问题. 假设是Linux操作系统的话.事实上 ...
- Tree Operations 打印出有向图中的环
题目: You are given a binary tree with unique integer values on each node. However, the child pointers ...
- alias记录
在seajs里边会有配置alias对象属性的,这个就是一个别名,下次在模块加载的时候直接引用别名就好了. 别名配置,配置之后可在模块中使用require调用 require('jquery'); se ...
- GSON学习笔记之初识GSON
引用"JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,採用全然独立于语言的文本格式.为Web应用开发提供了一种理想的数据交换格式. " ...
- (二)Java 简介
Java 简介 Java是由Sun Microsystems公司于1995年5月推出的Java面向对象程序设计语言和Java平台的总称.由James Gosling和同事们共同研发,并在1995年正式 ...
- go3--常量和类型转换
/* Go中不存在隐式转换,所有类型转换必须显式声明 转换只能发生在两种相互兼容的类型之间 类型转换的格式: <ValueA> [:]= <TypeOfValueA>(< ...