hduacm 5255
http://acm.hdu.edu.cn/showproblem.php?pid=5255
枚举a和c 求解b
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <algorithm>
using namespace std ; typedef long long LL ; #define clr( a , x ) memset ( a , x , sizeof a )
#define ls ( o << 1 )
#define rs ( o << 1 | 1 )
#define lson ls , l , m
#define rson rs , m + 1 , r
#define mid ( ( l + r ) >> 1 )
#define root 1 , 1 , n const int L = ; LL p[] ;
LL S[L] , top ; LL gcd ( LL a , LL b ) {
return b ? gcd ( b , a % b ) : a ;
} LL f ( LL pp , LL a , LL c , LL x1 , LL y1 ) {
LL x = a * pp * x1 - c * pp * y1 + c * x1 - a * y1 ;
LL y = ( y1 - x1 ) * ;
if ( x == ) return ;
else if ( x > && y < || x < && y > ) return - ;
else {
if ( x % y ) return - ;
else return x / y ;
}
} char s[] ; void solve () {
int x = , y = , loc = ;
top = ;
scanf ( "%s" , s ) ;
int n = strlen ( s ) ;
for ( int i = ; i < n ; ++ i ) {
if ( s[i] >= '' ) {
x = x * + s[i] - '' ;
if ( loc ) y *= ;
} else loc = ;
}
int g = gcd ( x , y ) ;
int x1 = x / g ;
int y1 = y / g ;
for ( int i = ; i <= ; ++ i ) {
for ( int a = ; a <= ; ++ a ) {
for ( int c = ; c <= ; ++ c ) {
LL b = f ( p[i] , a , c , x1 , y1 ) ;
if ( b < || b * >= p[i] ) continue ;
LL t = a * p[i] + b * + c ;
S[top ++] = t ;
}
}
}
printf ( "%d\n" , top ) ;
sort ( S , S + top ) ;
for ( int i = ; i < top ; ++ i ) {
printf ( "%I64d%c" , S[i] , i < top - ? ' ' : '\n' ) ;
}
} int main () {
int T ;
p[] = ;
for ( int i = ; i <= ; ++ i ) {
p[i] = p[i - ] * ;
}
scanf ( "%d" , &T ) ;
for ( int i = ; i <= T ; ++ i ) {
printf ( "Case #%d:\n" , i ) ;
solve () ;
}
return ;
}
hduacm 5255的更多相关文章
- 5255 -- 【FJOI2016】神秘数
5255 -- [FJOI2016]神秘数 Description 一个可重复数字集合\(S\) 的神秘数定义为最小的不能被 \(S\) 的子集的和表示的正整数.例如: \(S = {1,1,1,4, ...
- 数学 2015百度之星初赛2 HDOJ 5255 魔法因子
题目传送门 /* 数学:不会写,学习一下这种解题方式:) 思路:设符合条件的数的最高位是h,最低位是l,中间不变的部分为mid,由题意可得到下面的公式(这里对X乘上1e6用a表示,b表示1e6) (h ...
- hdu-acm steps 命运
/*表示刚刚接触dp.这是我接触到的第3道dp题,刚开始以为是要用dfs+dp,后来栈溢出...仔细想想, 其实这道题和数塔差不多,只要每步都得到最优子结构,最后结果一定是最优的.题目的初始化要做好, ...
- hdu-acm steps 免费馅饼
/*dp入门级的题目,和数塔是一样的,这道题不用做什么优化,感觉时间复杂度不会超.主要还是细节上的问题, 这道题的状态和状态方程都容易找到,采用自底向上的方式会好很多*/ #include" ...
- hdu-acm steps Common Subsequence
/*这道题是很明显的dp题,状态方程有点不大好想,也许是我刚刚接触dp的缘故吧.dp[i][j]表示字符串s1取前i个字符s2取前j个字符时最大公共子序列的大小,这样的如果s1[i]==s2[j],d ...
- hdu-acm steps Max sum
/*求最大字段和,d[i]表示已 i 结尾(字段和中包含 i )在 a[1..i] 上的最大和,d[i]=(d[i-1]+a[i]>a[i])?d[i-1]+a[i]:a[i];max = {d ...
- hdu-acm steps Monkey and Banana
这道题是典型的dp题.首先是数据的处理上,因为每个长方体的3条不同长度的棱都可以作为高,因此一个长方体可以看成3个不同的长方体.从而将数据扩展为3*n,然后将所有的长方体以长度为第一排序条件,宽度为第 ...
- hdu-acm stepsHumble Numbers
这是我做的第六道动态规划水题,对动态规划差不多有了一个大致的概念.动态规划有几个关键因素,第一是最优子结构,第二是状态和状态转移方程.整个过程都是以 最优 为中心的.因此在状态转移方程中常涉及到几 ...
- hdu-acm steps FatMouse's Speed
本想用暴力法先试试的,案例和自己找的数据都过掉了,但是始终wa,本来期待的是tle,结果始终wa.所以也就懒的管了,直接用dp来做了.主要是因为最近在刷暴力法和dp这两个专题,所以才想好好利用一下这道 ...
随机推荐
- HBase介绍及简易安装(转)
HBase介绍及简易安装(转) HBase简介 HBase是Apache Hadoop的数据库,能够对大型数据提供随机.实时的读写访问,是Google的BigTable的开源实现.HBase的目标是存 ...
- [转载] 对象存储(2):OpenStack Swift——概念、架构与规模部署
原文: http://www.testlab.com.cn/Index/article/id/1085.html#rd?sukey=fc78a68049a14bb228cb2742bdec2b9498 ...
- 使用xml方式定义补间动画
在res下创建一个目录 anim目录 public class MainActivity extends Activity { private ImageView iv; @Override prot ...
- Command设计模式
1 意图:将一个请求封装为一个对象,可以用不同的请求对客户进行参数化: 对请求排队或记录请求日志,以及支持可撤销的操作. 2 别名:Action.Transaction 3 动机:把请求变成一个对象. ...
- (转)TCP、UDP、IP协议
原文地址:http://blog.chinaunix.net/uid-26833883-id-3627644.html 互连网早期的时候,主机间的互连使用的是NCP协议.这种协议本身有很多缺陷,如 ...
- 什么是cname a记录
https://support.dnsimple.com/articles/cname-record/ CNAME就是别名记录,就是负责跳转,比如你给某个地址设置了一个cname,那当访问那个cnam ...
- 多重比对multiple alignment
之前只接触过双序列比对,现在需要开始用多序列比对了. 基本概念:多序列比对 - 百科 常用的 multiple alignment 软件: Muscle ClustalW T-coffee 软件之间的 ...
- 【转】android fragment 博客 学习
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37970961 自从Fragment出现,曾经有段时间,感觉大家谈什么都能跟Fra ...
- 联想手机#P1来了#P1背后的故事系列
http://bbs.lenovo.com/forum.php?mod=viewthread&fid=928&tid=560992&extra=page%3D1 联想手机#P1 ...
- 配置NGReport 报告中文
1. 测试报告的名称 在测试开始或测试监听器的类中加上下面一句代码即可: System.setProperty("org.uncommons.reportng.title", &q ...