problem 1110

来源:互联网 发布:windows 系统修复 编辑:程序博客网 时间:2024/04/29 15:44

分别记Spot、Puff、Yertle的年龄为a1、a2、a3。由题意列方程组:
①a1 = s + a2 + b1(Spot was s years old when Puff was born)
②a2 = p + a3 + b2(Puff was p years old when Yertle was born)
③a1 = y + a3 + b3(Spot was y years old when Yertle was born)
④a1 + a2 + a3 = 12 + j(The sum of Spot's age, Puff's age, and Yertle's age equals the sum of Dick's age (12) and Jane's age (j))
其中b1,b2,b3为待定常数,它们只能取0或1。枚举b1, b2, b3即可。
 

#include<stdio.h>
int s,p,y,j;
bool solve(int b1, int b2, int
 b3)
{
    
int a1 = 0, a2 = 0, a3 = 0
;
    
if(y + b3 == s + p + b1 +
 b2)
    {
        a2 
= j - s - b1 + p +
 b2;
        
if(a2 % 3 == 0
)
        {
            a2 
= a2 / 3
;
            a1 
= s + a2 +
 b1;
            a3 
= a2 - p -
 b2;
            
if(a1 + a2 + a3 ==
 j)
            {
                printf(
"%d %d %d/n"
, a1, a2, a3);
                
return true
;
            }
        }
    }
    
return false
;
}
int
 main()
{
#ifndef ONLINE_JUDGE
    freopen(
"1110.txt","r"
,stdin);
#endif

    
while(scanf("%d%d%d%d",&s,&p,&y,&j)!=EOF)
    {
        j 
+= 12
;
        
if(solve(000|| solve(001||
 
           solve(
010|| solve(011||
 
           solve(
100|| solve(101||
 
           solve(
110|| solve(111
));
    }
#ifndef ONLINE_JUDGE
    fclose(stdin);
#endif

    
return 0;
}
原创粉丝点击