题解:UVA10257 Dick and Jane
wenqinghua1001 · · 题解
前言
题目传送门
看懂题目的人,英语至少过了十级。
题目大意
- Dick
12 岁。 - Puff the cat 出生时,Spot the dog 是
s 岁。 - Yertle the turtle 出生时,Puff the cat 是
p 岁 - Yertle the turtle 出生时,Spot the dog 是
y 岁。 - Spot the dog、Puff the cat 和 Yertle the turtle 的年龄之和等于 Dick 和 Jane 的年龄之和。
问:Spot the dog、Puff the cat 和 Yertle the turtle 多大了?
题目简化
设 Spot the dog 是
-
X=Y+s -
Y=Z+p -
X=Z+y -
X+Y+Z=12+j
求
思路
根据以上题意,列出式子:
代入
简化得:
将上式代入
将上式代入
::::warning[警告1]{open}
求出了
特判时可能
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int s,p,y,j;
while(cin>>s>>p>>y>>j){
// 多组数据
int X=(j-y-p+12)/3+y;
int Y=(j-y-p+12)/3+p;
int Z=(j-y-p+12)/3;
// X,Y,Z的答案
int tepan=(j-y-p+300)%3;
// 特判
// if(tepan==0)
// 直接除,不需特判
if(tepan==1){
// 比较复杂的情况
if(s+p==y){
// 抵消
X++;
}
else
Y++;
}
if(tepan==2){
X++;
Y++;
}
cout<<X<<" "<<Y<<" "<<Z<<endl;
}
return 0;
}