首页 > 其他分享 >HDOJ1194 Beat the Spread!

HDOJ1194 Beat the Spread!

时间:2023-02-20 10:34:03浏览次数:34  
标签:HDOJ1194 scanner Beat System int Spread scores println impossible


Beat the Spread!


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7501    Accepted Submission(s): 3956


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


 


import java.util.Scanner;

public class Main{
private static Scanner scanner;
public static void main(String[] args) {
scanner = new Scanner(System.in);
int cases = scanner.nextInt();
while(cases-->0){
int a = scanner.nextInt();
int b = scanner.nextInt();
if(a<b){
System.out.println("impossible");
continue;
}
if((a+b)%2!=0 || (a-b)%2!=0){
System.out.println("impossible");
}else {
System.out.println((a+b)/2+" "+(a-b)/2);
}
}
}
}
/*
int a = scanner.nextInt();
int b = scanner.nextInt();
int m = (a+b)/2;
int n = (a-b)/2;
if(m<0 || n<0 || (a+b)%2!=0 || (a-b)%2!=0){
System.out.println("impossible");
}else {
System.out.println(m+" "+n);
}
*/
/*
输入2个数 a,b。
a是m,n的和,b是m,n的差。(m,n只能为正整数或者0)
如果m,n中出现了负数就输出impossible。
要注意的是m=(a+b)/2;n=(a-b)/2;
因为m,n是正整数,所以(a+b)%2==0且(a-b)%2==0;
*/



标签:HDOJ1194,scanner,Beat,System,int,Spread,scores,println,impossible
From: https://blog.51cto.com/u_15741949/6067734

相关文章

  • hertzbeat告警监控系统
    github地址:​​https://github.com/dromara/hertzbeat​​dockerrun-d-p1157:1157--namehertzbeattancloud/hertzbeat默认用户名密码:root/hertzbeat......
  • filebeat+elasticsearch+kibana
    一、到elasticsearch官网下载filebeat+elasticsearch+kibanahttp://www.elasticsearch.cn/ 二、新增fbeat用户tar-xzvffilebeat-7.16.3-linux-x86_64.tar.gz-C......
  • Svelte框架结合SpreadJS实现表格协同文档
    SpreadJS是葡萄城结合40余年专业控件技术和在电子表格应用领域的经验而推出的纯前端表格控件。作为一个类Excel控件,SpreadJS如何实现当前比较流行的表格协同呢?本篇文章将......
  • ElasticSearch+Kibana+Filebeat+Head搭建日志采集系统
    安装步骤如下:1.进入elasticsearch官网下载:​​​https://www.elastic.co/downloads/elasticsearch​​​cd/usr/local/wget​​https://artifacts.elastic.co/download......
  • (19)go-micro微服务filebeat收集日志
    目录一Filebeat介绍二FileBeat基本组成三FileBeat工作原理四Filebeat如何记录文件状态:五Filebeat如何保证事件至少被输出一次六安装Filebeat七使用Filebeatfilebea......
  • filebeat->kafka->logstash->es->kibana
    filebeat部分(k8s)filebeat.ymlapiVersion:apps/v1kind:DaemonSetmetadata:name:filebeatnamespace:kube-systemspec:selector:matchLabels:......
  • filebeat7.9.2设置字段
    当测试环境的日志类型有多个时,比如,NGINX,jar包日志,等等,用filebeat采集日志时可以设置多个字段,编辑filebeat.ymlfilebeat.inputs:-type:logenabled:truepaths:-/v......
  • 【Elastic Search】Logstatsh & FileBeat
    Logstash:Data转换,分析,提取,丰富及核心操作:https://blog.csdn.net/UbuntuTouch/article/details/100770828Beats家族(如FileBeat)参考:ES官方博客:Beats入门教程......
  • 【论文导读】- SpreadGNN: Serverless Multi-task Federated Learning for Graph Neur
    文章目录​​论文信息​​​​摘要​​​​SpreadGNNFramework​​​​用于图层次学习的联邦图神经网络​​​​图神经网络的联邦多任务学习​​​​SpreadGNN​​​​DPA-......
  • 如何利用filebeat把不同服务器上的log4j日志传输到同一台ELK服务器
    1.问题描述 我们需要将不同服务器(如WebServer)上的log4j日志传输到同一台ELK服务器,介于公司服务器资源紧张(^_^)2.我们需要用到filebeat什么是filebeat?filebeat被用来......