Problem A 骨牌铺方格
(origin:HDU 2046)
1 #include <stdio.h>
2 int main()
3 {
4 int n,j;
5 long long a[51];
6 while(scanf("%d",&n)!=EOF)
7 {
8 a[1]=1;
9 a[2]=2;
10 for(j=3;j<=n;j++)
11 a[j]=a[j-1]+a[j-2];
12 printf("%lld\n",a[n]);
13 }
14 return 0;
15 }
Problem D Increasing Sequence
(origin:CodeForces 11A)
解法1:(AC不过,但是感觉是正确的)
1 #include<stdio.h>
2 int main()
3 { int n,d,i,j,count=0;
4 int a[2000];
5 scanf("%d%d",&n,&d);
6 for(i=0;i<n;i++)
7 scanf("%d",&a[i]);
8 for(j=1;j<n;j++)
9 while(a[j]<=a[j-1])
10 { a[j]+=d;
11 ++count;
12 }
13 printf("%d\n",count);
14 return 0;
15 }
解法2:(author:成哥)
1 #include<iostream>
2 using namespace std;
3 int main()
4 {
5 int n, d, b[2000], i, m, num = 0;
6 cin >> n >> d;
7 cin >> b[0];
8 for (i = 1; i < n; i++){
9 cin >> b[i];
10 if (b[i] <= b[i - 1]){
11 m = (b[i - 1] - b[i]) / d + 1;
12 num += m;
13 b[i] += m*d;
14 }
15 }
16 cout << num << endl;
17 return 0;
18 }