题意:在这个20×20方阵中,四个在同一方向(从下至上、从上至下、从右至左、从左至右或者对角线)上相邻的数的乘积最大是多少?

思路:暴力去枚举以 ( x , y ) 为中心拓展的四个方向


/*************************************************************************
> File Name: euler011.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月25日 星期日 09时35分02秒
************************************************************************/ #include <stdio.h>
#include <inttypes.h> #define MAX_N 26
#define max(a,b) a > b ? a : b void input_mat(int32_t mat[][MAX_N]) {
for(int32_t i = 3 ; i < 23 ; i++) {
for(int32_t j = 3 ; j < 23 ; j++) {
scanf("%d",&mat[i][j]);
}
}
}
void solve(int32_t mat[][MAX_N]) {
int32_t ans = 0;
int32_t dx[4] = { 0 , 1 , 1 , 1 } , dy[4] = { 1 , 0 , 1 , -1 }; // 定义方向数组
for(int32_t i = 3 ; i < 23 ; i++){
for(int32_t j = 3 ; j < 23 ; j++){
for(int32_t num = 0 ; num < 4 ; num++){ // 四个方向进行遍历
int32_t p = mat[i][j];
for(int32_t k = 1 ; k < 4 ; k++){
p *= mat[ i + k*dx[num] ][ j + k*dy[num] ];
}
ans = max( ans , p );
}
}
}
printf("%d\n",ans);
}
int32_t main() {
int32_t mat[MAX_N][MAX_N] = {0};
freopen("PE11input.txt","r",stdin); input_mat(mat);
solve(mat);
return 0;
}

Project Euler 11 Largest product in a grid的更多相关文章

  1. Project Euler 8 Largest product in a series

    题意:寻找这 1000 个数中相邻 13 个数相乘积最大的值 思路:首先想到的是暴力,但是还可以利用之前记录过的数值,什么意思呢?即在计算 2 - 14 后,再计算 3 - 15 时完全可以利用之前计 ...

  2. R语言学习——欧拉计划(11)Largest product in a grid

    Problem 11 In the 20×20 grid below, four numbers along a diagonal line have been marked in red. 08 0 ...

  3. Largest product in a grid

    这个比前面的要复杂点,但找对了规律,还是可以的. 我逻辑思维不强,只好画图来数数列的下标了. 分四次计算,存入最大值. 左右一次,上下一次,左斜一次,右斜一次. In the 2020 grid be ...

  4. Project Euler 99:Largest exponential 最大的幂

    Largest exponential Comparing two numbers written in index form like 211 and 37 is not difficult, as ...

  5. Project Euler Problem 8-Largest product in a series

    直接暴力 写完才想到,代码写矬了,扫一遍就出结果了,哪还用我写的这么麻烦 ss = '''73167176531330624919225119674426574742355349194934 9698 ...

  6. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  7. 【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 × ...

  8. [project euler] program 4

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

  9. Python练习题 036:Project Euler 008:1000位数字中相邻13个数字最大的乘积

    本题来自 Project Euler 第8题:https://projecteuler.net/problem=8 # Project Euler: Problem 8: Largest produc ...

随机推荐

  1. 转载 - Tarjan算法(求SCC)

    出处:http://blog.csdn.net/xinghongduo/article/details/6195337 说到以Tarjan命名的算法,我们经常提到的有3个,其中就包括本文所介绍的求强连 ...

  2. 洛谷—— P1041 传染病控制

    https://www.luogu.org/problem/show?pid=1041 题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜 ...

  3. Java&amp;&amp;(面试题)初始化顺序总结

    1  无继承情况下的Java初始化顺序: class Sample {       Sample(String s)       {             System.out.println(s) ...

  4. JavaScript高级特性之原型

    JavaScript的原型 原型prototype属性仅仅适用于函数对象(这里的函数对象是自己为了理解更好定义的,普通对象是没有原型属性的) 1.研究函数原型: <script type=&qu ...

  5. luogu1908 逆序对 树状数组

    题目大意:对于给定的一段正整数序列,逆序对就是序列中ai>aj且i<j的有序对.求一段序列的逆序对数. 对于一个数组T,其一个点的值为值与该点下标相等的A序列中点的个数.对T维护一个树状数 ...

  6. 【Codeforces 258D】 Count Good Substrings

    [题目链接] http://codeforces.com/contest/451/problem/D [算法] 合并后的字符串一定是形如"ababa","babab&qu ...

  7. Linux&nbsp;Oracle服务启动&amp;停止脚本与开机自启动

    在CentOS 6.3下安装完Oracle 10g R2,重开机之后,你会发现Oracle没有自行启动,这是正常的,因为在Linux下安装Oracle的确不会自行启动,必须要自行设定相关参数,首先先介 ...

  8. Python中断言与异常的区别

    异常,在程序运行时出现非正常情况时会被抛出,比如常见的名称错误.键错误等. 异常: >>> s Traceback (most recent call last): File &qu ...

  9. Codeforces 680D Bear and Tower of Cubes 贪心 DFS

    链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...

  10. 2015 多校赛 第一场 1002 (hdu 5289)

    Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...