题意:在这个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. 进入全屏 nodejs+express+mysql实现restful风格的增删改查示例

    首先,放上项目github地址:https://github.com/codethereforam/express-mysql-demo 一.前言 之前学的java,一直用的ssm框架写后台.前段时间 ...

  2. wifi断线问题

    近期在项目中,遇到wifi常常断线现象,平台是Android平台,现象是:连接wifi后,长时间播放视频,会出现wifi断开,界面上WiFi图标显示打叉,请问有WiFi方面的行家朋友,有没有办法来检測 ...

  3. oc24--description

    // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject { int _age; double ...

  4. Android ADB 常用命令

    Android ADB 常用命令 泛原罪 2016.09.21 00:02* 字数 605 阅读 2912评论 0喜欢 1 [TOC] adb logcat 查看日志 详细内容可参见 ADB Usag ...

  5. Adding a view

    在添加View之前,之前的页面是下面这个样子,需要注意的是浏览器标题,以及浏览器的内容 https://docs.asp.net/en/latest/tutorials/first-mvc-app/a ...

  6. 【BZOJ 2982】 combination

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2982 [算法] lucas定理 [代码] #include<bits/stdc ...

  7. sublime界面主题

    一直以来都是使用的SUBLIME,真的很强大. 最近刚转到linux来学习C,把它重新配置了一遍,默认的字体颜色的搭配已经很不错了.不过界面的样子还是不太习惯.重新安装了下soda这个主题包,惭愧!即 ...

  8. Wannafly挑战赛25 B 面积并 数学

    题面 题意:有一个正n边形,它的外接圆的圆心位于原点,半径为l .以原点为圆心,r为半径作一个圆,求圆和这个正n边形的面积并.3<=n<=1e8  1<=l<=1e6 0< ...

  9. C - Queue at the School

    Problem description During the break the schoolchildren, boys and girls, formed a queue of n people ...

  10. jqGrid 排序

    jqgrid 排序: 1.前台和后台交互依靠的是index属性,index属性没有设置情况下获取name属性 2.如下状态是经过处理显示的中文,name属性为StatusStr,没有index属性的情 ...