链接:

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. css 在一定区域内滚动显示,不修改父级样式

    做项目时,会遇到一些零碎的技术点.记录下来以防忘记 需求:图中圈中的部门是滚动的.不修改父级样式 代码: <div class="right-text-bottom"> ...

  2. golang 1.12 自动补全

    golang 1.12 版本的自动补全问题 问题 golang 1.12 开始, 默认的 go install 不再生成 pkg 文件. 所以对第三方库的引用, 无法进行代码的自动补全. 解决方法 g ...

  3. 应用Redis分布式锁解决重复通知的问题

    研究背景: 这几天被支付宝充值后通知所产生的重复处理问题搞得焦头烂额, 一周连续发生两次重复充钱的杯具, 发事故邮件发到想吐..为了挽回程序员的尊严, 我用了Redis的锁机制. 事故场景: 支付宝下 ...

  4. Aliplayer视频点播加密播放

    Aliplayer视频播放器填坑 aliplayer视频点播分为Flash和HTML5两个版本,移动端不支持Flash播放器.Flash播放器兼容IE8+,HTML5播发器支持比较新的浏览器,对浏览器 ...

  5. 基于 HTML5 WebGL 的 3D 智慧隧道漫游巡检

    前言 这次为大家展示的是通过 HT for Web 灵活的图型化编辑工具打造的智慧隧道监控系统.通过 HTML5 技术实现了桌面和移动端的跨平台性,同时现实了可视化运维. 这次主要跟大家分享里面的漫游 ...

  6. MySQL各类型字段可定义最大宽度

    今天浏览mysql的官网文档,无意中看到如图划线部分一句话,引起了我的兴趣,所以决定做实验官方所言. 条例1.创建数据表时,所有字段定义时"宽度之和"不得超过65535字节: 条例 ...

  7. C# foreach循环

    一.简介 foreach循环可以迭代数组或者一个集合对象 二.语法 foreach(数据类型  变量名  in  数组名) {     //语句块: } 循环运行的过程:每一次循环时,从集合中取出一个 ...

  8. json解析常见异常

    (1) : org.json.JSONException: Expected a ',' or '}' at 80 [character 81 line 1]   原因:出现乱码了, 导致json格式 ...

  9. 7.vertical-align属性

    本节学习目标: 图片.表单和旁边的文字对齐 解决图片底部默认空白缝隙问题 1.图片.表单和旁边的文字对齐 默认的图片.表单等行内元素或行内快元素是和文字的基线对齐的,但在实际情况下,我们想让他们中间对 ...

  10. vue+element下拉框样式的点击按钮

    项目中点击按钮实在太多了,怎么办呢?我们就可以将它们制作成像下拉框那样的类似操作 1.HTML样式部分:关键点在于command 方法和属性 1 <el-dropdown 2 size=&quo ...