题目相对应的原题链接
B:Problem - 1618D - Codeforces
目录
预估平均5~6题。因为除了两道题,其他都是签到水平的题,当然这个签到不是无脑签到,如果仔细思考一下,很容易想到。本来以为这场拼的是细心和手速。
A
这道题真的没什么可以说的,每次按比例相加个部分的,所以其实每次加的都一样,直接输出在加上当前在总和的比,乘上k。
/*Looking! The blitz loop this planet to search way
Only my RAILGUN can shoot it 今すぐ
身体中を 光の速さで
駆け巡った確かな予感
掴め! 望むものなら残さず
輝ける自分らしさで
信じてるよ あの日の誓いを
この瞳に光る涙それさえも 強さになるから
*/
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<numeric>
#include<stack>
using namespace::std;
typedef long long ll;
inline __int128 read(){
__int128 x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void print(__int128 x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
print(x / 10);
putchar(x % 10 + '0');
}
//struct dian{
// double x,y;
//}A,B,C,D,E,F;//点
//cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y>>E.x>>E.y>>F.x>>F.y;
//double len(dian x,dian y){
// return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
//}//两点之间距离
//double xj(dian x,dian y,dian z){
// x.x-=y.x;
// x.y-=y.y;
// z.x-=y.x;
// z.y-=y.y;
// return x.x*z.y-x.y*z.x;
//}//叉积
int n,t;
ll a[100005],k;
void wanyurukong(){
cin>>n>>k;
ll an=0;
for (int i =1 ;i<=n; i++) {
cin>>a[i];
an+=a[i];
}
for (int i =1; i<=n; i++) {
printf("%.7lf ",1.0*a[i]+1.0*a[i]*k/an);
}
printf("\n");
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
wanyurukong();
}
//wanyurukong
return 0;
}
B
这道题感觉同样没什么可说的,分数最低,那么肯定先消除大的,同样的,将一个大的除于它的相对大的就是0,我们只需要处理一下直接求和即可?
/*Looking! The blitz loop this planet to search way
Only my RAILGUN can shoot it 今すぐ
身体中を 光の速さで
駆け巡った確かな予感
掴め! 望むものなら残さず
輝ける自分らしさで
信じてるよ あの日の誓いを
この瞳に光る涙それさえも 強さになるから
*/
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<numeric>
#include<stack>
using namespace::std;
typedef long long ll;
inline __int128 read(){
__int128 x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void print(__int128 x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
print(x / 10);
putchar(x % 10 + '0');
}
namespace simpler{
template<const unsigned _Mod=INT32_MAX>
class modint{
protected:
int64_t _val;
typedef modint<_Mod> _mint;
friend inline _mint
__construct(_mint&& _res,int64_t _x){
_res._val=_x;
return _res;
}
template<class _Tp>friend _mint
__quickly_power(_mint _a,_Tp _b){
if(_b<=0)return 1;
_mint _res=1;
for(;(bool)_b;_b>>=1,_a*=_a)if(_b&1)_res*=_a;
return _res;
}
public:
modint():_val(0){}
template<class _Tp>modint(_Tp _x){
_val=((int64_t)_x%_Mod+_Mod)%_Mod;
}
template<class _Tp>explicit inline operator _Tp(){return (_Tp)_val;}
friend _mint operator+(const _mint& _a,const _mint& _b){
if(_a._val+_b._val>=_Mod)return __construct(_mint(),_a._val+_b._val-_Mod);
return __construct(_mint(),_a._val+_b._val);
}
inline _mint& operator+=(const _mint& _b){return *this=*this+_b;}
inline _mint& operator++(){return *this=*this+__construct(_mint(),1);}
inline _mint& operator++(int){
_mint _res=*this;*this=*this+__construct(_mint(),1);
return _res;
}//plus
friend _mint operator-(const _mint& _a,const _mint& _b){
if(_a._val-_b._val<0)return __construct(_mint(),_a._val-_b._val+_Mod);
return __construct(_mint(),_a._val-_b._val);
}
inline _mint& operator-=(const _mint& _b){return *this=*this-_b;}
inline _mint& operator--(){return *this=*this-__construct(_mint(),1);}
inline _mint& operator--(int){
_mint _res=*this;*this=*this-__construct(_mint(),1);
return _res;
}//minus
friend inline _mint
operator*(const _mint& _a,const _mint& _b){
return __construct(_mint(),_a._val*_b._val%_Mod);
}
inline _mint& operator*=(const _mint& _b){return *this=*this*_b;}//multiplies
_mint operator-(){return __construct(_mint(),_val?_Mod-_val:_val);}//negative
friend inline _mint
operator%(const _mint& _a,const _mint& _b){
return __construct(_mint(),_a._val%_b._val);
}
inline _mint& operator%=(const _mint& _b){return *this=*this%_b;}//modulus
friend inline bool
operator==(const _mint& _a,const _mint& _b){
return _a._val==_b._val;
}
friend inline bool
operator!=(const _mint& _a,const _mint& _b){
return _a._val!=_b._val;
}
friend inline bool
operator<(const _mint& _a,const _mint& _b){
return _a._val<_b._val;
}
friend inline bool
operator>(const _mint& _a,const _mint& _b){
return _a._val>_b._val;
}
friend inline bool
operator<=(const _mint& _a,const _mint& _b){
return _a._val<=_b._val;
}
friend inline bool
operator>=(const _mint& _a,const _mint& _b){
return _a._val>=_b._val;
}
friend inline _mint
operator&(const _mint& _a,const _mint& _b){
return _a._val&_b._val;
}
inline _mint& operator&=(const _mint& _b){return *this=*this&_b;}
friend inline _mint
operator|(const _mint& _a,const _mint& _b){
return _a._val|_b._val;
}
inline _mint& operator|=(const _mint& _b){return *this=*this|_b;}
friend inline _mint
operator^(const _mint& _a,const _mint& _b){
return _a._val^_b._val;
}
inline _mint& operator^=(const _mint& _b){return *this=*this^_b;}
friend inline _mint
operator<<(const _mint& _a,const _mint& _b){
return _a._val<<_b._val;
}
inline _mint& operator<<=(const _mint& _b){return *this=*this<<_b;}
friend inline _mint
operator>>(const _mint& _a,const _mint& _b){
return _a._val>>_b._val;
}
inline _mint& operator>>=(const _mint& _b){return *this=*this>>_b;}
inline _mint operator~()const{return __construct(_mint(),~_val);}
inline bool operator!()const{return !_val;}
friend inline std::istream&
operator>>(std::istream& _is,_mint& _b){
return _is>>_b._val;
}
friend inline std::ostream&
operator<<(std::ostream& _os,const _mint& _b){
return _os<<_b._val;
}
template<class _Tp>_mint
power(_Tp _n)const{
return __quickly_power(*this,_n);
}
inline _mint inv()const{return __quickly_power(*this,_Mod-2);}
friend inline _mint
operator/(const _mint& _a,const _mint& _b){
return __construct(_mint(),_a._val*_b.inv()._val%_Mod);
}
inline _mint& operator/=(const _mint& _b){return *this=*this/_b;}
};//modint 2.0
}
using mint=simpler::modint<998244353>;
const int Maxn=2e5+5;
//definition
//mint a[Maxn];
//mint f[2][Maxn];
int n,t,k;
int a[105];
void wanyurukong(){
cin>>n>>k;
for (int i =1; i<=n ;i++) {
cin>>a[i];
}
sort(a+1, a+1+n);
ll f1=0;
for (int i =0; i<k; i++) {
f1+=a[n-i-k]/a[n-i];
}
for (int i=1; i<=n-2*k; i++) {
f1+=a[i];
}
printf("%lld\n",f1);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
wanyurukong();
}
//wanyurukong
return 0;
}
C
根据它给的东西,换算一下,然后 IF 判断一下即可?
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<numeric>
using namespace::std;
typedef long long ll;
int n,t;
ll b,r,d,s;
void solv(){
cin>>b>>r>>d>>s;
if (r==0) {
if (d==0) {
printf("ok\n");
}
else{
printf("gua!\n");
}
return;
}
r=s*r/60+1;
if (b*r>=d) {
printf("ok\n");
}
else{
printf("gua!\n");
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
solv();
}
return 0;
}
D
题目大意:长度为n的环,m种颜色,一次涂连续k个长度。给出环的结果,问你最小涂改次数,和是否能涂改成功。
涂改单位可以相互覆盖,所以很容易想到,不可能的情况,那么就是最长的一段连续区间的长度小于k,因为大于等于k都可以达成,这段区间可以当作 最后收尾的区间。
那么其他情况呢,中间的区间长度的涂改次数,很明显就是当前连续长度对k的向上取整。
然后因为是环,所以我们需要首先处理一下头尾的情况,因为它们可能是相同的颜色,然后剩下的就是for循环了
感觉也很签
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<numeric>
using namespace::std;
typedef long long ll;
int n,m,k,t;
int a[1000005];
void solv(){
cin>>n>>m>>k;
ll ans=0;
int msd=-1;
for (int i =0; i<n; i++) {
cin>>a[i];
}
if (m==1) {
printf("%d\n",(n+k-1)/k);
return;
}
int rr=a[0];
int l =0,r=n-1;
while (rr==a[l]) {
l++;
}
while (rr==a[r]) {
r--;
}
if (r<l) {
printf("%d\n",(n+k-1)/k);
// printf("dsadsa\n");
return;
}
int jl=l+n-r-1;
// cout<<jl<<endl;
ans+=(jl+k-1)/k;
msd=max(msd, jl);
int we=1;
for (int i=l+1 ; i<=r; i++) {
if (a[i]==a[i-1]) {
we++;
msd=max(we, msd);
}
else{
ans+=(k-1+we)/k;
we=1;
}
}
ans+=(k-1+we)/k;
msd=max(we,msd);
if (msd<k) {
printf("-1\n");return;
}
printf("%lld\n",ans);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
solv();
}
return 0;
}
E
这道题纯签到,随便枚举一下就可以看出来两种情况。doctor ddddoctor 前两位字母相同和不相同的。随便就可以推出来结论
/*Looking! The blitz loop this planet to search way
Only my RAILGUN can shoot it 今すぐ
身体中を 光の速さで
駆け巡った確かな予感
掴め! 望むものなら残さず
輝ける自分らしさで
信じてるよ あの日の誓いを
この瞳に光る涙それさえも 強さになるから
*/
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include <unordered_map>
#include<set>
#include<tuple>
#include<numeric>
#include<stack>
using namespace::std;
typedef long long ll;
inline char nc() {
static char buf[1000000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename _Tp> inline void read(_Tp&sum) {
char ch = nc(); sum = 0;
while (!(ch >= '0'&&ch <= '9')) ch = nc();
while (ch >= '0'&&ch <= '9') sum = (sum << 3) + (sum << 1) + (ch - 48), ch = nc();
}
inline __int128 read128(){
__int128 x = 0, f = 1;
char ch128 = getchar();
while(ch128 < '0' || ch128 > '9'){
if(ch128 == '-')
f = -1;
ch128 = getchar();
}
while(ch128 >= '0' && ch128 <= '9'){
x = x * 10 + ch128 - '0';
ch128 = getchar();
}
return x * f;
}
inline void print128(__int128 x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
print128(x / 10);
putchar(x % 10 + '0');
}
//struct dian{
// double x,y;
//}A,B,C,D,E,F;//点
//cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y>>E.x>>E.y>>F.x>>F.y;
//double len(dian x,dian y){
// return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
//}//两点之间距离
//double xj(dian x,dian y,dian z){
// x.x-=y.x;
// x.y-=y.y;
// z.x-=y.x;
// z.y-=y.y;
// return x.x*z.y-x.y*z.x;
//}//叉积
int n,t;
string s;
void wanyurukong(){
cin>>s;
ll an=0;
if (s[0]==s[1]) {
int k=1;
while (s[k]==s[k+1]) {
k++;
}
an=2*s.size()-k-1;
if (an==s.size()) {
an-=1;
}
}
else{
an=s.size()*2-1;
}
printf("%lld\n",an);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
wanyurukong();
}
//wanyurukong
return 0;
}
F
这道题原题是吃火锅,因为英文感觉不好翻译,所以换成了一个中文题面,就变成了吃糖。
我们发现m是1e9,所以还有个T组输入,所以硬着头皮模拟,肯定会T掉(不知道有没有人头铁
题目很简单,每个人有着相对应的糖的类型,如果盆里面存在,那么就吃掉,如果没有,那就再加进去一个。很简单的模拟,我们如果想拿n次来找规律,明显是有些限制的,因为刚开始盆里都是没有的,可能某个糖的类型是奇数,n轮过后,该类型的糖存在于盆里面。
但这个时候,我们只需要把n*2,跑2*n次,就没有任何顾虑了,不过偶数还是奇数乘偶数都是偶数,所以每次肯定都是空的。n 1e5,2n. 2e5,所以我们知道了以2n一个周期的规律,所以我们可以直接得到m关于2n的整数倍的答案,而剩下的我们可以直接for,因为2n最大2e5,用for进行模拟也是不会TLE的。代码如下:
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<numeric>
using namespace::std;
typedef long long ll;
int n,k,m,t;
int a[100005];
ll ans[100005];
int bj[100005];
void solv(){
cin>>n>>k>>m;
memset(bj, 0, sizeof bj);
memset(ans, 0, sizeof ans);
for (int i =1; i<=n; i++) {
cin>>a[i];
}
ll k1=min(2*n, m);
int k2=0;
for (int i =1; i<=k1; i++) {
k2=k2%n+1;
if (bj[a[k2]]) {
ans[k2]++;
bj[a[k2]]=0;
}
else{
bj[a[k2]]++;
}
// k2++;
}
if (m>2*n) {
ll k3=m/(2*n);
for (int i =1; i<=n; i++){
ans[i]=ans[i]*k3;
}
k2=0;
memset(bj, 0, sizeof bj);
for (int i =1; i<=m%(2*n); i++) {
k2=k2%n+1;
if (bj[a[k2]]) {
ans[k2]++;
bj[a[k2]]=0;
}
else{
bj[a[k2]]++;
}
// k2++;
}
}
for (int i = 1; i<=n; i++) {
cout<<ans[i];
if(i!=n){cout<<' ';
}
}
cout<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
solv();
}
return 0;
}
G
这是一道并查集的题,因为有学长想考并查集,感觉这道题也不错就拉过来了,想通了,也同样很简单。
参加多少人,减多少。相对的,如果参加的里面有两个人是好朋友就加1 。所以我们很容易得到一个结论对于一个点,加入一个与其相关的点肯定是非递减的。
加上去一个减1,而相对的与其相关的点相关则加1,然后新加入的点还有可能与先前已经加入的点相关,若相关则加1,不相关则没有影响,也不会减少。
所以我们用并查集来链接,标记,转移状态。(感觉很板子,本来想拉带权的,但是怕你们都不会,所以换了这道简单的题
/*Looking! The blitz loop this planet to search way
Only my RAILGUN can shoot it 今すぐ
身体中を 光の速さで
駆け巡った確かな予感
掴め! 望むものなら残さず
輝ける自分らしさで
信じてるよ あの日の誓いを
この瞳に光る涙それさえも 強さになるから
*/
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<numeric>
#include<stack>
using namespace::std;
typedef long long ll;
inline __int128 read(){
__int128 x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void print(__int128 x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
print(x / 10);
putchar(x % 10 + '0');
}
//struct dian{
// double x,y;
//}A,B,C,D,E,F;//点
//cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y>>E.x>>E.y>>F.x>>F.y;
//double len(dian x,dian y){
// return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
//}//两点之间距离
//double xj(dian x,dian y,dian z){
// x.x-=y.x;
// x.y-=y.y;
// z.x-=y.x;
// z.y-=y.y;
// return x.x*z.y-x.y*z.x;
//}//叉积
int n,t,m;
int fa[300005];
ll sum[300005];
int a,b;
int fin(int x){
if (fa[x]==x) {
return x;
}
return fa[x]=fin(fa[x]);
}
void uio(int x,int y){
int xx=fin(x);
int yy=fin(y);
if (xx!=yy) {
fa[xx]=yy;
}
else{
sum[yy]++;
}
}
int k =1;
void wanyurukong(){
cin>>n>>m;
for (int i =1; i<=n; i++) {
fa[i]=i;
sum[i]=-1;
}
for (int i =1; i<=m; i++) {
cin>>a>>b;
uio(a, b);
}
set<int>f1;
ll ans=0;
for (int i =1; i<=n; i++) {
int xx=fin(i);
if (f1.count(xx)) {
continue;
}
else{
ans+=max(0*1ll, sum[xx]);
f1.insert(xx);
}
}
printf("Case #%d: %lld\n",k,ans);
k++;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
wanyurukong();
}
//wanyurukong
return 0;
}
H
这个我是把它离散化差分来写了,按照时间的前后来进行排序。如果到了一个同学的时间段我们加1,时间段之后减1,朴实无华的差分。然后我们每次异或,因为异或了想相同的值就等于没有改变。所以我们直接遍历+判断即可。这道题很像 秦皇岛还是哈尔滨或者别的区域赛的 E.Exam Results 的弱化弱化版,那个要 离散化+差分+双指针 来写。
/*Looking! The blitz loop this planet to search way
Only my RAILGUN can shoot it 今すぐ
身体中を 光の速さで
駆け巡った確かな予感
掴め! 望むものなら残さず
輝ける自分らしさで
信じてるよ あの日の誓いを
この瞳に光る涙それさえも 強さになるから
*/
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include <unordered_map>
#include<set>
#include<tuple>
#include<numeric>
using namespace::std;
typedef long long ll;
inline char nc() {
static char buf[1000000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename _Tp> inline void read(_Tp&sum) {
char ch = nc(); sum = 0;
while (!(ch >= '0'&&ch <= '9')) ch = nc();
while (ch >= '0'&&ch <= '9') sum = (sum << 3) + (sum << 1) + (ch - 48), ch = nc();
}
inline __int128 read128(){
__int128 x = 0, f = 1;
char ch128 = getchar();
while(ch128 < '0' || ch128 > '9'){
if(ch128 == '-')
f = -1;
ch128 = getchar();
}
while(ch128 >= '0' && ch128 <= '9'){
x = x * 10 + ch128 - '0';
ch128 = getchar();
}
return x * f;
}
inline void print128(__int128 x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
print128(x / 10);
putchar(x % 10 + '0');
}
//struct dian{
// double x,y;
//}A,B,C,D,E,F;//点
//cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y>>E.x>>E.y>>F.x>>F.y;
//double len(dian x,dian y){
// return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
//}//两点之间距离
//double xj(dian x,dian y,dian z){
// x.x-=y.x;
// x.y-=y.y;
// z.x-=y.x;
// z.y-=y.y;
// return x.x*z.y-x.y*z.x;
//}//叉积
int n,k;
struct we{
ll x,y,z;
};
ll q,w,e;
bool cmp(we a,we b){
if (a.x==b.x) {
return a.z<b.z;
}
return a.x<b.x;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>n>>k;
vector<we>an;
for (int i =1; i<=n; i++) {
cin>>q>>w>>e;
an.push_back({q,e,1});
an.push_back({w+1,e,-1});
}
sort(an.begin(), an.end(), cmp);
int ff=0;
ll na=-1;
ll anf=0;
for (int i =0; i<an.size(); i++) {
if (an[i].z==1) {
ff++;
anf^=an[i].y;
}
else
{
ff--;
anf^=an[i].y;
}
if (ff>=k&&an[i].x!=an[i+1].x) {
na=max(na, anf);
}
// printf("%d\n",ff);
}
printf("%lld\n",na);
return 0;
}
I
朴实无华的19届浙江省赛的第一题,是签到题,最后应该是都能写出来的(如果真的有写不出来的看代码想一下就好了(保底wa两三发的感觉😀 看细心了
/*Looking! The blitz loop this planet to search way
Only my RAILGUN can shoot it 今すぐ
身体中を 光の速さで
駆け巡った確かな予感
掴め! 望むものなら残さず
輝ける自分らしさで
信じてるよ あの日の誓いを
この瞳に光る涙それさえも 強さになるから
*/
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include <unordered_map>
#include<set>
#include<tuple>
#include<numeric>
#include<stack>
using namespace::std;
typedef long long ll;
inline char nc() {
static char buf[1000000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename _Tp> inline void read(_Tp&sum) {
char ch = nc(); sum = 0;
while (!(ch >= '0'&&ch <= '9')) ch = nc();
while (ch >= '0'&&ch <= '9') sum = (sum << 3) + (sum << 1) + (ch - 48), ch = nc();
}
inline __int128 read128(){
__int128 x = 0, f = 1;
char ch128 = getchar();
while(ch128 < '0' || ch128 > '9'){
if(ch128 == '-')
f = -1;
ch128 = getchar();
}
while(ch128 >= '0' && ch128 <= '9'){
x = x * 10 + ch128 - '0';
ch128 = getchar();
}
return x * f;
}
inline void print128(__int128 x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
print128(x / 10);
putchar(x % 10 + '0');
}
//struct dian{
// double x,y;
//}A,B,C,D,E,F;//点
//cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y>>E.x>>E.y>>F.x>>F.y;
//double len(dian x,dian y){
// return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
//}//两点之间距离
//double xj(dian x,dian y,dian z){
// x.x-=y.x;
// x.y-=y.y;
// z.x-=y.x;
// z.y-=y.y;
// return x.x*z.y-x.y*z.x;
//}//叉积
int n,t;
ll a,b;
void wanyurukong(){
cin>>a>>b;
if (a==b) {
printf("0\n");return;
}
if (a>b) {
if (abs(a-b)&1) {
printf("2\n");
}
else{
printf("1\n");
}
}
else{
if (abs(a-b)&1) {
printf("1\n");
}
else{
if ((abs(a-b)/2)&1) {
printf("2\n");
}
else
printf("3\n");
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin>>t;
while (t--) {
wanyurukong();
}
//wanyurukong
return 0;
}