| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
TLE了,哪里抄了,帮忙给改改吧,谢谢!!#include <iostream>
using namespace std;
int main()
{
int nCases,n,tag,i,j,array[100000];
cin >> nCases;
while(nCases--){
cin >> n >> tag;
int total = 0,max = 0,sum = 0,length = n + 1,tmp = n + 1;
for(i = 0;i < n;i++){
cin >> array[i];
if(array[i] > max)
max = array[i];
total += array[i];
}
if(max >= tag){
cout << "1" << endl;
break;
}
if(total < tag){
cout << "0" << endl;
continue;
}
if(total == tag){
cout << n << endl;
continue;
}
int *p1 = array,*p2;
for(i = 0;i < n;i++){
p2 = p1;
for(j = i;j < n;j++){
sum += *p2;
p2++;
if(sum >= tag)
break;
}
if(sum >= tag){
tmp = p2 - p1;
if(tmp < length)
length = tmp;
if(length == 1)
break;
}
p1++;
sum = 0;
}
if(length == n + 1)
cout << "0" << endl;
else
cout << length << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator