A - Add Odd or Subtract Even
A - Add Odd or Subtract Even



思路:其实认真观察就能发现,这个与输入的书有关系,且答案为0,1,2。先看相同,不用加减,为0,再看前小后大,因为加奇数减偶数,如果,相差奇数,为1,相差偶数,为2,同理可得前大后小的答案。
代码:
#include<iostream>
#include<cmath>
using namespace std; int main(){
std::ios::sync_with_stdio(false);
int a, b, sum, n;
cin >> n;
while (n--){
cin >> a >> b;
if (a == b)
cout << "0" << endl; else if (a < b){
sum = b - a;
if (sum % 2 == 0)
cout << "2" << endl;
else
cout << "1" << endl;
}
else{
sum = a - b;
if (sum % 2 == 0)
cout << "1" << endl;
else
cout << "2" << endl;
}
}
return 0;
}
A - Add Odd or Subtract Even的更多相关文章
- Codeforce 1311A Add Odd or Subtract Even
Add Odd or Subtract Even time limit per test2 seconds memory limit per test256 megabytes inputstanda ...
- [CF1311A] Add Odd or Subtract Even
Solution a<b, delta=odd, ans=1 a<b, delta=even, ans=2 a=b ans=0 a>b, delta=odd, ans=2 a> ...
- Codeforces Round #624 (Div. 3) A. Add Odd or Subtract Even(水题)
You are given two positive integers aa and bb . In one move, you can change aa in the following way: ...
- deep_learning_Function_tf.add()、tf.subtract()、tf.multiply()、tf.div()
tf.add().tf.subtract().tf.multiply().tf.div()函数介绍和示例 1. tf.add() 释义:加法操作 示例: x = tf.constant(2, dtyp ...
- Codeforces补题2020.2.28(Round624 Div 3)
A.Add Odd or Subtract Even 签到题~ #include<bits/stdc++.h> using namespace std; int T; int a,b; i ...
- Codeforces Round #624 (Div. 3)(题解)
A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...
- HDU 4919 Exclusive or 数学
题意: 定义 \[f(n)=\sum\limits_{i=1}^{n-1}(i\oplus (n-i))\] 求\(f(n),n \leq 10^{500}\) 分析: 这个数列对应OEIS的A006 ...
- 缓冲区溢出利用——捕获eip的傻瓜式指南
[译文] 摘要:为一个简单的有漏洞程序写一个简单的缓冲区溢出EXP,聚焦于遇到的问题和关键性的教训,提供详细而彻底的描述 内容表:1. I pity the fool, who can't smash ...
- [开源].NET数据库访问框架Chloe.ORM
扯淡 13年毕业之际,进入第一家公司实习,接触了 EntityFramework,当时就觉得这东西太牛了,访问数据库都可以做得这么轻松.优雅!毕竟那时还年轻,没见过世面.工作之前为了拿个实习机会混个工 ...
- Beginning Scala study note(4) Functional Programming in Scala
1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...
随机推荐
- ARM的发展史以及架构解析
本文从ARM的发展历史着手,以S3C2440为例与51单片机进行对比分析,详细解析了ARM架构. 先来谈一下ARM的发展史:1978年12月5日,物理学家Hermann Hauser和工程师Chris ...
- 新装Eclipse运行Java程序报错Exception in thread "main" java.lang.UnsupportedClassVersionError
错误现象: Exception in thread "main" java.lang.UnsupportedClassVersionError: views/LoginFram ...
- global 函数
x = 15 # 全局变量Gdef func_a(): print(x)def func_b(): print(x)def func_c(): global x # 在定义函数内声明x为全局变量后,才 ...
- a菜单点击标红,其他标黑代码
<script> let aList = document.querySelectorAll('a'); console.log(aList); for (let index = 0; i ...
- php不缓存直接输出
ini_set('max_execution_time', 600); header('X-Accel-Buffering:no'); ob_end_flush(); $l_zhen = \M('zh ...
- css样式 div垂直水平居中对齐
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 网页端微信小程序客服
https://mpkf.weixin.qq.com/ 可以设置自动回复
- Hadoop 设置静态IP、关闭防火墙
设置静态IP [root@localhost ~]# cd /etc[root@localhost etc]# cd sysconfig[root@localhost sysconfig]# cd n ...
- 把本地项目上传到github
一在本地项目文件内,git初始化,并add, commit cd /test/xxxdemo git init add . commit -m "inits" 二在github创建 ...
- Abp框架使用Swgger注释加分组
1.在ConfigureSwaggerServices中配置SwaggerDoc,并options.DocInclusionPredicate((doc, desc) => { return d ...