链接:

https://codeforces.com/contest/1278/problem/B

题意:

You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.

For example, if a=1 and b=3, you can perform the following sequence of three operations:

add 1 to a, then a=2 and b=3;

add 2 to b, then a=2 and b=5;

add 3 to a, then a=5 and b=5.

Calculate the minimum number of operations required to make a and b equal

思路:

先转换成,前n个数,分成两堆,差为a和b的差,

打一个前缀和,猜了一下,分成的两堆差肯定为a和b的差,考虑不断给两边加上1,如果总和是前n项和,答案就是n。

卡了一个小时。。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; LL sum[1000010]; int main()
{
int t;
cin >> t;
sum[0] = 0, sum[1] = 1;
for (int i = 1;i <= 1000000;i++)
sum[i] = sum[i-1]+i;
while(t--)
{
int a, b;
cin >> a >> b;
if (a == b)
{
cout << 0 << endl;
continue;
}
int sub = abs(a-b);
int res = 0;
for (int i = 1;i <= 1000000;i++)
{
if (sum[i] < sub)
continue;
if ((sum[i]-sub)%2 == 0)
{
res = i;
break;
}
}
cout << res << endl;
} return 0;
}

Educational Codeforces Round 78 (Rated for Div. 2) B. A and B的更多相关文章

  1. Educational Codeforces Round 78 (Rated for Div. 2) D. Segment Tree

    链接: https://codeforces.com/contest/1278/problem/D 题意: As the name of the task implies, you are asked ...

  2. Educational Codeforces Round 78 (Rated for Div. 2) C. Berry Jam

    链接: https://codeforces.com/contest/1278/problem/C 题意: Karlsson has recently discovered a huge stock ...

  3. Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing

    链接: https://codeforces.com/contest/1278/problem/A 题意: Polycarp has built his own web service. Being ...

  4. 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)

    比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...

  5. Educational Codeforces Round 78 (Rated for Div. 2)B. A and B(1~n的分配)

    题:https://codeforces.com/contest/1278/problem/B 思路:还是把1~n分配给俩个数,让他们最终相等 假设刚开始两个数字相等,然后一个数字向前走了abs(b- ...

  6. Educational Codeforces Round 78 (Rated for Div. 2)

    A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...

  7. Educational Codeforces Round 78 (Rated for Div. 2) --补题

    链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...

  8. Educational Codeforces Round 78 (Rated for Div. 2) 题解

    Shuffle Hashing A and B Berry Jam Segment Tree Tests for problem D Cards Shuffle Hashing \[ Time Lim ...

  9. Educational Codeforces Round 78 (Rated for Div. 2) C - Berry Jam(前缀和)

随机推荐

  1. ASP.NET MVC 下使用支付宝支付接口 以及 ASP.NET Core 下相关改造支付

    通过nuget首先引用AopSdk.dll 包 下面写的是 Asp.Net MVC 下相关的支付接口 APP支付 配置客户端相关的参数,配置成自己的代码就可以了 private string APPI ...

  2. Python【每日一问】38

    问: 基础题: 设计一个经营杠杆系数函数DOL,它包含三个参数,S为营业收入,C为变动成本总额,F为固定成本的总额. 已知2018年的S为20,C为11,F为3,求2019年的经营杠杆系数. 提高题: ...

  3. Python学习教程(一)自学资源分享

    Python 可以用来做什么? 在我看来,基本上可以不负责任地认为,Python 可以做任何事情.无论是从入门级选手到专业级选手都在做的爬虫,还是Web 程序开发.桌面程序开发还是科学计算.图像处理, ...

  4. NPOI中的PhysicalNumberOfCells 与 LastCellNum

    这两个理论上一个是算空列,一个不算空列,但是实际上有时候相同数据的excel,不同的excel编辑工具保存后的,PhysicalNumberOfCells可能不一样,会导致莫名其妙错误,最好使用Las ...

  5. 【leetcode-200 深度优先+广度优先】 岛屿数量

    给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 1: 输入: ...

  6. lombok的@Accessors注解3个属性说明

    https://www.cnblogs.com/kelelipeng/p/11326936.html https://www.cnblogs.com/kelelipeng/p/11326621.htm ...

  7. CTS,CLS,CLR解释

    问题阐述 CTS.CLS和 CLR分别是什么意思? 专家解答 CTS.CLS和 CLR是.NET框架的 3个核心部分,下面分别对它们进行介绍. (1)CTS CTS即通用类型系统,它定义了如何在.NE ...

  8. mac pro使用2K(2056*1440)设置屏幕解决方法

    参考: https://www.jianshu.com/p/40cee8ab3d0f https://www.zhihu.com/question/35300978 在点击ok后,发现并不能保存.或者 ...

  9. tf.Session()函数的参数应用(tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/dcrmg/article/details ...

  10. es6中的arrowfunction

    es6新增箭头函数,主要解决了以下几点问题 函数体内的this对象,就是定义时所在的对象,而不是使用时所在的对象. 不可以当作构造函数,也就是说,不可以使用new命令,否则会抛出一个错误. 不可以使用 ...