HDOJ 1194 Beat the Spread!(简单题)
Problem Description
Superbowl Sunday is nearly here. In order to pass the time waiting for the half-time commercials and wardrobe malfunctions, the local hackers have organized a betting pool on the game. Members place their bets on the sum of the two final scores, or on the absolute difference between the two scores.
Given the winning numbers for each type of bet, can you deduce the final scores?
Input
The first line of input contains n, the number of test cases. n lines follow, each representing a test case. Each test case gives s and d, non-negative integers representing the sum and (absolute) difference between the two final scores.
Output
For each test case, output a line giving the two final scores, largest first. If there are no such scores, output a line containing “impossible”. Recall that football scores are always non-negative integers.
Sample Input
2
40 20
20 40
Sample Output
30 10
impossible
题意:输入2个数 a,b。
a是x,y的和,b是x,y的差。(x,y只能为正整数或者0)
如果x,y中出现了负数就输出impossible。
要注意的是x=(a+b)/2;y=(a-b)/2;
因为x,y是正整数,所以(a+b)%2==0且(a-b)%2==0;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int a = sc.nextInt();
int b = sc.nextInt();
int x=(a+b)/2;
int y=(a-b)/2;
if(x<0||y<0||(a+b)%2!=0||(a-b)%2!=0){
System.out.println("impossible");
}else{
System.out.println(x+" "+y);
}
}
}
}
HDOJ 1194 Beat the Spread!(简单题)的更多相关文章
- HDOJ 1326 Box of Bricks(简单题)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- HDU 1194 - Beat the Spread!
给两数之和和两数之差,求两数,两数还必须同奇偶 #include <iostream> using namespace std; int main() { int a,b,t; cin&g ...
- DFS HDOJ 2614 Beat
题目传送门 /* 题意:处理完i问题后去处理j问题,要满足a[i][j] <= a[j][k],问最多能有多少问题可以解决 DFS简单题:以每次处理的问题作为过程(即行数),最多能解决n个问题, ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- 这样leetcode简单题都更完了
这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
随机推荐
- [RxJS] Creation operators: fromEventPattern, fromEvent
Besides converting arrays and promises to Observables, we can also convert other structures to Obser ...
- crtmpserver 基本流程分析
近期在研究crtmpserver,这里记录下学习过程,首先我们先分析下基本流程. 1.初始化流程 InitNetworking---初始化网络 Initialize Logger::Init()--- ...
- Scala学习笔记之:tuple、array、Map
[TOC] 本文<快学Scala>的笔记 tuple学习笔记 tuple的定义 对偶是元组(tuple)的最简单形态--元组是不同类型的值的聚集. 元组的值是通过将单个值包含在圆括号中构成 ...
- 为什么要配置path环境变量?
一:关于path环境变量--为了在任意目录下,使用javac/java命令 第一种配置方法: 通过配置path环境变量,我们可以使某个程序,比如javac.exe,在任意目录下都可以运行,而不用跑到j ...
- yii cgridview 对生成的数据进行分页
这个其实最简单 在对应的model里找Search方法 找到后,参见如下代码 public function search() { // @todo Please modify the followi ...
- 国内使用google地图的初级使用
<!DOCTYPE html><html><head><title>Simple Map</title><meta name=&quo ...
- (转)background-position—CSS设置背景图片的位置
background-position :在 CSS 中通过 background-position 属性可以调整背景图片的位置.因为在默认情况下背景图片都是从设置了 background-posit ...
- 关于服务器防火墙和discuz论坛的问题
今天做了一个b2b商城,其中的论坛用的是discuz论坛 .net版本,主页要取出其中三个板块的最新帖子数据,安装好后,帖子数据在dnt_posts1数据表里,其中的tid为外链表dnt_forums ...
- (转)asp.net 使用cookie完成记住密码自动登录
代码如下 复制代码 string username = this.txtUserName.Text;//用户名 string password = this.txtPassword.T ...
- js鼠标右键操作
一个页面中,BODY中用oncontextmenu='return false'来取消鼠标右键: 在JS中设置oncontextmenu='return true'用window.document. ...