【codeforces】CF11B Jumping Jack (题解)

大水题

让我们介绍一下STL库中的绝对值函数-----------abs()

abs()是一个c++自带的绝对值函数,作用是将一个数取绝对值

示例:

#include <cstdlib>
#include <cstdio>
int main()
{
 int number = -1234;
 printf("number: %d absolute value: %d
";   
     number= abs(number));
 return 0;
}

类似的函数还有fabs()

好的,上代码~

无注释版ACcode:

#include <bits/stdc++.h>
using namespace std;
int main()
{
 int x,ans=0,t=1;
 cin>>x;
 abs(x);
 for(int i=1; x&&!ans;)
 {
  if(t==x||(t>x&&!((t-x)%2)))
  {
   ans=i;
  }
  i++;
  t+=i;
 }
 cout<<ans;
 return 0;
}

祝大家AC成功~

c++的好处有什么

原文地址:https://www.cnblogs.com/BorisDimitri/p/13546622.html