我是菜鸟,我怕谁
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10988 Accepted Submission(s): 6334
Problem Description
lin2144是一只小菜鸟,都是笨鸟先飞,lin2144想来个菜鸟先飞,他从0点出发
一开始的飞行速度为1m/s,每过一个单位时间lin2144的飞行速度比上一个单位时间的飞行速度快2m/s,问n (0 < n < 10^5)个单位时间之后lin2144飞了多远?
Input
一开始的飞行速度为1m/s,每过一个单位时间lin2144的飞行速度比上一个单位时间的飞行速度快2m/s,问n (0 < n < 10^5)个单位时间之后lin2144飞了多远?
输入一个T表示为有几组数据
每组数据输入一个n,表示lin2144飞行的时间.
Output
每组数据输入一个n,表示lin2144飞行的时间.
输出lin2144飞行了多远,因为数字很大,所以对10000取模.
Sample Input
2 1 2
1 4
问题链接:HDU2520 我是菜鸟,我怕谁。
题意简述:参见上文。
问题分析:本题有两种解法,一是数学解法,二是模拟解法。
1.数学解法
因为v=v0+a*(t-1)且s=(v+v0)*t/2,所以s=(2v0+a(t-1))*t/2
其中v0=1且a=2,所以s=t*t。
2.模拟解法:一个一个时间单位算下去。
程序说明:需要注意类型,不然会溢出。
AC的C语言程序如下:
/* HDU2520 我是菜鸟,我怕谁 */ #include <stdio.h> #define MOD 10000 int main(void) { int t, n; scanf("%d", &t); while (t--) { scanf("%d", &n); printf("%lld ", (long long)n * n % MOD); } return 0; }
AC的C语言程序(过程模拟)如下:
/* HDU2520 我是菜鸟,我怕谁 */ #include <stdio.h> #define MOD 10000 #define A 2 int main(void) { int t, n, s, i; long long sum; scanf("%d", &t); while (t--) { scanf("%d", &n); s = 1; sum = 0; for(i=1; i<=n; i++) sum += s, s += A; printf("%lld ", sum % MOD); } return 0; }