标签:遍历 turn job contains max return ring end can
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 255288 Accepted Submission(s):
60663
1 //尺取法 2 3 #include<stdio.h> 4 #include<string.h> 5 int que[100002]; 6 main() 7 { 8 int t,flag; 9 scanf("%d",&t); 10 flag=t; 11 while(t--) 12 { 13 memset(que,0,sizeof(que)); 14 int n,i,temp=0; 15 int fir=1,end=1,sum=-1,max=-0x7fffffff;/*0x7fffffff这是2进制的int最大*/ 16 scanf("%d",&n); 17 for(i=1;i<=n;i++) 18 scanf("%d",&que[i]); 19 for(i=1;i<=n;i++) 20 { 21 if(sum<0) 22 { 23 temp=i; 24 sum=que[i]; 25 26 } 27 else 28 { 29 sum+=que[i]; 30 31 } 32 if(sum>max) 33 { 34 max=sum; 35 fir=temp; 36 end=i; 37 } 38 39 } 40 41 printf("Case %d:\n",flag-t); 42 printf("%d %d %d\n",max,fir,end); 43 if(t) 44 printf("\n"); 45 } 46 return 0; 47 }
标签:遍历 turn job contains max return ring end can
原文地址:http://www.cnblogs.com/52why/p/7478049.html