Max Sum_JAVA_HDU1003
来源:互联网 发布:java字符串转字节数组 编辑:程序博客网 时间:2024/05/21 16:55
Max Sum :
http://acm.hdu.edu.cn/showproblem.php?pid=1003
代码:
import java.util.Scanner;public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); //数据组数 for(int i=1;i<=n;i++){ int m = sc.nextInt(); //每组数据的个数 int s=0,smax=-1002; //s:连续子段和, smax:最大连续子段和 int x=1; //当前连续子段的起始位置 int xmax=0,ymax=0; //xmax:最大连续子段和的起始位置, ymax:结束位置 //求最大连续子段和,并记录位置 for(int j=1;j<=m;j++){ int k=sc.nextInt(); s+=k; if(s>smax){ xmax=x; ymax=j; smax=s; } if(s<0){ s=0; x=j+1; } } System.out.println("Case "+ i+ ":"); System.out.println(smax+" "+ xmax+" "+ ymax); if(i!=n) System.out.println(); } }}
另记:
代码自己写出来,但是始终不能AC,参照网上代码,把 ‘smax=0’ 改为’smax=-1002’ ,就可以了.此处不懂.
0 0
- Max Sum_JAVA_HDU1003
- max
- MAX
- max
- max
- max
- max
- max
- max * max
- Max product
- Max error
- air max
- Max Sum
- Math.max()
- Max Sum
- Max Sum
- Max Sequence
- max sum
- android color.xml
- linux启动基本流程
- 寄存器与缓存的区别
- Linux下wc工具的简单实现
- windows 计划任务中使用脚本 备份文件
- Max Sum_JAVA_HDU1003
- 在web服务器上,有些pdf, 怎么让用户在页面上点击一个按钮,就直接打印?
- android 处理输入法可见性
- 谷歌,你懂的
- org.hibernate.TransactionException: nested transactions not supported错误的解决方案
- mysql多实例(多个配置文件方式)
- 黑马程序员——反射
- MongoDB简单操作指令
- cocos2d js代码中编辑利用cocos studio生成的界面