Pairs of Integers
Pairs of Integers
Input
Output
Example
| input | output |
|---|---|
302 |
5 |
//题意是,给出一个数,问有哪些数少掉某一位,与原数相加可得这个数,列出所有情况,第一个加数不能有前导 0 ,后一个可以有,
还有,重复的情况只能输出一个 比如 455 + 55 = 510 去掉 455 第一个5,和第二个5都能得510 ,只要输出一次就可以了
//做过类似的题目,用数学方法做,比较快。http://www.cnblogs.com/haoabcd2010/p/5991009.html
不过这题有点不一样,要按第一个数大小排序,还要去掉重复的,还要记得在第二个加数可能要补0 ,不过这都是些小问题。。。
15ms 比较快
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std; struct Num
{
int a,b;
int z;
}num[];
int t; bool cmp(Num x,Num y)
{
return x.a<y.a;
} void read(int x,int y)
{
int a=x,b=y;
int lenx=,leny=;
while (a!=)
{
lenx++;
a/=;
}
while (b!=)
{
leny++;
b/=;
}
if (y==) leny=;
num[t].a=x;
num[t].b=y;
num[t].z=lenx--leny;
t++;
} int main()
{
int N;
while (scanf("%d",&N)!=EOF)
{
t=;
for (int i=;i<=N;i*=)
{
int a=N/i/;
int b=N/i%; if (b<)
{
int c=(N-N/i*i)/;
if ((*a+b)*i+*c==N)
read( (*a+b)*i+c , a*i+c );
}
b--;
if (a+b&&b>=)
{
int c=(N-N/i*i+i)/;
if ((*a+b)*i+*c==N)
read( (*a+b)*i+c , a*i+c );
}
}
sort(num,num+t,cmp);
int real_t=;
for (int i=;i<t;i++)
{
if (i!=&&num[i].a==num[i-].a) continue;
real_t++;
}
printf("%d\n",real_t);
for (int i=;i<t;i++)
{
if (i!=&&num[i].a==num[i-].a) continue;
printf("%d + ",num[i].a);
for (int j=;j<num[i].z;j++)
printf("");
printf("%d = %d\n",num[i].b,N);
}
}
return ;
}
Pairs of Integers的更多相关文章
- POJ 1117 Pairs of Integers
Pairs of Integers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4133 Accepted: 1062 Des ...
- 2018牛客网暑期ACM多校训练营(第一场) J - Different Integers - [莫队算法]
题目链接:https://www.nowcoder.com/acm/contest/139/J 题目描述 Given a sequence of integers a1, a2, ..., an a ...
- Different Integers 牛客多校第一场只会签到题
Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, r2), ..., (lq, r ...
- 牛客暑假多校第一场J-Different Integers
一.题目描述: 链接:https://www.nowcoder.com/acm/contest/139/JGiven a sequence of integers a1, a2, ..., an an ...
- 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)
链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...
- Codeforces Round #562 (Div. 2) B. Pairs
链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...
- Different Integers 牛客网暑期ACM多校训练营(第一场) J 离线+线状数组或者主席树
Given a sequence of integers a1, a2, ..., an and q pairs of integers (l 1, r1), (l2, r2), ..., (lq, ...
- Different Integers
牛客一 J题 树状数组 题目描述 Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, ...
- Vector Tile
Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...
随机推荐
- git学习——记录每次更新到仓库
记录每次更新到仓库 工作目录下面的所有文件都不外乎这两种状态:已跟踪或未跟踪.已跟踪的文件是指本来就被纳入版本控制管理的文件,在上次快照中有它们的记录,工作一段时间后,它们的状态可能是未更新,已修改或 ...
- Unity3D 中脚本执行的先后顺序
Unity3D本身自带有控制脚本执行先后顺序的方法: Edit ---> Project Settings ---> Script Execution Order ---> 值越小 ...
- Input.GetAxis 获取轴
static function GetAxis (axisName : string) : float Description描述 Returns the value of the virtual a ...
- spring拦截器不拦截方法名原因
开发一个基于注解的登录拦截器,遇到拦截器只能拦截controller不能拦截到具体的方法名,这样拦截器就完全没用,经过仔细摸索,DefaultAnnotationHandlerMapping和Anno ...
- STL学习笔记(第二章 C++及其标准程序库简介)
本章重点是介绍与C++标准程序库相关的几个最重要的语言新特性 template(模板) 程序库中几乎所有东西都被设计成template形式.所谓templates,是针对“一个或多个尚未明确的型别”所 ...
- Websphere: Stop Server and Uninstall Application
In WAS, stopping server and uninstalling application are important steps to re-deploy. SET ProfileLo ...
- 【BIEE】08_修改浏览器标题栏显示内容
打开分析,我们可以看到标题栏中显示的BIEE默认的,现在想要把这个修改为自定义的 打开文件路径: D:\obiee\Oracle_BI1\bifoundation\web\msgdb\l_zh-CN\ ...
- 【Excle数据透视表】如何将行字段中的某个项目拖动到第一行显示
如下图:需要把上海放到第一显示 步骤 方法一: 单击"地区"下的"上海"→鼠标移动到单元格边框处→鼠标变成四向箭头→向上拖拽 方法二: 单击单元格A5→编辑区域 ...
- 51单片机 | 实现SMG12864液晶显示器操作
———————————————————————————————————————————— SMG12864液晶显示器 128*64个点位,可以显示图形或8*4个汉字 - - - - - - - - - ...
- Java学习从入门到精通(2) [转载]
Java Learning Path(二).书籍篇 学习一门新的知识,不可能指望只看一本,或者两本书就能够完全掌握.需要有一个循序渐进的阅读过程.我推荐Oreilly出版的Java系列书籍. 在这里我 ...