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(前缀和)
随机推荐
- 二、CI框架之MCV模型
一.关于MCV,大概就是下图所示: 模型(model)-视图(view)-控制器(controller) M用来处理数据库,V用来显示界面,C用来控制 二.对应到CI的源码,对应的是这3个目录 不忘初 ...
- HDU-4857 逃生(逆向拓扑排序)
Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必须在b之前. ...
- matplotlib画图实例-day1
matplotlib主要用于根据数据画各种图表 官网:https://matplotlib.org/gallery/index.html 例1:画一天中每个两个小时温度变化趋势图 #!/usr/bin ...
- Tomcat解压版Windows配置(运行环境非开发环境)
tomcat官网下载的9.0.19,解压后目录如下: java官网下载的jre8 (8u131),目录如下(应该是下载的解压版): 打开tomcat9.0.19根目录下的RUNNING.txt,里面有 ...
- DispatcherServlet继承体系
GenericServlet implements Servlet, ServletConfig, java.io.Serializable | HttpServlet ...
- JZOJ-2019-11-5 B组
T1 给出一二维01矩阵\(f_{i,j}\), 定义点\((x_a, y_a), (x_b, y_b)\)的「距离」为\(max\{|x_a-x_b|, |y_a-y_b|\}\) 求出一矩阵\(w ...
- 工程日记之HelloSlide(3):如何使用Core Data数据库,以及和sqlite之间的对应关系
Core Data 和 SQLite 是什么关系 core data是对sqlite的封装,因为sqlite是c语言的api,然而有人也需要obj-c的api,所以有了core data ,另外,co ...
- Java自学-集合框架 聚合操作
聚合操作 步骤 1 : 聚合操作 JDK8之后,引入了对集合的聚合操作,可以非常容易的遍历,筛选,比较集合中的元素. 像这样: String name =heros .stream() .sorted ...
- Aras Innovator Method集成Visual Studio
首先下载集成安装包: https://github.com/RazorleafLabs/Aras-Integration-to-Visual-Studio 解压文件包,找到Aras-Integrati ...
- 修改maven默认仓库(即repository)的路径
原文链接:https://blog.csdn.net/ideality_hunter/article/details/53006188 简要说明:主要操作为新建仓库路径,在maven的conf目录下修 ...