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 }
时间: 2024-10-10 12:06:35