HDU1003 HDU1231

题意自明。可能是真的进步了点,记得刚开始研究这个问题时还想了好长时间,hdu 1231还手推了很长时间,今天重新写干净利落就AC了。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e5+;
int a[MAXN]; int main()
{
int T,N;
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
scanf("%d",&N);
for(int i=;i<=N;i++){
scanf("%d",&a[i]);
}
int ans=-1e9;
int l=,r=,pos=;
int tot=;
for(int i=;i<=N;i++){
tot+=a[i];
if(tot>ans){
ans=tot;
r=i;
l=pos;
}
if(tot<){
tot=;
pos=i+;
}
}
printf("Case %d:\n%d %d %d\n",cas,ans,l,r);
if(cas!=T)
printf("\n");
}
return ;
}

HDU 1003

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e5+;
int a[MAXN];
int N; int main()
{
while(scanf("%d",&N)==,N)
{
int cnt=;
for(int i=;i<=N;i++){
scanf("%d",&a[i]);
if(a[i]<) cnt++;
}
int ans=-1e9;
int l=,r=,pos=;
int tot=;
for(int i=;i<=N;i++){
tot+=a[i];
if(tot>ans){
ans=tot;
r=i;
l=pos;
}
if(tot<){
tot=;
pos=i+;
}
}
if(cnt==N){
ans=;
printf("%d %d %d\n",ans,a[],a[N]);
}else{
printf("%d %d %d\n",ans,a[l],a[r]);
}
}
return ;
}

HDU 1231

最新文章

  1. array&#39;s filter
  2. 一个iOS 框架介绍:MKNetworkKit
  3. 【读书笔记】iOS-Tagged Pointer对象-注意事项
  4. peak num
  5. HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法
  6. 常用icon以及color颜色RGB值和对应颜色效果图
  7. iOS摄像头和相册-UIImagePickerController-浅析
  8. CSAPP(深入理解计算机系统)读后感
  9. linux-kernel/CodingStyle
  10. Oracle 11g RAC database on ASM, ACFS or OCFS2
  11. Hive ERROR: Out of memory due to hash maps used in map-side aggregation
  12. .NET 微服务和Docker容器
  13. linux命令和awk
  14. Linux文档的压缩与打包
  15. 并行设计模式(二)-- Master-Worker模式
  16. Android 纵向跑马灯滚动效果
  17. 数据结构(六)查找---平衡二叉树(ASL)
  18. u3d加载加密和未加密
  19. 前端图片压缩(纯js)
  20. Dinic算法----最大流常用算法之一

热门文章

  1. mysqldump mysql数据库导出命令
  2. bzoj 1034 [ZJOI2008]泡泡堂BNB——贪心
  3. TZ_03_mybatis的注解开发
  4. 基于RBAC权限管理的后台管理系统
  5. Django 创建web项目之HelloWorld
  6. 【洛谷】P1876 开灯
  7. LUOGU P1081 开车旅行 (noip 2012)
  8. webpack--安装,使用
  9. web前端学习(三)css学习笔记部分(4)-- CSS选择器详解
  10. laravel-admin