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 <stdio.h> int main() { int textCnt; int a, b, m; int dt[10001]; int total[10001]; int i, j; int min; int minIndex; scanf("%d", &textCnt); while(textCnt--) { //读入数据 scanf("%d%d%d", &m, &a, &b); for(i = 1; i <= m; ++i) { scanf("%d", &dt[i]); } //穷举,每层都试 for(i = 1; i <= m; ++i) { total[i] = 0; for(j = 1; j <= m; ++j) { if(j < i) //需要往楼下走 { total[i] += dt[j] * ((i - j) * b + 0.5 * (i - j) * (i - j - 1)); } else { total[i] += dt[j] * ((j - i) * a + 0.5 * (j - i) * (j - i - 1)); } } } //寻找符合题目要求的结果 min = total[1]; minIndex = 1; for(i = 2; i <= m; ++i) { if(total[i] < min) { min = total[i]; minIndex = i; } } printf("%d\n", minIndex); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator