首页 > ACM题库 > HDU-杭电 > HDU 3816-To Be NUMBER ONE[解题报告]HOJ
2015
04-13

HDU 3816-To Be NUMBER ONE[解题报告]HOJ

To Be NUMBER ONE

问题描述 :

One is an interesting integer. This is also an interesting problem. You are assigned with a simple task.
Find N (3 <= N <= 18) different positive integers Ai (1 <= i <= N), and
Stones

Any possible answer will be accepted.

输入:

No input file.

输出:

No input file.

样例输出:

2 3 6
2 4 6 12

/**
[math] hdu 3816 to be no. one
一道没有输入的spj的计算,老是感觉代码写的好搓
1/n= 1/(a*b)=1/a*(a+b) + 1/b*(a+b)

*/
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;
int f[19][19] = {{},{},{},{0,2,3,6}};
void cal(int k,int &a,int &x,int &y)
{
	int i,j,b,m;
	for(i = 2; i < k; ++i)
	{
        m =sqrt(f[k][i] * 1.0);
        for(a = 1; a <= m; ++ a)
        if(f[k][i] % a == 0)
        {
            b = f[k][i] / a;
            if(a == b)
                continue;
            x = (a + b) * a;
            y = (a + b) * b;
            if(x > k * k || y > k * k)
                continue;
            for(j = 1; j <= k && f[k][j] != x && f[k][j] != y; ++j);
            if(j == k + 1){
                a = i;
                return ;
            }
        }
	}
}
int main(){
	int x = 0,y = 0,p = 0,i,j;
	for(i = 4; i <= 18; ++i){
		for(j = 1; j < i; ++j)
			f[i][j] = f[i-1][j];
		cal(i,p,x,y);
		f[i][p] = x;
		f[i][j] = y;
	}
	double res;
	for(i = 3;i < 19;++i){
	    sort(f[i]+1,f[i] + 1 + i);
	    res = 0.0;
		for(j = 1;j < i; ++j)
			printf("%d ",f[i][j]);
		printf("%d\n",f[i][j]);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/cscj2010/article/details/7878796


  1. 题本身没错,但是HDOJ放题目的时候,前面有个题目解释了什么是XXX定律。
    这里直接放了这个题目,肯定没几个人明白是干啥