HDOJ 1334 Perfect Cubes(暴力)
Problem Description
For hundreds of years Fermat’s Last Theorem, which stated simply that for n > 2 there exist no integers a, b, c > 1 such that a^n = b^n + c^n, has remained elusively unproven. (A recent proof is believed to be correct, though it is still undergoing scrutiny.) It is possible, however, to find integers greater than 1 that satisfy the “perfect cube” equation a^3 = b^3 + c^3 + d^3 (e.g. a quick calculation will show that the equation 12^3 = 6^3 + 8^3 + 10^3 is indeed true). This problem requires that you write a program to find all sets of numbers {a, b, c, d} which satisfy this equation for a <= 200.
Output
The output should be listed as shown below, one perfect cube per line, in non-decreasing order of a (i.e. the lines should be sorted by their a values). The values of b, c, and d should also be listed in non-decreasing order on the line itself. There do exist several values of a which can be produced from multiple distinct sets of b, c, and d triples. In these cases, the triples with the smaller b values should be listed first.
The first part of the output is shown here:
Cube = 6, Triple = (3,4,5)
Cube = 12, Triple = (6,8,10)
Cube = 18, Triple = (2,12,16)
Cube = 18, Triple = (9,12,15)
Cube = 19, Triple = (3,10,18)
Cube = 20, Triple = (7,14,17)
Cube = 24, Triple = (12,16,20)
Note: The programmer will need to be concerned with an efficient implementation. The official time limit for this problem is 2 minutes, and it is indeed possible to write a solution to this problem which executes in under 2 minutes on a 33 MHz 80386 machine. Due to the distributed nature of the contest in this region, judges have been instructed to make the official time limit at their site the greater of 2 minutes or twice the time taken by the judge’s solution on the machine being used to judge this problem.
题意:n在[2,200]的范围,都是整数
找出所有的n*n*n=a*a*a+b*b*b+c*c*c;
(<2a<=b<=c<200)
直接暴力做!
注意的只有格式:=号两边都有空格,第一个逗号后面有一个空格。
public class Main{
public static void main(String[] args) {
for(int m=6;m<=200;m++){
int mt = m*m*m;
int at;
int bt;
int ct;
for(int a=2;a<m;a++){
at=a*a*a;
for(int b=a;b<m;b++){
bt = b*b*b;
//适当的防范一下,提高效率
if(at+bt>mt){
break;
}
for(int c=b;c<m;c++){
ct=c*c*c;
//适当的防范一下,提高效率
if(at+bt+ct>mt){
break;
}
if(mt==(at+bt+ct)){
System.out.println("Cube = "+m+", Triple = ("+a+","+b+","+c+")");
}
}
}
}
}
}
}
HDOJ 1334 Perfect Cubes(暴力)的更多相关文章
- poj 1543 Perfect Cubes(注意剪枝)
Perfect Cubes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14901 Accepted: 7804 De ...
- OpenJudge 2810(1543) 完美立方 / Poj 1543 Perfect Cubes
1.链接地址: http://bailian.openjudge.cn/practice/2810/ http://bailian.openjudge.cn/practice/1543/ http:/ ...
- POJ 1543 Perfect Cubes
Perfect Cubes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12595 Accepted: 6707 De ...
- poj 1543 Perfect Cubes (暴搜)
Perfect Cubes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15302 Accepted: 7936 De ...
- ZOJ Problem Set - 1331 Perfect Cubes 判断一个double是否为整数
zju对时间要求比较高,这就要求我们不能简单地暴力求解(三个循环搞定),就要换个思路:因为在循环时,已知a,确定b,c,d,在外重两层循环中已经给定了b和c,我们就不用遍历d,我们可以利用d^3=a^ ...
- poj1543-Perfect Cubes(暴力)
水题:求n^3 = a^3 + b^3 + c^3 ;暴力即可 #include<iostream> using namespace std; int main(){ int n ; c ...
- UVaLive 3401 Colored Cubes (暴力)
题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...
- A. The Fault in Our Cubes 暴力dfs
http://codeforces.com/gym/101257/problem/A 把它固定在(0,0, 0)到(2, 2, 2)上,每次都暴力dfs检查,不会超时的,因为规定在这个空间上,一不行, ...
- 【题解】「SP867」 CUBES - Perfect Cubes
这道题明显是一道暴力. 暴力枚举每一个 \(a, b, c, d\) 所以我就写了一个暴力.每个 \(a, b, c, d\) 都从 \(1\) 枚举到 \(100\) #include<ios ...
随机推荐
- Android Studio中自己定义快捷输入块
快捷键:Ctrl + Alt + s,进入Settings >Editor>Live Templates>output中加入一个项,选择第一个Live Template waterm ...
- android 使用String.format("%.2f",67.876)自已定义语言(俄语、西班牙语)会把小数点变为逗号
市场人员反映公司的app使用系统设置俄语.西班牙语,double数据会把小数点变为逗号.调试一下,是自定义的语言时候(例如,俄语.西班牙语)转换String.format("%.2f&quo ...
- linux命令之partprobe
使用fdisk工具只是将分区信息写入到磁盘,如果需要使用mkfs格式化并使用分区,则需要重新启动系统.partprobe 是一个可以修改kernel中分区表的工具,可以使kernel重新读取分区表而不 ...
- linux telnet服务安装与配置
关闭防火墙:service iptabls stop chkconfig iptabls off 1.安装telnet服务 [root@rheltest1 ~]# rpm -qa ...
- Interpolator 插值器
简介 Interpolator:撺改者,校对机,分类机,插补器 Interpolator 定义了动画的变化速度,可以实现匀速.正加速.负加速.无规则变加速等,这使得基本的动画得以实现加速.减速等效果. ...
- 06-自定义Attribute标记案例
自定义Attribute: 1)Attribute都从System. Attribute类继承,类名一般以Attribute结尾 2) 标记类的用途—AttributeUsage标记(标记的标记):A ...
- CSS权威指南学习笔记系列(1)CSS和文档
题外话:HTML是一种结构化语言,而CSS是它的补充:这是一种样式语言.CSS是前端三板斧之一,因此学习CSS很重要.而我还是菜鸟,所以需要加强学习CSS.这个是我学习CSS权威指南的笔记,如有不对, ...
- apache的500错误是写到哪个文件里面
apache的500错误是写到哪个文件里面
- [php基础]Mysql日期函数:日期时间格式转换函数详解
在PHP网站开发中,Mysql数据库设计中日期时间字段必不可少,由于Mysql日期函数输出的日期格式与PHP日期函数之间的日期格式兼容性不够,这就需要根据网站实际情况使用Mysql或PHP日期转换函数 ...
- BitmapImage使用FileStream读取文件
var bitmapImage = new BitmapImage(); using (FileStream fs = new FileStream(file.FullName, FileMode.O ...