题: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. BZOJ:3231: [Sdoi2008]递归数列

    题解: 矩阵乘法,在矩阵中构造当前前缀和: 注意:for(int/long long ;;); #include<iostream> #include<cstdio> #inc ...

  2. localStorage中使用json

    function setLocalJson(name, json) { json = JSON.stringify(json); localStorage.setItem(name, json)} f ...

  3. mysql 如何删除数据库中所有的表

    SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')FROM information_schema.tablesWHERE table_sch ...

  4. UML-设计模式-对一组相关的对象使用抽象工厂模式

    1.场景 问题: javapos驱动,有2套,一套是IBM的,另一套是NCR的.如: 使用IBM硬件时要用IBM的驱动,使用NCR的硬件时要用NCR的驱动.那该如何设计呢? 注意,此处需要创建一组类( ...

  5. HDU 5423:Rikka with Tree Dijkstra算法

    Rikka with Tree  Accepts: 207  Submissions: 815  Time Limit: 2000/1000 MS (Java/Others)  Memory Limi ...

  6. SpringCloud学习之Hystrix请求熔断与服务降级(六)

    我们知道大量请求会阻塞在Tomcat服务器上,影响其它整个服务.在复杂的分布式架构的应用程序有很多的依赖,都会不可避免地在某些时候失败.高并发的依赖失败时如果没有隔离措施,当前应用服务就有被拖垮的风险 ...

  7. Mac OS/Windows好用软件分享

    下软件全部为破解版,仅供参考学习用,如涉及商业. 请支持正版!谢谢 全部为本人亲测过 看上哪个留言发给你!   直接全分享上来会有人居心不良!

  8. 解决XML警告"No grammar constraints (DTD or XML Schema) referenced in the document"

    解决办法: 顶部有这两行信息即可解决警告: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...

  9. Linux中Tomcat 自动设置CATALINA_HOME方法

    Linux中Tomcat 自动设置CATALINA_HOME方法 在服务器部署中,我们经常会出现“在一个服务器上运行多个tomcat服务”的情况. 使用如下方法设置,可以无限复制平移扩展Tomcat, ...

  10. 【前缀思想】二叉树中所有距离为 K 的结点

    863. 二叉树中所有距离为 K 的结点 class Solution { Map<TreeNode,String>map=new HashMap<>(); String pa ...