链接:

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. windows远程复制中断无法复制

    关掉对应的rdpclip进程,再创建一个

  2. C# HTTP系列11 以普通文件流方式上传文件远程服务器

    系列目录     [已更新最新开发文章,点击查看详细] 应用程序中上传附件是最常使用的操作之一,ASP.NET客户端一般通过上传控件实现, <input type="file" ...

  3. FFT(快速傅里叶变换)

    FFT(快速傅里叶变换) 前置知识 \(1.复数\) \(2.单位根\) \(3.循环结构\) \(4.C++\) 1.复数 \(定义:形如a+bi的数,其中i^2=-1\) \(计算:1.(a+bi ...

  4. HTML+css基础 img 标签的属性

    img: src=”” src是标签的属性 等号右边是属性值.就是图片的路径. 路径 1. 绝对路径:按照一个路径能找到,具体到某一个盘符下,某一个文件夹内. 2. 相对路径:以当前页面为参考物,去查 ...

  5. 网络基础-------------给电脑设置IP

    ip 是每一台电脑进入互联网的一个必备钥匙,没有它就不能体会冲浪的乐趣,当我们使用电脑连接无线时我们就会被自动分配一个ip地址(DHCP),这样我们就可以凭借这个IPV4地址来进行冲浪了,但是自动分配 ...

  6. Tomcat基础操作

    1.在WebApps ROOT目录里,如果删除过ROOT从新创建,放置index.html,index.jsp即可访问. 2.修改默认8080端口,打开server.xml,将8080端口修改为80即 ...

  7. centos7.x下环境搭建(三)—nodejs安装

    有3种方式可以安装nodejs yum安装 源码包安装 nvm方式安装 一.方式1:yum安装 这里我们指定安装8.x以上的版本 # curl --silent --location https:// ...

  8. 提高性能,MySQL 读写分离环境搭建

    这是松哥之前一个零散的笔记,整理出来分享给大伙! MySQL 读写分离在互联网项目中应该算是一个非常常见的需求了.受困于 Linux 和 MySQL 版本问题,很多人经常会搭建失败,今天松哥就给大伙举 ...

  9. 【leetcode-198】打家劫舍

    你是一个专业的小偷,计划偷窃沿街的房屋.每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警. 给定一个代表每 ...

  10. oracle 10 升级补丁

    Ooacle 10g补丁安装方法 Windows 平台 方法: 1.  备份数据库:关闭数据库,拷贝,安装软件目录,数据文件拷到另一个地方 2.  关闭停止所有oracle 服务+Distribute ...