1163 - Bank Robbery
In one very cold morning, Mark decides to rob a bank. But while trying hacking into the security system, he found that it is locked by some random value. He also found a pattern on the random number, that is if he chops off the last digit of a number A, he gets a new number B. Then he calculates (A-B). He checked the first few numbers of the security system which exactly equals (A-B). Being very excited to have found the pattern, he learns that there are like 500 levels on the security system. He calculated all those numbers by hand but took a lot of time. As a sign of his accomplishment he left a note on the vault stating the pattern. You were the first officer on the crime scene and you've obtained the note. So if you can figure out A from (A-B), you can rob the bank very quick!
By the way, Mark succeeded in robbing the bank but had a heart attack on the getaway car and crashed.
Input
Input starts with an integer T (≤ 500), denoting the number of test cases.
Each line contains a single positive integer between 10 and 1018 (inclusive), giving the value of A-B.
Output
For each case, print the case number and the possible values of A in ascending order. Separate consecutive numbers with a single space.
Sample Input |
Output for Sample Input |
4 31 18 12 17 |
Case 1: 34 Case 2: 19 20 Case 3: 13 Case 4: 18 |
题意:给出A-B,求A, B为A去掉最后一位形成的数。
分析:B = A / 10, 设A的最后一位为x, A-B的值为n(已知), B * 10 + x - B = n, 即9 * B = n - x; 而 x的取值为0 到9. A = (n - x)* 10 / 9 + x。
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
typedef unsigned long long ll;///注意是无符号位长整型,有符号位长整型会溢出。
#define N 100
using namespace std;
ll n;
int main()
{
int T, cas;
ll a[N];
scanf("%d", &T);
cas = 0;
while(T--)
{
cas++;
memset(a, 0, sizeof(a));
scanf("%llu", &n);
int k = 0;
for(int i = 0; i <= 9; i++)
{
if((n - i) % 9 == 0)
a[k++] =(n-i)*10/9 + i;
}
sort(a, a+k);///输出要求按升序排列。
k = unique(a, a+k) - a;///类属性算法unique的作用是从输入序列中“删除”所有相邻的重复元素。
printf("Case %d:", cas);
for(int i = 0; i < k; i++)
printf(" %llu", a[i]);
printf("\n");
}
return 0;
}
1163 - Bank Robbery的更多相关文章
- LightOj 1163 - Bank Robbery(x-x/10 = n求所有的 x )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1163 题意:有一个数A,然后去掉A的最后一位得到B,先告诉你A-B的值,求所有满足条件 ...
- Codeforces Round #414 A. Bank Robbery
A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megabytes A robber has a ...
- Bank Robbery LightOJ - 1163(推方程 注意计算机的计算方式)
题意:一个数A,如果A去掉它的最后一位就变成了B,即B=A/10,给A - B,求A #include <iostream> #include <cstdio> #includ ...
- 【codeforces 794A】Bank Robbery
[题目链接]:http://codeforces.com/contest/794/problem/A [题意] 每个位置上可能有物品(>=1)或是没物品 你一开始在某一个位置b; 然后你最左可以 ...
- Hdu 2955 Robberies 0/1背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- DP专题训练之HDU 2955 Robberies
打算专题训练下DP,做一道帖一道吧~~现在的代码风格完全变了~~大概是懒了.所以.将就着看吧~哈哈 Description The aspiring Roy the Robber has seen a ...
- HDU2955 Robberies[01背包]
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2955(0-1背包问题)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/M 题目: Description The aspir ...
- HDU2955 背包DP
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- Spring学习记录1——IoC容器
IoC容器 1.1 IoC概述 Ioc(Inverse of Control,控制反转)是Spring容器的内核.对于软件来说,即某一接口具体实现类的选择控制权从调用类中移除,转交给第三方决定,即由 ...
- 深夜话题boot2docker还有那些隐藏MENU
马克思的博士论文:自由意识的集中表达 --字体我设为5(18pt),你们懂的 总有人埋汰,终于我想起一个负负得正的话题 为什么放在深夜,因为希望看到的人越少越好,深夜是时差党的乐园 本篇作为之前几篇围 ...
- AVR单片机教程——定时器中断
本文隶属于AVR单片机教程系列. 中断,是单片机的精华. 中断基础 当一个事件发生时,CPU会停止当前执行的代码,转而处理这个事件,这就是一个中断.触发中断的事件成为中断源,处理事件的函数称为中断 ...
- 5.Switch多选择结构
Switch语句: 多选择结构还有一个实现方式就是 switch case 语句 switch case 语句判断一个变量与一系列值中的某个值是否相等,每个值称为一个分支. switch语句中的变量类 ...
- 在eclipse中用java调用python报错 Exception in thread "main" ImportError: Cannot import site module and its dependencies
最近做项目需要用java调用python,配置了jython后,运行了例子代码: 获得一个元组里面的元素: import org.python.util.PythonInterpreter; publ ...
- 生成URL(而不是链接) Generating URLs (and Not Links) | 在视图中生成输出URL |高级路由特性 | 精通ASP-NET-MVC-5-弗瑞曼
结果呢:
- Isx个人第4次作业—Alpha项目测试
标题 内容 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience 这个作业要求在哪里 https:// ...
- Nginx-入门(源码编译安装http://nginx.org/en/download.html)
比较早的时候 web主要经典组合--->LAMP 近几年---->nginx后来居上--->LNMP=LEMP Nginx = Engine x Nginx和Apache 都是 ...
- python+selenium爬取百度文库不能下载的word文档
有些时候我们需要用到百度文库的某些文章时,却发现需要会员才能下载,很难受,其实我们可以通过爬虫的方式来获取到我们所需要的文本. 工具:python3.7+selenium+任意一款编辑器 前期准备:可 ...
- FFMPEG结构体分析:AVCodecParameters
/** * This struct describes the properties of an encoded stream. * * sizeof(AVCodecParameters) is no ...