Dasha and Stairs
来源:互联网 发布:淘宝内衣模特王文雨 编辑:程序博客网 时间:2024/06/06 02:35
题目链接 http://codeforces.com/problemset/problem/761/A
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the l-th to the r-th (1 ≤ l ≤ r), for which values that Dasha has found are correct.
In the only line you are given two integers a, b (0 ≤ a, b ≤ 100) — the number of even and odd steps, accordingly.
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
2 3
YES
3 1
NO
输入两个数a,b分别表示偶数个数和技术个数。问是否存在L~R(1 ≤ L ≤ R),是的在L~R这个区间内存在a个偶数,b个奇数。如果存在,输出YES,否则输出NO。
解题思路:
其实只需满足两个条件即可:1=>a-b的绝对值>=0;如果输入的a=b=0,那么显然是不存在的。
代码:
#include<iostream>#include<cmath>using namespace std;int main(){ int a,b; while(cin>>a>>b) { if(a==0&&b==0) { cout<<"NO"<<endl; continue; } if(abs(a-b)>=0&&abs(a-b)<=1) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
- Codeforces761A. Dasha and Stairs
- A. Dasha and Stairs
- Codeforces761A Dasha and Stairs
- Dasha and Stairs
- Dasha and Stairs
- codeforces 753 A. Dasha and Stairs
- 【codeforces 761A】Dasha and Stairs
- Codeforces-Round 394#A-Dasha and Stairs
- CF761 A. Dasha and Stairs (水题)
- Codeforces 761A-Dasha and Stairs
- poj 761A Dasha and Stairs
- CodeForces 761A Dasha and Stairs【水题】
- CodeForces-761A-Dasha and Stairs [水题]
- Codeforcrs 761 A Dasha and Stairs
- codeforces 761A Dasha and Stairs
- Codeforces Round #394 (Div. 2)(A. Dasha and Stairs,B. Dasha and friends,C. Dasha and Password)
- Codeforces Round #394 (Div. 2)Dasha and Stairs
- Codeforces Round #394(Div. 2)A.Dasha and Stairs【水题】
- K近邻算法
- 每秒百万级流式日志处理架构的开发运维调优笔记
- D3 笔记七:交互事件、event、this
- 一起走进Java虚拟机的世界 —— 为什么要弄懂虚拟机
- DOM编程-事件(二)
- Dasha and Stairs
- C#中数组的属性和方法
- 框架学习之struts2-05文件上传、下载、ajax整合json
- Golang爬虫基础:通过代理IP发送请求
- CSS测试题
- [leetcode] 257. Binary Tree Paths
- DOM编程-事件(三)
- Linux 查找工具 find、grep
- 【简记】Java Web 内幕——Mybatis框架小结