题意:寻找这 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的更多相关文章

  1. Project Euler 11 Largest product in a grid

    题意:在这个20×20方阵中,四个在同一方向(从下至上.从上至下.从右至左.从左至右或者对角线)上相邻的数的乘积最大是多少? 思路:暴力去枚举以 ( x , y ) 为中心拓展的四个方向 /***** ...

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

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

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

  4. 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 = ...

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

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

  6. Largest product in a series

    这个我开始理解错了,算错了. 我以为是求连续5个数的最大值,结果,是连接5个数相乘的最大值. 英语不好,容易吃亏啊. Find the greatest product of five consecu ...

  7. Problem 8: Largest product in a series

    先粘实现代码,以后需要再慢慢补充思路 s = ''' 73167176531330624919225119674426574742355349194934 9698352031277450632623 ...

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

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

  9. Project Euler Problem8

    Largest product in a series Problem 8 Find the greatest product of five consecutive digits in the 10 ...

随机推荐

  1. maven+springMVC+mybatis+easyUI管理用户增删改查

    1.项目演示图 2.项目简单介绍 项目分为两个projectdomain和manager.project结构例如以下图所看到的.当中domain是Maven javaproject主要完毕对数据库的操 ...

  2. Libgdx: android单机斗地主支持局域网wifi联网的网络模块核心代码

    这个作品是我近期写的,结合我的毕业设计的通信模块和之前的单机版斗地主.我已经上架到豌豆荚了,贴了点广告,看看能不能赚点茶钱. 但是一点也不乐观.因此我想分享给大家源代码. 仅仅要不用于商业. 以下先贴 ...

  3. 消息推送之百度云推送Android集成与用法

    这两天因为项目须要.研究了一下百度云推送,本来这事没什么多大工作量的,但注冊百度开发人员账户创建应用令我蛋疼菊紧了好一阵,这些东西做了对技术没啥提升,不做又不行,必经之路. 好在我耗费了N多个毫毫秒秒 ...

  4. Maven与IDEA结合

    转自:https://blog.csdn.net/zzpzheng/article/details/49474671 1. 什么是 Maven,为什么要使用 Maven 而不是 Ant Maven简单 ...

  5. Cracking the Coding Interview 5.2

    Given a(decimal -e.g. 3.72)number that is passed in as a string, print the binary representation. If ...

  6. Mac OS X10.9安装的Python2.7升级Python3.4步骤详解

    Mac OS X10.9安装的Python2.7升级Python3.4步骤详解 Mac OS X10.9默认带了Python2.7,不过现在Python3.4.0出来了,如果想使用最新版本,赶紧升级下 ...

  7. B - Guess a number!

    Problem description A TV show called "Guess a number!" is gathering popularity. The whole ...

  8. ansible usually

    链接地址:https://my.oschina.net/kangvcar/blog/1830155

  9. lua队列实现

    Queue = {} function Queue.newquene() } end function Queue.push(queue, value) queue.count = queue.cou ...

  10. 使用Micrisoft.net设计方案 前言

    前言 主要阐述23种设计模式在Microsoft.Net中的使用,以及使用设计模式创建后的对象如何使用.同是向我们传达3个理念,分别是: 1.  使用设计模式可以让程序更加灵活 2.  结构越复杂,意 ...