zoukankan      html  css  js  c++  java
  • [结题报告]10812 Beat the Spread! Time limit: 3.000 seconds

    Problem D: Beat the Spread!

    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?

    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. 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
    

    Output for Sample Input

    30 10
    impossible

    参考代码:
    这道题给定2个数的和和差,需要求出这2个数,我们可以得到2个方程:x+y=a;x-y=b;联立可得到x=(a+b)/2;y=(a-b)/2;而通过联系实际我们可以知道:1.分数不可能为负数.(这点题目已告知).2.比赛分数一定为整数.注意到这两点,这题就能解出.
    #include"stdio.h"
    main()
    {long n,a,b,x,y,s,flag;
     scanf("%ld",&n);
     while(n--)
     {scanf("%ld%ld",&a,&b);
      flag=0;
      x=(a+b)/2;
      y=(a-b)/2;
      s=a+b;    
      if(s%2!=0) printf("impossible\n");  //a+b若为奇数,则x讲不会是整数。 
      else if(x<0||y<0) printf("impossible\n");
      else printf("%ld %ld\n",x,y);
               }
          }
  • 相关阅读:
    Wireshark教程
    存储基础知识4——
    java核心技术 要点笔记3
    java核心技术 要点笔记2
    java核心技术 要点笔记1
    java Vamei快速教程22 内存管理和垃圾回收
    java Vamei快速教程21 事件响应
    php框架练习
    php之图片处理类缩略图加水印
    php之框架增加日志记录功能类
  • 原文地址:https://www.cnblogs.com/sjy123/p/2917066.html
Copyright © 2011-2022 走看看