免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: davycu

[算法] 迅雷笔试题 [复制链接]

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
发表于 2010-09-14 17:30 |显示全部楼层
dp

论坛徽章:
0
发表于 2010-09-14 19:22 |显示全部楼层

  1. int max_sum( int array[], int len )
  2. {
  3.   int max_so_far = 0;
  4.   int max = 0;

  5.   for( int i = 0; i < len; i++ ) {
  6.     max_so_far += array[i];
  7.     if( max_so_far > max )
  8.       max = max_so_far;
  9.     if( max_so_far < 0 )
  10.       max_so_far = 0;
  11.   }
  12.   return max;
  13. }

  14. int main( int argc, char *argv[] )
  15. {
  16.   int array[9] = { 9, -12, 120, 8, -20, 100, 30, -89, 20 };
  17.   printf( "%d\n", max_sum( array, 9 ) );
  18.   return 0;
  19. }
复制代码

论坛徽章:
0
发表于 2010-09-14 23:26 |显示全部楼层
见识了……

论坛徽章:
3
巳蛇
日期:2013-10-03 10:41:48申猴
日期:2014-07-29 16:12:04天蝎座
日期:2014-08-21 09:24:52
发表于 2010-09-15 08:52 |显示全部楼层
这个题有意思啊。。

论坛徽章:
0
发表于 2010-09-15 09:02 |显示全部楼层
笨方法,使劲加!
  1. #include <iostream>
  2. #include <stdio.h>

  3. using namespace std;

  4. int max_sum(int *array, int len)
  5. {
  6.         if(!array)
  7.                 return 0;
  8.         int max = array[0];
  9.         for(int i = 0; i < len;i++)
  10.         {
  11.                 int tmp = 0;
  12.                 for(int j = i; j < len; j++)
  13.                 {
  14.                         tmp += array[j];
  15.                         if(tmp > max)
  16.                                 max = tmp;
  17.                 }
  18.         }
  19.         return max;
  20. }

  21. int main()
  22. {
  23.         int a[] = {9, -12, 120, 8, -20, 100, 30, -89, 20};

  24.         printf("%d\n",max_sum(a,9));

  25. }
复制代码

论坛徽章:
0
发表于 2010-09-15 09:03 |显示全部楼层
什么是连续元素?

论坛徽章:
0
发表于 2010-09-15 09:59 |显示全部楼层
回复 12# churchmice


    还是这个好

论坛徽章:
0
发表于 2010-09-15 10:39 |显示全部楼层
迅雷做哪方面的嵌入式啊?很好奇的问问,小弟真不懂

论坛徽章:
0
发表于 2010-09-15 10:42 |显示全部楼层
用动态规划,《编程之美——微软技术面试心得》这本书里面有原题,自己去看看吧。

论坛徽章:
0
发表于 2010-09-15 12:42 |显示全部楼层
哎,《编程珠玑》里的题,昨天睡觉前我还在看着呢,
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP