1812

分析:

首先考虑枚举那些量,如果四个变量全部枚举,则肯定超时。

那么是枚举bcd呢,还是枚举其它?

输出要求:请按照a的值,从小到大依次输出。当两个完美立方等式中a的值相同,则b值小的优先输出、仍相同则c值小的优先输出、再相同则d值小的先输出。

据此最好按 abc的顺序枚举,其中a>c>=b.

另外次方的表示可以用pow函数,需要加头文件cmath

特别注意:n的1/3次方的表示方法 pow(n,1.0/3),结果为实数类型,在本题中需要将实数转换为整数,正确的做法是

int d = floor(pow(n,1.0/3)+0.1)加0.1的目的是防止浮点数的精确度问题。

说明:

floor是下取整函数结果是实数类型,而int也是下取整,但结果是整数类型:

比如:

printf("%lf\n",floor(pow(216,1.0/3)));
       printf("%d\n",int(pow(216,1.0/3)+0.1));

#include<cstdio>
#include<cmath>
int main(){
    int n;
    scanf("%d",&n);
    for (int a=2;a<=n;a++)
        for (int b=2;b<a;b++)
            for(int c=b;c<a;c++){
                int d=floor(pow(a*a*a-(b*b*b+c*c*c),1.0/3)+0.1);
                //printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
                if (d>=c&&a*a*a==b*b*b+c*c*c+d*d*d) printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
            }
    printf("\n");
    return 0;
}

时间: 2024-08-09 02:08:49

1812的相关文章

csu 1812: 三角形和矩形 凸包

传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************************************************************** Problem: User: youmi Language: C++ Result: Accepted Time: Memory: ***********************************

spoj 1812 LCS2 - Longest Common Substring II (后缀自动机)

spoj 1812 LCS2 - Longest Common Substring II 题意: 给出最多n个字符串A[1], ..., A[n], 求这n个字符串的最长公共子串. 限制: 1 <= n <= 10 |A[i]| <= 1e5 思路: 和spoj 1811 LCS差不多的做法 把其中一个A建后缀自动机 考虑一个状态s, 如果A之外的其他串对它的匹配长度分别是a[1], a[2], ..., a[n - 1], 那么min(a[1], a[2], ..., a[n - 1]

spoj 1812

1812. Longest Common Substring II Problem code: LCS2 A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the set of lowercase letters. Substring, also called factor, is a consecutive sequence of characters o

SPOJ LCS2 1812. Longest Common Substring II

SPOJ Problem Set (classical) 1812. Longest Common Substring II Problem code: LCS2 A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the set of lowercase letters. Substring, also called factor, is a consecu

hdu 1812 Count the Tetris polya计数

哈哈哈,简单polya,公式自己推导. 不过这题需要用到大数,很久没写Java,调了好久. import java.math.*; import java.util.*; import java.io.*; public class Main{ public static void main(String args[]){ Scanner cin=new Scanner(System.in); int n; BigInteger c; while(cin.hasNextInt()) { BigI

spoj 1812 LCS2 - Longest Common Substring II (后缀自己主动机)

spoj 1812 LCS2 - Longest Common Substring II 题意: 给出最多n个字符串A[1], ..., A[n], 求这n个字符串的最长公共子串. 限制: 1 <= n <= 10 |A[i]| <= 1e5 思路: 和spoj 1811 LCS几乎相同的做法 把当中一个A建后缀自己主动机 考虑一个状态s, 假设A之外的其它串对它的匹配长度各自是a[1], a[2], ..., a[n - 1], 那么min(a[1], a[2], ..., a[n -

TECH: Getting a Stack Trace from a CORE file on Unix (文档 ID 1812.1)

修改时间:2013-4-8类型:BULLETIN Introduction ~~~~~~~~~~~~ This short article aims to explain how to get a stack trace from a core dump produced by any of the Oracle products on Unix platforms. By following the steps below you can provide Oracle Support with

1812: [Ioi2005]riv

1812: [Ioi2005]riv Time Limit: 10 Sec Memory Limit: 64 MB Submit: 635 Solved: 388 [Submit][Status][Discuss] Description 几乎整个Byteland王国都被森林和河流所覆盖.小点的河汇聚到一起,形成了稍大点的河.就这样,所有的河水都汇聚并流进了一条大河,最后这条大河流进了大海.这条大河的入海口处有一个村庄--名叫Bytetown 在Byteland国,有n个伐木的村庄,这些村庄都座

CSU 1812 三角形和矩形

湖南省第十二届大学生计算机程序设计竞赛$J$题 计算几何. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #

SPOJ 1812 LCS2 [后缀自动机]

题意: 求多个串<=10的最长连续子串 一个串建SAM,然后其他串在上面走 每个状态记录所有串在这个状态的公共子串的最小值 一个串在上面走的时候记录与每个状态公共子串的最大值,注意出现次数向父亲传递,一个状态能到达说明了Suffix Link指向的状态可以取到最大子串,这一步对val后基数排序然后倒着更新就行了 注意两点: 1.空间要开两倍,基数排序用的东西也要两倍哦 2.答案不能用mn[1]更新!!!!因为mn[1]没有意义啊root状态一个子串也没有还可能有某些bug #include <