这题先是推公式…

狂用不完全归纳+二次回归,最后推出这么一个奇怪的公式

\[f(t,x,y,z)=4(t-1)(x+y+z+t-2)+2(xy+yz+xz)\]

表示长宽高为\(x\)、\(y\)、\(z\)的立方体第\(t\)层放的立方体的个数。

接下来就是算答案了…

方法很简单:暴力

但是暴力还是有技巧的,开始我是直接从1到1000枚举\(t\)、\(x\)、\(y\)、\(z\),但这样出不来结果。

换成下面代码里的方法就行了。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=;
int a[];
inline int f(int t,int x,int y,int z)
{
return *(t-)*(x+y+z+t-)+*(x*y+y*z+x*z);
}
int main(int argc, char *argv[])
{
freopen("1.out","w",stdout);
for(int x=;f(,x,x,x)<=maxn;x++)
for(int y=x;f(,x,y,y)<=maxn;y++)
for(int z=y;f(,x,y,z)<=maxn;z++)
for(int t=;f(t,x,y,z)<=maxn;t++)
a[f(t,x,y,z)]++;
for(int i=;i<=;i++)
printf("%d %d\n",i,a[i]);
return ;
}

Project Euler 126 - Cuboid layers的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  6. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  7. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  9. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. Frequent Values-线段树求解出现最多的数

    Frequent Values(poj 3368) 注意:以下答案为离线作答结果,并非能通过poj,若要通过poj,需要修改函数接口,因为以下程序接受半封闭区间(s,e],同时还需要修改输入数据的顺序 ...

  2. sqlite时间段查询

    同样的SQL语句,查不出数据来 select * from table1 where t1>='2017-6-1' and t1<='2017-6-5' 改成 select * from ...

  3. Ubuntu16.04安装postgresql9.4(转发:http://www.cnblogs.com/sparkdev/p/5678874.html)

    安装前的检查 首先查看是否已经安装了旧版本: dpkg -l |grep postgresql 如果已经安装了某个版本的postgresql,请先卸载. 安装postgresql 添加postgres ...

  4. Mysql查询结果导出为Excel的几种方法

    本文地址:http://www.cnblogs.com/qiaoyihang/p/6398673.html 具体原文找不到了,此篇是借鉴门户的一篇文章 方法一:查询语句直接输出语法格式: Exampl ...

  5. MySQL的搜索引擎,统一字符编码 和忘记MySQL密码如何破解

    忘记mysql密码 linux平台下,破解密码的两种方式 [root@egon ~]# rm -rf /var/lib/mysql/mysql #所有授权信息全部丢失!!! [root@egon ~] ...

  6. yii2查询数据倒序显示

    public function selectall(){ return $this->findBySql("SELECT * FROM article order by art_tim ...

  7. 微信小程序组件icon

    基础内容icon:官方文档 Demo Code Page({ data: { iconSize: [20, 30, 40, 50, 60, 70], iconColor: [ 'red', 'oran ...

  8. smarty内置函数

      1.{append} 追加 2.{assign} 赋值 3.{block} 块 4.{call} 调用 5.{capture}捕获 6.{config_load}用来从配置文件中加载config变 ...

  9. form:checkboxes radiobutton select用法

    <form:checkboxes path="subjects" items="${requestScope.subjects}" element=&qu ...

  10. Calendar的那些神坑

    参考我的博客:http://www.isedwardtang.com/2017/08/31/java-calendar-bug/