杭电1194-Beat the Spread

//题目大意:已知两个整数的和与差,求这两个整数
//收获:1. absolute difference between the two scores. 指的是两个分数的差的绝对值
             2.对于数学类问题,在写代码前,就要用数学知识对其进行化简,功夫应该是在数学上,真正化简后,代码很简单
//AC代码

#include<iostream>
using namespace std;
int main()
{
	//已知两个整数的和与差,求这两个数 
	int T,x,y,sum,dif;
	cin>>T;
	while(T>=1)
	{
		//主体过程
		cin>>sum;
		cin>>dif;
		if((sum+dif)%2==0&&(sum>=dif)&&(sum-dif)%2==0)  //判断是否符合要求 
		{
			x=(sum+dif)/2;
			y=(sum-dif)/2;
			cout<<x<<" "<<y<<endl; 
		 } 
		 else
		 {
		 	cout<<"impossible\n";
		 }
		T--;
	}
	 
 } 

猜你喜欢

转载自blog.csdn.net/liangwgl/article/details/79450811