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-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的分配)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)
比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...
- Educational Codeforces Round 78 (Rated for Div. 2)
A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...
- Educational Codeforces Round 78 (Rated for Div. 2) --补题
链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...
- 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 ...
- Educational Codeforces Round 78 (Rated for Div. 2) C - Berry Jam(前缀和)
随机推荐
- cd oldpwd
常用方式 环境变量OLDPWD表示前一次的当前目录.刚登录系统之后,这个变量是没有设置的. 环境变量PWD表示当前目录. 环境变量CDPATH用来指定cd命令的搜索路径,类似于PATH,它也是用:分隔 ...
- 下页小希学MVC5+EF6.2 学习记录二
目的:1 学习mvc+ef 2 写下日记也是对自己的督促 从前端的UI开始 MVC分离的比较好,开发顺序没有特别要求,先开发哪一部分都可以,这次我们主要讲解前端UI的部分. ASP.NET MVC抛 ...
- 【数据结构】二叉树的遍历(前、中、后序及层次遍历)及leetcode107题python实现
文章目录 二叉树及遍历 二叉树概念 二叉树的遍历及python实现 二叉树的遍历 python实现 leetcode107题python实现 题目描述 python实现 二叉树及遍历 二叉树概念 二叉 ...
- 登录之后跳转到登录之前的页面 之 Referer 的坑
简而言之:通过鼠标在页面上点击链接发送请求,请求header中会包含referer信息, 通过在浏览器地址栏书写并发送请求的,header中不会有referer信息. 为了完成登录动作成功后返回原页面 ...
- Mac OS 终端 iTerm2配置大全
转载链接:https://www.cnblogs.com/diyxiaoshitou/p/9017413.html,在按照原文执行时发现有些问题,所以本文对原文中存在问题的地方做了些调整. 之前一直使 ...
- /Array.CreateInstance创建类型为int,长度为5的数组
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Console ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:数据类型
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- 网格视图GridView
1.常用属性 2.Adapter接口 3.Demo演示 今天观看了GridView的相关视频,并且根据案例,进行了代码的编写和实例 新建GridViewActivity.java继承AppCompat ...
- Q6:ZigZag Conversion
6. ZigZag Conversion 官方的链接:6. ZigZag Conversion Description : The string "PAYPALISHIRING" ...