第一次参加公司的招聘笔试,虽然只是抱着试试水的心态去参加的,可惜的是第一题就做错了。。。。。
第一题,其实只是一个求最大子段和的变式题,不过笔试的时候也不知道怎么了,就是不知道思路,最后还写了一个错的思路
题目大意:笔试题是求两个不相邻区间的最大子段和, OJ题是不相交区间的最大子段和
思路:很简单,遍历一遍,记录从前往后每个元素以该元素结尾的最大子段和,从后往前每个元素以该元素结尾的最大字段和,
然后一层遍历枚举每一个断点,求出该断点前的最大子段和和断点后的最大子段和最大值
Maximum sum
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 41980   Accepted: 13098

Description

Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:

Your task is to calculate d(A).

Input

The input consists of T(<=30) test cases. The number of test cases (T) is given in the first line of the input.
Each test case contains two lines. The first line is an integer n(2<=n<=50000). The second line contains n integers: a1, a2, ..., an. (|ai| <= 10000).There is an empty line after each case.

Output

Print exactly one line for each test case. The line should contain the integer d(A).

Sample Input

110
1 -1 2 2 3 -3 4 -4 5 -5

Sample Output

13

Hint

In the sample, we choose {2,2,3,-3,4} and {5}, then we can get the answer.

Huge input,scanf is recommended.

Maximum sum
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 41980   Accepted: 13098

Description

Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:

Your task is to calculate d(A).

Input

The input consists of T(<=30) test cases. The number of test cases (T) is given in the first line of the input.
Each test case contains two lines. The first line is an integer n(2<=n<=50000). The second line contains n integers: a1, a2, ..., an. (|ai| <= 10000).There is an empty line after each case.

Output

Print exactly one line for each test case. The line should contain the integer d(A).

Sample Input

110
1 -1 2 2 3 -3 4 -4 5 -5

Sample Output

13

Hint

In the sample, we choose {2,2,3,-3,4} and {5}, then we can get the answer.

Huge input,scanf is recommended.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<sstream>
#include<cctype>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int maxn=1234;int T;
int a[50005];
int b1[50005],b2[50005];
int main()
{int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);int sum=0;int maxs=a[0];for(int i=0;i<n;i++)、、从前往后的最大子段和{sum+=a[i];if(sum>maxs) maxs=sum;if(sum<0) sum=0;b1[i]=maxs;}sum=0;maxs=a[n-1];for(int i=n-1;i>=0;i--){//从后往前的最大子段和sum+=a[i];if(sum>maxs) maxs=sum;if(sum<0) sum=0;b2[i]=maxs;}int ans=b1[0]+b2[1];for(int i=0;i<n-1;i++){ans=max(ans,b1[i]+b2[i+1]);}printf("%d\n",ans);}return 0;
}

今日头条2018校园招聘第一题 ---POJ 2479相关推荐

  1. 今日头条2018校园招聘后端开发工程师(第二批)编程题 - 题解

    以前做过第三批的题目,今日头条2018校园招聘后端开发工程师(第三批)编程题 - 题解.这一场的题目偏技巧和算法,而第三批的题偏编码.这一场涉及的算法有二分查找.区间动态规划. 原题链接:点这儿. 第 ...

  2. 今日头条2018校园招聘后端开发工程师(第四批)编程题 - 题解

    做过第三批的题目,今日头条2018校园招聘后端开发工程师(第三批)编程题 - 题解和第二批的题目,今日头条2018校园招聘后端开发工程师(第二批)编程题 - 题解. 这一场题目还是挺好玩的,也挺有技巧 ...

  3. 今日头条2018校园招聘后端开发工程师(第二批)编程题 (Java版)

    本人技术小白一枚,文章只是记录个人的解题思路和过程 牛客网地址:原题链接 第一题:用户喜好 题目 为了不断优化推荐效果,今日头条每天要存储和处理海量数据.假设有这样一种场景:我们对用户按照它们的注册时 ...

  4. 今日头条2018校园招聘后端开发工程师(第三批)编程题 - 题解

    昨天做了下头条的后端开发工程师的编程题,这编码量大啊,两个小时,三个编程题,一个改错题,一个设计题,说实话,很考技术含量,而且编程题中有两个还特别考细心编码,如果两个小时能做三个题,确实非常不错了,写 ...

  5. 今日头条2018校园招聘第一次笔试第二题“字符串拼接”题解(一维动态规划及递归解法)

    3.24晚的笔试,结束后题目看不到了,有人截图了,来源:https://www.jianshu.com/p/00d3fd1d9e23 最新更新:在leetcode 上有一道类似的题,区别在于第一种操作 ...

  6. 今日头条2018校园招聘后端开发工程师 (第二批) 编程题 - 字母交换

    题目描述: [编码题]字符串S由小写字母构成,长度为n.定义一种操作,每次都可以挑选字符串中任意的两个相邻字母进行交换.询问在至多交换m次之后,字符串中最多有多少个连续的位置上的字母相同? 输入描述: ...

  7. 手串(暴力) - 今日头条2018校园招聘后端方向(9.10)

    时间限制:1秒 空间限制:65536K 题目描述 作为一个手串艺人,有金主向你订购了一条包含n个杂色串珠的手串--每个串珠要么无色,要么涂了若干种颜色.为了使手串的色彩看起来不那么单调,金主要求,手串 ...

  8. 今日头条2018秋招编程题

    今日头条 2018秋招 Android方向 编程题 1.手串 作为一个手串艺人,有金主向你订购了一条包含n个杂色串珠的手串–每个串珠要么无色,要么涂了若干种颜色.为了使手串的色彩看起来不那么单调,金主 ...

  9. 今日头条2018校园春季招聘研发岗位笔试(第一场)经验

    笔试公司:今日头条 笔试岗位:后端开发 笔试时间:2018年3月24日19:00-21:00 笔试形式:牛客网在线做题 笔试回忆: 笔试总共五道题.是的,只有五道编码题,没有选择or填空. 第一题,输 ...

最新文章

  1. android开发技术博客
  2. 浅谈Dynamic 关键字系列之二:调用属性,方法,字段
  3. 机器学习降维方法总结
  4. 图解Dev C++ 创建Win32 项目模板
  5. python与Java线程实现方式的对比
  6. C# 使用Conditional特性而不是#if条件编译
  7. python做系统查人的往来的信息_L01-04:python查询员工信息表练习
  8. MySQL批处理SQL语句
  9. 交易系统开发(六)——HFT高频交易
  10. 完全免费绝地求生吃鸡罗技宏
  11. 信息学奥赛一本通1032
  12. Linux安全模块(LSM)学习——简单的LSM demo(1)
  13. AI算力基础 -- TPU1.0
  14. 网吧用计算机性能配件清单,网吧组装电脑配置清单
  15. 【2021年4月电影网络关注度榜】《我的姐姐》登顶热度榜及票房榜
  16. 六大重要策略与技巧,让我们更有效在领英(LinkedIn)开展线上营销
  17. 原始经纬度转百度地图定位并显示地理位置
  18. 怎么用手机控制电脑?手机控制手机如何实现?
  19. 【深度科普】辐射的真相
  20. ENVI水体提取流程实践与问题

热门文章

  1. Spark 2.0.2 中文文档 | 片刻 ApacheCN(Apache中文网)
  2. 西部数据硬盘 代码解析
  3. 牛客练习赛97 C 哦~唔西迪西小姐~
  4. js学习76-107
  5. linux脚本if then,shell里if-then的使用
  6. WebRTC用到的方法
  7. ROS launch调用摄像头问题(已解决)
  8. 一共470多例winformnbsp;界面特…
  9. EOJ 3298 排队买夜宵
  10. 不能在MEMO,OLE或超级链接