acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 题解

    userId_undefined

    法兰西玫瑰

    倔强青铜
    14阅读
    0回复
    1点赞
  • 题解

    #include <iostream> #include <cmath> #include <string> #include <cstring> #include <iomanip> #include <algorithm> #include <vector> #include <cstdio> #define int long long /* 很巧妙的一个题,我们可以把这个问题转化为: 输入一个T,使用1到n的所有数通过加减运算得到T,求最小的n 其实我们要找的数是最小的比T的绝对值大且与T的差为偶数的累加数的累加次数 如果我们达到这个累加数,我们可以通过改变已累加的符号调整到T 至于为什么差要是偶数,因为你改变一个符号,实际上是减少了两倍的这个数,减少的值总是偶数 */ using namespace std; const int N=1,inf=2147483647; int T; int k,s; int f[N]; signed main(){ scanf("%lld",&T); T=T<0?-T:T; k=0; while(s<T||(s-T)%2!=0){ k++; s+=k; } printf("%lld",k); return 0; }

    userId_undefined

    小张张五

    AC狗饲养员
    倔强青铜
    14阅读
    0回复
    1点赞
首页