Little Sub and Mr.Potato's Math Problem-构造
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5864
思路 : 判断小于它的合法的,再看大于它的合法的,特判10000、10、1000.... 这种情况
.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll t,n,k,m,po[222];
ll getmin(ll x)
{
ll ret=0,data[55],id=0;
po[0]=1;
while(x)
{
data[id++]=x;
x/=10;
po[id]=po[id-1]*10;
}
for(int i=0; i<id; i++)
ret+=data[i]-po[id-i-1]+1;
return ret;
}
int main()
{
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&k,&m);
m-=getmin(k);
if(m<0)printf("0\n");
else if(m==0)printf("%lld\n",k);
else
{
ll hig,big;
for(ll i=1;; i*=10)
if(k/i<10)
{
big=i;
hig=k-i;
break;
}
if(big==k)printf("0\n");
else
{
big*=10;
hig*=10;
while(m>hig)
{
m-=hig;
hig*=10;
big*=10;
}
printf("%lld\n",big+m-1);
}
}
}
return 0;
}
Little Sub and Mr.Potato's Math Problem-构造的更多相关文章
- Little Sub and Mr.Potato's Math Problem (构造法)
题目传送门Little Sub and Mr.Potato's Math Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Littl ...
- (P2022 有趣的数)||(zoj Little Sub and Mr.Potato's Math Problem)(思维)
题目链接:https://www.luogu.org/problemnew/show/P2022 题目大意:中文题目 具体思路: 第一步:我们可以先计算出当前的数前面按照字典序的话,前面有多少数(包括 ...
- hdu 1757 A Simple Math Problem (构造矩阵解决递推式问题)
题意:有一个递推式f(x) 当 x < 10 f(x) = x.当 x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 5615 Jam's math problem
Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...
- hdu----(5055)Bob and math problem(贪心)
Bob and math problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- BestCoder Round #70 Jam's math problem(hdu 5615)
Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...
随机推荐
- MySql分页查询慢|这里告诉你答案
一.背景 我们在开发的过程中使用分页是不可避免的,通常情况下我们的做法是使用limit加偏移量:select * from table where column=xxx order by xxx li ...
- WebGL教程
https://www.w3cschool.cn/webgl/rleo1oh7.html
- PMP知识点(一)——风险登记册
一.Reference: [管理心得之四十八]<风险登记册>本身的风险 问题日志与风险登记册的区别与联系 PMBOK重要概念梳理之二十六 风险登记册 风险登记单-MBAlib 二.Atta ...
- Arduino语法-变量和常量
变量的声明: int led=11 一般变量的声明方法为类型名+变量名+变量初始化值.变量名的写法约定为首字母小写 变量的作用范围又称为作用域,变量的作用范围与该变量在哪儿声明有关,大致分为如下两种: ...
- Springboot项目打包后的页面丢失问题(thymeleaf报错)
遇到的问题目前找到两种: 返回视图路径以/开头,例如 /test/hello 在thymeleaf页面中,引入的页面以/开头,例如:<footer th:replace="/index ...
- springboot2.1.3集成单节点elasticsearch6.4.0
本案例写了一个关于医生医院搜索的例子,包括求和模式下的打分(分值与相关性有关)搜索,单节点时切勿配置节点名称和节点ip.github地址:https://github.com/zhzhair/spri ...
- Visual Studio 2013 SDK 扩展之简介
Release Notes:[发行说明]启动记事本的扩展,以管理员身份运行验证通过. Getting Started Guide:[入门]使用[Ctrl + 1]更快捷打开记事本 More Info ...
- 使用SpringSecurity体验OAUTH2之一 (入门1)
OAUTH2是一种安全的授权框架,其原理在网上有许多文章上可以看到.但从实践角度,好的文章比较少.SpringSecurity框架本身是支持OAUTH2的,所以下面通过使用SpringSecurity ...
- LaTex basics
分节: \section{Supplemental Material}\label{sec:supplemental} 小节: \noindent {\bf Preparing References: ...
- css 生成图片添加的十字
<span class="add" title="继续上传"></span> .add { display: inline-block; ...