The following program is my ACcepted code for NTHU-7091 (fast version).
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 7091 (fast version) 的AC code!
點這裡看題目 Click here to see this Problem!
之前這篇的程式是比較慢的XD,可能會在嚴格的測資中TLE,所以就有了這個比較快的版本!
This previous article's program is slower. Maybe get TLE when there're serious test cases so I write this faster version.
//This program is for NTHU 7091 PA - Sum (fast version)
//NTHU 題目來源 Problem link: http://acm.cs.nthu.edu.tw/problem.php?pid=7091
#include<stdio.h>
int main()
{
int K, N, Q, n[10001], q1, q2;
scanf("%d", &K);
while(K--)
{
scanf("%d %d", &N, &Q);
n[0] = 0;
for(int i = 1; i <= N; i++)
{
scanf("%d", &n[i]);
n[i] = n[i] + n[i - 1];
}
while(Q--)
{
scanf("%d %d", &q1, &q2);
printf("%d\n", n[q2] - n[q1 - 1]);
}
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 7091 (fast version) 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
點這裡看題目 Click here to see this Problem!
之前這篇的程式是比較慢的XD,可能會在嚴格的測資中TLE,所以就有了這個比較快的版本!
This previous article's program is slower. Maybe get TLE when there're serious test cases so I write this faster version.
//This program is for NTHU 7091 PA - Sum (fast version)
//NTHU 題目來源 Problem link: http://acm.cs.nthu.edu.tw/problem.php?pid=7091
#include<stdio.h>
int main()
{
int K, N, Q, n[10001], q1, q2;
scanf("%d", &K);
while(K--)
{
scanf("%d %d", &N, &Q);
n[0] = 0;
for(int i = 1; i <= N; i++)
{
scanf("%d", &n[i]);
n[i] = n[i] + n[i - 1];
}
while(Q--)
{
scanf("%d %d", &q1, &q2);
printf("%d\n", n[q2] - n[q1 - 1]);
}
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!