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(0, 0, 0) || solve(0, 0, 1) ||
solve(0, 1, 0) || solve(0, 1, 1) ||
solve(1, 0, 0) || solve(1, 0, 1) ||
solve(1, 1, 0) || solve(1, 1, 1));
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
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(0, 0, 0) || solve(0, 0, 1) ||
solve(0, 1, 0) || solve(0, 1, 1) ||
solve(1, 0, 0) || solve(1, 0, 1) ||
solve(1, 1, 0) || solve(1, 1, 1));
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
- problem 1110
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- two improvement to the "drop all table with T-SQL" solution
- 一个程序员的成长的六个阶段
- 实现表格交替颜色
- VHDL编程设计技巧
- ASP.NET遇到问题---onmouseover
- problem 1110
- ASP.NET里常用的JS
- 第二人生的源码分析(四十一)使用Apache运行库线程
- J2ME Custom Text Input
- 使用 /proc 文件系统来控制系统[转贴]
- 第二人生客户端程序, 第一部分: 探索第二人生
- j2ee(SSH)项目开发中的代码小结(四)
- baidu收录速度明显慢了
- 面试常见问题heibernate中sessin的get和load方法区别的实验解说