codeforces 1278 B. A and B
程序员文章站
2023-12-26 22:47:39
...
本题
分析:
然后贪心枚举步数n,先满足②式,再满足①式,break就完事
有异曲同工之妙的一个题[codeforces 1260B]
(https://codeforces.com/contest/1260/problem/B)
总结:两个题都是先根据题意,用题目的opertions表示出两个数得到两个式子,然后加减两个式子,就水暗花明!
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<iostream>
#define ll long long
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll a,b;
cin>>a>>b;
ll s=a+b;
ll c=abs(a-b);
ll sum;
for(int i=0;i<=1000000000;i++)
{
sum=i*(i+1)/2;
if(sum>=c)
{
if((s+sum)%2==0)
{
cout<<i<<endl;
break;
}
}
}
}
return 0;
}
推荐阅读
-
codeforces 1278 B. A and B
-
codeforces 607B Zuma 区间dp
-
Codeforces Round #553 (Div. 2) B. Dima and a Bad XOR(异或+思维)
-
Codeforces Round #246 (Div. 2) ?B. Football Kit_html/css_WEB-ITnose
-
Codeforces Round #261 (Div. 2)B. Pashmak and Flowers(容易)
-
Codeforces Round #266 (Div. 2) B. Wonder Room_html/css_WEB-ITnose
-
『ACM C++』 Codeforces | 1066B - Heaters
-
Codeforces 939A题,B题(水题)
-
codeforces 712B Memory and Trident
-
codeforces 1282B(dp)