杭电ACM1194——Beat the Spread!
来源:互联网 发布:中国人寿储备主管知乎 编辑:程序博客网 时间:2024/06/04 00:58
简单的数学题目,就是解方程。
不过需要注意的是,解出来的两个解没有负数。
输入m和n,方程1:x + y = m;方程2:| x - y | = n;
x = (n + m)/ 2; y = (-n + m)/ 2;
注意:n + m和m - n 必须是偶数!~~做个判断就OK了。
AC的代码:
#include <iostream>using namespace std;int main(){int t, a, b;cin >> t;while(t--){cin >> a >> b;if((b + a) % 2 && (-b + a) % 2){cout << "impossible" << endl;continue;}int ans_1 = (b + a) / 2;int ans_2 = (-b + a) / 2;if(ans_1 > 0 && (b + a) % 2 == 0 && a - ans_1 > 0)cout << ans_1 << ' ' << a - ans_1 << endl;else if(ans_2 > 0 && (-b + a) % 2 == 0 && a - ans_2 > 0)cout << ans_2 << ' ' << a - ans_2 << endl;elsecout << "impossible" << endl;}return 0;}
1 0
- 杭电ACM1194——Beat the Spread!
- 杭电 HDU 1194 Beat the Spread!
- 杭电 OJ 1194 Beat the Spread!
- Beat the Spread!
- Beat the Spread! (P2301)
- zoj2388----------------Beat the Spread!
- HDU1194:Beat the Spread!
- 10812 - Beat the Spread!
- zoj_2388 Beat the Spread!
- hdu1194-Beat the Spread!
- zoj Beat the Spread!
- zoj2388 Beat the Spread!
- Beat the Spread!
- Beat the Spread!
- 1194:Beat the Spread!
- 1194 Beat the Spread!
- [1194]:Beat the Spread!
- ZOJ2388 Beat the Spread!
- 基于sqoop的导入导出操作
- shader入门 《顶点着色器 与 片段(像素)着色器》概念
- 用android studio导入项目的常见问题
- C++编程的一些笔记
- Ubuntu14.04搭建Android Studio
- 杭电ACM1194——Beat the Spread!
- git 上传本地文件到github
- 【VR】Leap Motion 官网文档 手型资源
- 双端队列简要实现
- 3D dungeon
- Altium Designer 中Device Sheet Symbol 与 Sheet Symbol 的使用
- css基础学习之css sprite(css精灵)
- mysql事务隔离级别
- C++多态性 虚函数与纯虚函数 重载与覆盖