(Problem 62)Cubic permutations(待续)
The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.
Find the smallest cube for which exactly five permutations of its digits are cube.
题目大意:
立方数 41063625 (3453) 通过排列可以得到两个另外的立方数: 56623104 (3843) 和 66430125 (4053)。 实际上41063625是最小的三个(不多不少)排列是立方数的立方数。
找出最小的立方数,其五个(不多不少)排列是立方数。
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<stdlib.h> #define N 8000 typedef struct data {
long long n;
char na[];
}; struct data a[N]; int cmp1(const void * a, const void * b)
{
struct data * c = (struct data * )a;
struct data * d = (struct data * )b;
return strcmp(c ->na, d ->na);
} int cmp2(const void * a, const void * b)
{
return *(char *)a - *(char *)b;
} void solve()
{
int i, j;
long long t, min;
min = ;
for(i = , j = ; i < N; i++, j++) {
a[i].n = j * j * j;
sprintf(a[i].na, "%lld", a[i].n);
qsort(a[i].na, strlen(a[i].na), sizeof(char), cmp2);
}
qsort(a, N, sizeof(a[]), cmp1); for(int i = ; i < N; i++) {
if(strcmp(a[i].na, a[i + ].na) == && strcmp(a[i].na, a[i + ].na) == &&
strcmp(a[i].na, a[i + ].na) == && strcmp(a[i].na, a[i + ].na) == ) {
printf("%lld\n%lld\n%lld\n%lld\n%lld\n", a[i].n, a[i + ].n, a[i + ].n, a[i + ].n, a[i + ].n); }
}
//printf("%lld\n", min);
} int main()
{
solve();
return ;
}
(Problem 62)Cubic permutations(待续)的更多相关文章
- Project Euler 62: Cubic permutations
立方数\(41063625 (345^3)\)的各位数重新排列形成另外两个立方数\(6623104 (384^3)\)和\(66430125 (405^3)\).事实上,\(41063625\)是满足 ...
- 欧拉工程第62题:Cubic permutations
题目链接 找出最小的立方数,它的各位数的排列能够形成五个立方数 解决关键点: 这五个数的由相同的数组成的 可以用HashMap,Key是由各位数字形成的key,value记录由这几个数组成的立方数出现 ...
- Project Euler problem 62
题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 ...
- POJ2369 Permutations(置换的周期)
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- [CC150] Get all permutations of a string
Problem: Compute all permutations of a string of unique characters. 此题用循环的方式不好做,下面是一种递归的思路: 把给的字符串看成 ...
- oj 1031 random permutation
Problem A: Random Permutations Time Limit: 1 Sec Memory Limit: 128 MB Submit: 91 Solved: 54 Descri ...
- List of NP-complete problems
This is a list of some of the more commonly known problems that are NP-complete when expressed as de ...
- 2009-2010 ACM-ICPC, NEERC, Western Subregional Contest
2009-2010 ACM-ICPC, NEERC, Western Subregional Contest 排名 A B C D E F G H I J K L X 1 0 1 1 1 0 1 X ...
- AtCoder Grand Contest 038 简要题解
从这里开始 比赛目录 Problem A 01 Matrix Code #include <bits/stdc++.h> using namespace std; typedef bool ...
随机推荐
- iOS 处理方法中的可变參数
## iOS 处理方法中的可变參数 近期写了一个自己定义的对话框的demo,想模仿系统的UIAlertView的实现方式.对处理可变參数的时候,遇到了小问题,于是谷歌了一下.写下了处理问题的方法.记录 ...
- python <tab>自动补全
1.获取python目录[我使用的是64位ubuntu系统] [~$]python Python 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] ...
- JavaScript之充实文档的内容
1.我们在平时的开发中会碰到一些缩略语如:XML,HTML,API等专业术语:为了能使用户,更好的了解术语的意思,我们通常会给<abbr></abbr>标签加一个title属性 ...
- param
页面之间值传递用param作为参数,提高网站安全性
- NSString 的常见方法
NSString的常用方法 创建一个新字符串并将其设置为 path 指定的文件的内容,使用字符编码enc,在error上返回错误 + (id)stringWithContentsOfURL:(NSUR ...
- iOS 证书那些事
关于开发证书配置(Certificates & Identifiers & Provisioning Profiles),相信做iOS开发的同学没少被折腾.对于一个iOS开发小白.半吊 ...
- 红豆带你从零学C#系列之——初识C#
问题一:什么是C#? C#是微软公司在2000年新推出的一款运行在.NET Framework平台上面的编程语言,这个.NET Framework平台又怎么去理解呢?举个例子来说好了,一个土著族人只会 ...
- 论try/catch的重要性,我们经常遇到代码出现无法调试的错误,程序退出的时候崩溃。这跟我们代码日常保护的习惯息息相关。
每当构造函数或析构函数中出现溢出,会导致调试非常困难,而使用try/catch来处理构造中的初始化就非常重要了. 如上图,在构造函数中,我们的很多初始化动作会放在这里,但是却忽视了,一旦初始化出错了, ...
- 用C++写一个简单的发布者
节点是一个可执行程序,它连接到了ROS的网络系统中.我们将会创建一个发布者,也就是说话者节点,它将会持续的广播一个信息. 改变目录到之前所建立的那个包下: cd ~/catkin_ws/src/beg ...
- memcached look status
$ STAT pid STAT STAT STAT version STAT pointer_size STAT rusage_user 7.054927 STAT rusage_system 14. ...