【HDOJ】1271 整数对
枚举,假设这个数x=a*10^(i+1)+b*10^i+c,去掉b后y=a*10^i+c,x+y=n,则x+y=n(mod10^i),求出c,注意c<10^i,但2*c有可能大于10^i,因此分类后,加一些限制条件枚举可得。
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 105
int buf[MAXN]; int comp(const void *a, const void *b) {
return *(int *)a - *(int *)b;
} int main() {
int m, n;
int i, j, k, tmp;
int a, b, c; while (scanf("%d", &n)!=EOF && n) {
k = ;
for (m=,i=; i<; ++i) {
j = n%k;
if ((j&) == ) {
c = j>>;
// 11a+b = tmp;
tmp = n/k;
for (b=; b<; ++b) {
if ((tmp||b) && (tmp-b)% == ) {
a = (tmp-b)/;
buf[m++] = n-a*k-c;;
}
}
}
if (((j+k)&) == ) {
c = (j+k)>>;
// 11a+b+1 = tmp
tmp = n/k-;
for (b=; b<; ++b) {
if ((tmp||b) && (tmp-b)% == ) {
a = (tmp-b)/;
buf[m++] = n-a*k-c;
}
}
}
k *= ;
}
if (m == ) {
printf("No solution.\n");
} else {
qsort(buf, m, sizeof(int), comp);
printf("%d", buf[]);
for (i=; i<m; ++i) {
if (buf[i] != buf[i-])
printf(" %d", buf[i]);
}
printf("\n");
}
#ifndef ONLINE_JUDGE
fflush(stdout);
#endif
} return ;
}
【HDOJ】1271 整数对的更多相关文章
- hdu 1271 整数对
看了别人的解题报告a了, 大致思路就是 A=a+b*10^k+c*10^(k+1) B=a+c*10^k (在A中取出一位数后) N=A+B=2*a+b*10^k+11*c*10^k 这样就好做了,再 ...
- HDU 1271 整数对(思路题)
假设删除第k位,把整数A表示成如下形式: A = a * 10^(k+1) + b * 10 ^k + c; 则: B = a * 10^k + c; N = A + B = (11*a+b)*10^ ...
- ACM STEPS——Chapter Two——Section One
数学题小关,做得很悲剧,有几道题要查数学书... 记下几道有价值的题吧 The area(hdoj 1071) http://acm.hdu.edu.cn/showproblem.php?pid=10 ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- HDOJ 2561. 第二小整数 第k大问题
第二小整数 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDOJ/HDU 2561 第二小整数(水题~排序~)
Problem Description 求n个整数中倒数第二小的数. 每一个整数都独立看成一个数,比如,有三个数分别是1,1,3,那么,第二小的数就是1. Input 输入包含多组测试数据. 输入的第 ...
- HDOJ 2092 整数解(2次方程整数解公式)
Problem Description 有二个整数,它们加起来等于某个整数,乘起来又等于另一个整数,它们到底是真还是假,也就是这种整数到底存不存在,实在有点吃不准,你能快速回答吗?看来只能通过编程. ...
- 并查集(HDOJ 1856)
并查集 英文:Disjoint Set,即“不相交集合” 将编号分别为1…N的N个对象划分为不相交集合, 在每个集合中,选择其中某个元素代表所在集合. 常见两种操作: n 合并两个集合 ...
- HDOJ 1848 Fibonacci again and again
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
随机推荐
- Enterprise Architect使用教程
一.Enterprise Architect简介 Enterprise Architect是一个对于软件系统开发有着极好支持的CASE软件(Computer Aided Software Engine ...
- 线程、委托、lambda运算符的简单示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- android图片处理方法(转)
//压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArr ...
- Java基础知识强化之IO流笔记05:try...catch...finally包含的代码是运行期的
1. 代码示例: 上面看到的第13行: Date d = null;(这里必须初始化) 第14~20行使用try...catch...finally包含代码,这里的代码已经变成运行期代码.此时我们 ...
- Android中强大的Matrix操作
简介: Matrix翻译字面意思时矩阵,在Android的API中提供了两种Matrix,分别是android.graphics.Matrix 和 android.opengl.Matrix . 后者 ...
- C#解leetcode 16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- java常见错误的列表
ava常见错误列表: 找不到符号(symbol) 类X是public的,应该被声明在名为X.java的文件中 缺失类.接口或枚举类型 缺失X 缺失标识符 非法的表达式开头 类型不兼容 非法的方法声明; ...
- (转)PHP中构造函数和析构函数解析
--http://www.jb51.net/article/56047.htm 构造函数 void __construct ([ mixed $args [, $... ]] ) PHP 5 允行开发 ...
- 织梦dede自定义内容分页,datalist运用实例
在/plus文件夹中新建一个ceshi.php文件..<?php require(dirname(__FILE__)."/../include/common.inc.php" ...
- 总结Linux下查看流量工具
Linux服务器要查看带宽情况,可以使用nethogs.dstat.nload.iftop.ifstat工具. 而每个工具都有自己的特色,这里简单总结一下使用方法. 一.nethogs 查看这台设备上 ...