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

思路:还是把1~n分配给俩个数,让他们最终相等

   假设刚开始两个数字相等,然后一个数字向前走了abs(b-a)步,由等差数列求和公式,这时候我们贪心的让另外一个数字走大于等于abs(b - a)的最小步数,然后如果两数相等必须满足走的步数之和%2=0

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int M=1e6+;
ll a[],countt[M];
void solve()
{
ll a,b;
cin>>a>>b;
ll c=max(a,b)-min(a,b);
int i;
for(i=;;i++)
if(c<=(i*(i + ))/)
break;
ll m =(i*(i + ))/;
while((m+c)% )
i++,m=(i*(i + ))/;
cout<<i<<endl;
return;
}
int main()
{
int t;cin>>t;
while(t--)
solve();
}

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

  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) B. A and B

    链接: https://codeforces.com/contest/1278/problem/B 题意: You are given two integers a and b. You can pe ...

  4. 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 ...

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

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

  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. Sublime Text基本配置

    官网最新版本号 3059 破解链接: http://bbs.pediy.com/showthread.php?t=182774 可以看那个人放出来的百度网盘,去他的百度网盘里面可以看到最新的破解文件. ...

  2. Go语言开发环境的搭建(Goland和VSCode)

    教程首发于:微信公众号<Go编程时光>,欢迎你一起来学习 1. 下载安装 Go语言 下载地址:https://golang.google.cn/dl/ 下载完成后,直接双击 msi 文件进 ...

  3. 浅谈$NTT$

    \(NTT\),快速数论变换,可以理解为带模数的FFT. 原根 & 阶 先来补一点数论.(这里讲的应该很少,都是针对\(ntt\)胡的,具体的话可以去看<初等数论>那本小黄书). ...

  4. web嵌入到原生的app里需要注意的事项

    1.https://www.cnblogs.com/shimily/articles/7943370.html 2.https://www.cnblogs.com/stoneniqiu/p/60771 ...

  5. tensorflow笔记2(北大网课实战)

    1.正则化缓解过拟合 正则化在损失函数中引入模型复杂度指标,利用给w加权值,弱化了训练数据的噪声 一般不会正则化b. 2.matplotlib.pyplot 3.搭建模块化的神经网络八股: 前向传播就 ...

  6. POJ 3911:Internet Service Providers

    Internet Service Providers Time Limit: 2MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I ...

  7. 一个算法题--Self Crossing

    You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to th ...

  8. 18 11 12 网络通信 tcp

    tec 客户端的接受代码 import socket def main(): # 1. 创建tcp的套接字 tcp_socket = socket.socket(socket.AF_INET, soc ...

  9. h5-钟表动画案例

    1.html代码 <div class="clock"> <div class="line line1"> <div class= ...

  10. 2019牛客网暑假多校训练第四场 K —number

    链接:https://ac.nowcoder.com/acm/contest/884/K来源:牛客网 题目描述 300iq loves numbers who are multiple of 300. ...