0
点赞
收藏
分享

微信扫一扫

A. Distance and Axis(思维) Codeforces Round #665 (Div. 2)

原题链接: ​​https://codeforces.com/contest/1401/problem/A​​

A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_操作数

测试样例:

input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
output
0
3
1000000
0
1
0

样例解释:

A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_ios_02

题意: A,B两点都在A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_#define_03轴上,先给定A的坐标A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_ios_04,同时给定原点到B的距离与点A到点B的距离差值的绝对值。你可以通过对A的坐标进行增1减1操作来使得B的坐标存在,问你要使得B的坐标存在应该进行的最小操作数。

解题思路: 这个题我们判断各种情况即可,即A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_ios_04A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_思维_06的关系,如果A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_ios_07,那么我们发现这个B点放哪都是不可能的,我们最大也只能是这个差值为A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_ios_04,那么我们为了补齐这个差值,同时要使得操作数最小,既然A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_ios_04变为A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_思维_06即可。那么如果A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_操作数_11,那么说明这有点可能了,的确,这个时候我们就可以把B点放原点到A点的中间之前的位置,那么我们设A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_思维_12为对应坐标,那么我们的A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_#define_13,那么转换过去就是A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_思维_14,那么如果我们要让B点的坐标存在,即是A. Distance and Axis(思维)  Codeforces Round #665 (Div. 2)_思维_15是否为偶数,如果不是我们就让它变成偶数即可。OK,具体看代码。

AC代码:

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t,n,k;
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n>>k;
if(k>n){
cout<<k-n<<endl;
}
else{
if((n-k)%2==0)
cout<<0<<endl;
else
cout<<1<<endl;
}
}
}
return 0;
}


举报

相关推荐

0 条评论