[Codeforces]1004A. Sonya and Hotels

題目URL:http://codeforces.com/contest/1004/problem/A
可以擴張就擴張,要判斷的是數若兩數之間一減一加(分別是右、左)加的那個數後比減的大,就不得擴張


#include<bits/stdc++.h>
using namespace std;
int str[1005],ans[1005];
main()
{
 int a,b,flag=0,total=1;
 cin >> a >> b;
 for(int i=0;i<a;i++)
 {
  cin >> str[i];
  if(i>=1)
  {
   if(str[i-1]+b<str[i]-b)
   total+=2;
   else if(str[i-1]+b==str[i]-b)
   total++;
  }
 }
 cout << total+1 << endl;
 return 0;
}

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP