1 条题解
-
0
题意分析
题目要求在超级碗比赛期间,当地的黑客组织了一个赌局,赌的是比赛的两个最终得分的和()以及它们的绝对差()。给定这两个数字 和 ,我们需要推断出这两个得分。如果不存在这样的得分,则输出“impossible”。
解题思路
-
数学推导:设两个得分分别为 和 ,其中 。根据题意,有:
-
解方程组:将这两个方程联立,可以解得:
-
合法性检查:为了确保 和 是有效的得分,必须满足以下条件:
- 和 都是非负整数。
- (即 )。
- (因为 )。
实现步骤
- 输入处理:读取输入的测试用例数量 ,然后逐个处理每个测试用例的 和 。
- 计算得分:对于每个测试用例,计算 和 。
- 合法性验证:
- 检查 且 是偶数(确保 和 是整数)。
- 检查 和 是否为非负整数。
- 输出结果:如果合法,输出 和 ;否则,输出“impossible”。
代码实现
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; ll a,b; int main() { int t; cin>>t; while(t--) { scanf("%lld%lld",&a,&b); if(a<b) { puts("impossible");continue; } ll ans1 = (a+b)>>1; if(ans1*2 != (a+b)) { puts("impossible");continue; } ll ans2 = a-ans1; if(ans1 < ans2) swap(ans1,ans2); printf("%lld %lld\n",ans1,ans2); } return 0 ; }
-
- 1
信息
- ID
- 1302
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 2
- 上传者