zoukankan      html  css  js  c++  java
  • 子数组的最大和

    说实话,这不是自己写的。

    十几次debug就忍不住百度了下算法。

    和自己开始写的很接近,可我解决不了在不增加时间复杂度的基础上判断负数temp加上下一个数变为正,看了别人的伪码,我想复杂了。

    这确实是一道面试题。叹。

    #include<iostream>
    #include<time.h>
    #define random(x) (rand()%x)
    using namespace std;
    
    void main()
    {
    	srand((int)time(0));
    	int a[100];
    	int i,n;
    	int temp=0,sum=0;
    	cout<<"几个数?"<<endl;
    	cin>>n;
    	
    	for(i=0;i<n;i++)
    		a[i]=random(20)-10;
    	for(i=0;i<n;i++) 
    		cout<<a[i]<<" ";
    	
    	for(i=0;i<n;i++)
    	{
    		if(temp>0)
    		{
    			temp+=a[i];
    		}
    		else
    		{
    			temp=a[i];			
    		}
    
    		if(temp>sum)
    			sum=temp;
    	}
    	cout<<endl<<sum<<endl;
    }

    时间记录日志表:

    日期 开始时间 结束时间 中断时间 净时间 活动 备注
    3.20 17:00 21:30 30min 4 编程 课上已构思
    3.23 10:20 10.55 0 35min 整理  

    周活动总结表:

    日期/任务 听课 编程 阅读课本 课外活动 日总结
    周日   0 0 200 200
    周一   200 0 0 120 320
    周二 400 0 0   535
    周三 100 0   240 340
    周四 300 30 0   330
    周五 300 240 0 100 400
    周六   0 0 120 120
    周总结 1300 270 0 780 2350

    缺陷记录日志:

    日期 编号 类型 引入阶段 排除阶段 修复时间 修复缺陷
    3.20 1 20 编码 编译 120min temp变为正的最后一个正数
  • 相关阅读:
    centos 安装docker-ce
    quartz.net .netcore 定时任务部署到linux
    c# 获取linux 磁盘信息
    nginx 安装
    async await 理解
    Remote side unexpectedly closed network connection
    centos 安装。net
    yum 操作
    centos7下安装mysql5.7
    git 本地仓库版本无法从远程更新到本地
  • 原文地址:https://www.cnblogs.com/apak/p/4354667.html
Copyright © 2011-2022 走看看