OpenJudge 2810(1543) 完美立方 / Poj 1543 Perfect Cubes
1.链接地址:
http://bailian.openjudge.cn/practice/2810/
http://bailian.openjudge.cn/practice/1543/
http://poj.org/problem?id=1543
2.题目:
Perfect Cubes
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13190 Accepted: 6995 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 <= N.Input
One integer N (N <= 100).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.Sample Input
- 24
Sample Output
- 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)
Source
3.思路:
枚举+打表(减少计算次数)
注意a要升序排列,然后b,c,d再升序排列
4.代码:
- #include <iostream>
- #include <cstdio>
- #define START_N 2
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- int *arr_cube = new int[n];
- int i,j,k,p;
- for(i = START_N; i <= n; ++i)
- {
- arr_cube[i - START_N] = i * i * i;
- for(j = START_N; j <= i; ++j)
- {
- for(k = j; k <= i; ++k)
- {
- for(p = k; p <= i; ++p)
- {
- if(arr_cube[i - START_N] == arr_cube[j - START_N]
- + arr_cube[k - START_N] + arr_cube[p - START_N])
- {
- cout<<"Cube = "<<i<<", Triple = ("<<j<<","<<k<<","<<p<<")"<<endl;
- }
- }
- }
- }
- }
- delete [] arr_cube;
- return ;
- }
OpenJudge 2810(1543) 完美立方 / Poj 1543 Perfect Cubes的更多相关文章
- 2810:完美立方-poj
2810:完美立方 总时间限制: 1000ms 内存限制: 65536kB 描述 形如a3= b3 + c3 + d3的等式被称为完美立方等式.例如123= 63 + 83 + 103 .编写一个 ...
- OpenJudge计算概论-完美立方【暂时就想到了枚举法了】
/*===================================== 完美立方 总时间限制: 1000ms 内存限制: 65536kB 描述 a的立方 = b的立方 + c的立方 + d的立 ...
- POJ 2810:完美立方
原题链接 总时间限制: 1000ms 内存限制: 65536kB 描述 形如\(a^{2}\)= \(b^{2}\) + \(c^{2}\) + \(d^{2}\)的等式被称为完美立方等式.例如123 ...
- poj 1543 Perfect Cubes(注意剪枝)
Perfect Cubes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14901 Accepted: 7804 De ...
- 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 ...
- Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)
Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配) Description 农夫约翰上个 ...
- OpenJ_Bailian 2810 完美立方
题目地址: https://vjudge.net/problem/OpenJ_Bailian-2810 形如a3= b3 + c3 + d3的等式被称为完美立方等式.例如123= 63 + 83 + ...
- Openjudge-计算概论(A)-完美立方
描述: a的立方 = b的立方 + c的立方 + d的立方为完美立方等式.例如12的立方 = 6的立方 + 8的立方 + 10的立方 .编写一个程序,对任给的正整数N (N≤100),寻找所有的四元组 ...
随机推荐
- JAVA线程全局异常处理
大家平时写线程很多,但可能很少关注如何捕获线程的全局异常.其实jdk提供了两种捕获全局异常的方法,一种是基于整个线程类(staticsetDefaultUnaughtExceptionHandler( ...
- bzoj 1800: [Ahoi2009]fly 飞行棋 暴力
1800: [Ahoi2009]fly 飞行棋 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...
- 使用Zipalign工具优化Android APK应用记录
生成的Android应用APK文件最好进行优化,因为APK包的本质是一个zip压缩文档,经过优化能使包内未压缩的数据有序的排列,从而减少应用程序运行时的内存消耗.我们可以使用Zipalign工具进行A ...
- 【转贴】gdb中的信号(signal)相关调试技巧
一篇不错的帖子,讲的是gdb中的信号(signal)相关调试技巧 转自Magic C++论坛 http://www.magicunix.com/index_ch.html http://www.m ...
- SAP交货单过账自动生产采购订单、采购订单自动收货入库
公司间需要买卖操作,由于发货和收货都是同一批人在操作,为了减少业务人员的工作量,提高工作效率,特实现以上功能 1.增强实现:增强点为交货单过账成功时触发,在提交前触发,如果遇到不可预知问题,可能造成数 ...
- PAT 1014
1014. Waiting in Line (30) Suppose a bank has N windows open for service. There is a yellow line in ...
- eclipse安装android sdk后工具栏没有图标的设置
如果没有出现这android图标,选择'Window>Customize Perspective...>Commands',并在'Available command groups'中勾选' ...
- Google前工程经理王忻:如何准备软件工程师的面试
http://t.jobdu.com/thread-368-1-1.html 导读:原文作者王忻,Google前工程经理,2003年月加入Google,是Google Lively背后的主导力量,是G ...
- Java设计模式08:框架基础知识
1. 框架是什么 ? 框架是能完成一定功能的半成品软件.(不能直接使用,还需要再加工,所以叫半成品.比如:方便面) 2. 框架能干什么 ? (1)能完成一定的功能,加快程序开发进度. (2)给我们一个 ...
- 对比AppScan Source和Fortify扫描AltoroJ的结果
对比AppScan Source和Fortify扫描AltoroJ的结果: http://blog.csdn.net/testing_is_believing/article/details/1963 ...