Project Euler 8 Largest product in a series
题意:寻找这 1000 个数中相邻 13 个数相乘积最大的值
思路:首先想到的是暴力,但是还可以利用之前记录过的数值,什么意思呢?即在计算 2 ~ 14 后,再计算 3 ~ 15 时完全可以利用之前计算 2~14的值再除以 2 乘上 15 ,但是因为其中有 0 的存在需要改造一下,记录下之前出现的 0 的个数,当这连续13个数有 0 存在的时候,结果自然是 0 直接忽略,当没 0 的时候更新一下 maxN 即可。
/*************************************************************************
> File Name: euler008.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月23日 星期五 22时41分02秒
************************************************************************/
#include "inputdata.h"
int32_t main(){
int64_t ans = 1 , zero = 0 , maxN = 0;
for(int32_t i = 0 ; i < 1000 ; i++){
if( ch[i] != '0' ){
ans *= ch[i] - '0';
}else{
++zero;
}
if( i >= 13 ){
if( ch[i-13] != '0' ){
ans /= ch[i-13] - '0';
}else{
--zero;
}
}
if( zero == 0 && ans > maxN ) maxN = ans;
}
printf("%"PRId64"\n",maxN);
return 0;
}
Project Euler 8 Largest product in a series的更多相关文章
- Project Euler 11 Largest product in a grid
题意:在这个20×20方阵中,四个在同一方向(从下至上.从上至下.从右至左.从左至右或者对角线)上相邻的数的乘积最大是多少? 思路:暴力去枚举以 ( x , y ) 为中心拓展的四个方向 /***** ...
- Project Euler Problem 8-Largest product in a series
直接暴力 写完才想到,代码写矬了,扫一遍就出结果了,哪还用我写的这么麻烦 ss = '''73167176531330624919225119674426574742355349194934 9698 ...
- 【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 × ...
- projecteuler Problem 8 Largest product in a series
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = ...
- Project Euler 99:Largest exponential 最大的幂
Largest exponential Comparing two numbers written in index form like 211 and 37 is not difficult, as ...
- Largest product in a series
这个我开始理解错了,算错了. 我以为是求连续5个数的最大值,结果,是连接5个数相乘的最大值. 英语不好,容易吃亏啊. Find the greatest product of five consecu ...
- Problem 8: Largest product in a series
先粘实现代码,以后需要再慢慢补充思路 s = ''' 73167176531330624919225119674426574742355349194934 9698352031277450632623 ...
- Python练习题 036:Project Euler 008:1000位数字中相邻13个数字最大的乘积
本题来自 Project Euler 第8题:https://projecteuler.net/problem=8 # Project Euler: Problem 8: Largest produc ...
- Project Euler Problem8
Largest product in a series Problem 8 Find the greatest product of five consecutive digits in the 10 ...
随机推荐
- 0807再整理SQL执行流程
转自http://www.cnblogs.com/annsshadow/p/5037667.html MySQL架构总览->查询执行流程->SQL解析顺序 前言: 一直是想知道一条SQ ...
- 【ACM】nyoj_2_括号配对问题_201308091548
括号配对问题时间限制:3000 ms | 内存限制:65535 KB 难度:3描述 现在,有一行括号序列,请你检查这行括号是否配对. 输入 第一行输入一个数N(0<N<=100),表示 ...
- 【ACM】hdu_1234_开门人和关门人_201307300845
开门人和关门人Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Linux学习笔记:什么是x86
什么是x86 和硬件打交道常常会听说x86,疑惑的时候自己翻过书上网查过资料.可是都不甚明白.近期再次遇到x86这个词,随具体了解并做笔记记录. 想要知道什么是x86应该先区分CPU的分类. CPU ...
- Android后台服务拍照的解决方式
一.背景介绍 近期在项目中遇到一个需求.实现一个后台拍照的功能. 一開始在网上寻找解决方式.也尝试了非常多种实现方式,都没有惬意的方案.只是确定了难点:即拍照要先预览,然后再调用拍照方法.问题也随之而 ...
- 杭电1879继续畅通project
继续畅通project Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 去哪网实习总结:JavaWeb配置404页面(JavaWeb)
本来是以做数据挖掘的目的进去哪网的,结构却成了系统开发. .. 只是还是比較认真的做了三个月,老师非常认同我的工作态度和成果... 实习立即就要结束了,总结一下几点之前没有注意过的变成习惯和问题.分享 ...
- 【SCOI 2005】 骑士精神
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1085 [算法] IDA* [代码] #include<bits/stdc++. ...
- php Aes 128位算法
<?php class Mcrypt { private static $key = "fsdjfojojodjiovjojgfosdjfiojio"; private st ...
- 从默认析构函数学习c++,new,delete,内存泄漏,野指针
默认析构函数:当系统没有显式定义析构函数,编译器同样会为对象定义一个默认析构函数,默认的析构函数只能释放普通数据成员所占用的空间,无法通过释放通过new和malloc进行申请的空间,因此避免内存泄漏, ...