AtCoder Grand Contest 008 A
Problem Statement
Snuke has a calculator. It has a display and two buttons.
Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:
- Button A: When pressed, the value on the display is incremented by 1.
- Button B: When pressed, the sign of the value on the display is reversed.
Find the minimum number of times Snuke needs to press the buttons to achieve his objective. It can be shown that the objective is always achievable regardless of the values of the integers x and y.
Constraints
- x and y are integers.
- |x|,|y|≤109
- x and y are different.
Input
The input is given from Standard Input in the following format:
x y
Output
Print the minimum number of times Snuke needs to press the buttons to achieve his objective.
Sample Input 1
10 20
Sample Output 1
10
Press button A ten times.
Sample Input 2
10 -10
Sample Output 2
1
Press button B once.
Sample Input 3
-10 -20
Sample Output 3
12
Press the buttons as follows:
- Press button B once.
- Press button A ten times.
- Press button B once.
题意:告诉我们两个数字,两种操作,一种是+1,一种是改变正负,问最小进行几次操作可以将x变成y
解法:讨论讨论讨论。。。。(注意等于0的情况)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n,m;
cin>>n>>m;
// cout<<min(abs(m-n),min(abs(-1*n-m)+1,min(abs(-1*n+m)+1,min(abs(-1*n+m)+2,abs(-1*n-m)+2))))<<endl;
// if(n==m) continue;
// cout<<n<<" "<<m<<" ";
if(n<m)
{
ll pos=n*(-);
if(n>=&&m>=)
{
//3 5
cout<<m-n<<endl;
}
else if(n<=&&m>=)
{
//-3 5
//3 5
//-3 2
//-3+1=-2 2
if(pos<=m)
{
if(n!=)
{
cout<<m-pos+<<endl;
}
else
{
cout<<m-pos<<endl;
}
}
else
{
// cout<<"A"<<endl;
//ll ans=pos-m;
if(m==)
{
cout<<pos<<endl;
}
else
cout<<pos-m+<<endl;
}
}
else if(n<=&&m<=)
{
//-3 -2
cout<<pos+m<<endl;
}
}
else
{
if(n>=&&m>=)
{
//4 2
if(m!=)
{
cout<<n-m+<<endl;
}
else
{
cout<<n+m+<<endl;
}
}
else if(n>=&&m<=)
{
ll pos=-*m;
if(n==)
{
cout<<-*m+<<endl;
}
else
{
if(n<=pos)
{
cout<<pos-n+<<endl;
}
else
{
cout<<n+m+<<endl;
}
}
}
else
{
if(n==)
{
cout<<(-)*m+<<endl;
}
else
{
cout<<(-)*m-(-)*n+<<endl;
}
}
}
return ;
}
AtCoder Grand Contest 008 A的更多相关文章
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 008 D - K-th K
题目传送门:https://agc008.contest.atcoder.jp/tasks/agc008_d 题目大意: 给你一个长度为\(N\)的序列\(A\),请你构造一个长度为\(N^2\)的序 ...
- Atcoder Grand Contest 008 E - Next or Nextnext(乱搞+找性质)
Atcoder 题面传送门 & 洛谷题面传送门 震惊,我竟然能独立切掉 AGC E 难度的思维题! hb:nb tea 一道 感觉此题就是找性质,找性质,再找性质( 首先看到排列有关的问题,我 ...
- AtCoder Grand Contest 008题解
传送门 \(A\) 分类讨论就行了 然而我竟然有一种讨论不动的感觉 int x,y; inline int min(R int x,R int y){return x<y?x:y;} inlin ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
随机推荐
- PL/SQL %TYPE和%ROWTYPE的区别【转】
%TYPE: 定义一个变量,其数据类型与已经定义的某个 数据变量的类型相同,或者与数据库表的某个列的数据类型 相同,这时可以使用%TYPE. 使用%TYPE 特性的优点在于: 1.所引 ...
- idea使用心得(2)-安装设置与创建web项目
idea 是与eclipse齐名的IDE(集成开发工具),以智能闻名,不过对于熟悉eclipse的的用户来说,初次接触idea有些让人搞不清方向,下面介绍一下简单的使用 方式. 1.安装 官网下载ul ...
- Python学习【第六篇】运算符
运算符 算数运算: a = 21 b = 10 c = 0 c = a + b print ("1 - c 的值为:", c) c = a - b print ("2 - ...
- Jmeter学习(三十三)调试工具Debug Sampler
一.Debug Sampler介绍: 使用Jmeter开发脚本时,难免需要调试,这时可以使用Jmeter的Debug Sampler,它有三个选项:JMeter properties,JMeter v ...
- Python之路-python(css布局、JavaScript)
CSS布局 JavaScript css布局: 后台管理界面一:(左右标签都有下来菜单) 利用position: absolute;让某个标签固定在具体位置,然后使用overflow: auto;属性 ...
- python成长之路-----day1-----作业(登录程序和三级菜单)
作业: 作业1:用户登录 1)程序说明: a.用户输入密码验证成功然后打印欢迎信息 b.如果密码错误,用户登录失败,提示用户,密码错误 c.用户输入密码错误3次,则用户锁定 d.当用户多次输入不存在的 ...
- new一張form時用using{}的好處。
以下代碼,用Using可避免一些問題,例如handel10000.如果PaymentForm裏面用dialogresult=''而不是close或X,(close或X會即時dispose回收,但dia ...
- Windows Phone 十九、罗盘
磁力计概述 拥有磁力计硬件支持的设备可以根据磁力计来确定相对于北极的角度 磁力计的访问 API 定义在 Compass 类中 调用方式和加速计类似 <Grid Background=" ...
- Linux操作系统备份之二:通过tar拷贝分区实现Linux操作数据的在线备份
http://www.tektea.com/archives/2163.html. 在<Linux操作系统备份之一:使用LVM快照实现Linux操作系统数据的在线备份>文章中,我们介绍了使 ...
- oracle 11g 服务启动时提示1053错误,服务启动不了,重新配置监听解决问题
早上发现oracle服务启动不了了,找了很多资料,没找到有用的.通过重新配置监听解决问题.