我用超白痴的方法解出了这道题,大家有没有更好的方法
2005-11-11 18:41
211 查看
题目如下
Dick and JaneTime limit: 1 Seconds Memory limit: 32768K
Total Submit: 208 Accepted Submit: 92
Dick is 12 years old. When we say this, we mean that it is at least twelve and not yet thirteen years since Dick was born.
Dick and Jane have three pets: Spot the dog, Puff the Cat, and Yertle the Turtle. Spot was s years old when Puff was born; Puff was p years old when Yertle was born; Spot was y years old when Yertle was born. The sum of Spot's age, Puff's age, and Yertle's age equals the sum of Dick's age (d) and Jane's age (j). How old are Spot, Puff, and Yertle?
Each input line contains four non-negative integers: s, p, y, j. For each input line, print a line containing three integers: Spot's age, Puff's age, and Yertle's age. Ages are given in years, as described in the first paragraph.
Problem Source: University of Waterloo Local Contest 1998.06.06
我用的是傻得无以复加的方法,而且差0.02s就超时了,好险!
//http://acm.zju.edu.cn/show_problem.php?pid=1110
#include<iostream>
using namespace std;
main()
{
const int d=12;
int s,p,y,j;
float sa,pa,ya;
while( scanf("%d%d%d%d",&s,&p,&y,&j)!=EOF)
{
for(ya=0.0;ya<=50;ya+=0.1)
{
for(pa=ya;pa<=ya+p+3;pa+=0.1)
{
for(sa=pa;sa<=ya+y+3;sa+=0.1)
{
if ( (int(sa-pa)==s) && (int(sa-ya)==y) && (int(pa-ya)==p) && (int(sa)+int(pa)+int(ya)==d+j) )
goto finish;
}
}
}
finish:
printf("%.0f %.0f %.0f\n",sa,pa,ya);
}
}
大家有更好的算法吗?
Dick and JaneTime limit: 1 Seconds Memory limit: 32768K
Total Submit: 208 Accepted Submit: 92
Dick is 12 years old. When we say this, we mean that it is at least twelve and not yet thirteen years since Dick was born.
Dick and Jane have three pets: Spot the dog, Puff the Cat, and Yertle the Turtle. Spot was s years old when Puff was born; Puff was p years old when Yertle was born; Spot was y years old when Yertle was born. The sum of Spot's age, Puff's age, and Yertle's age equals the sum of Dick's age (d) and Jane's age (j). How old are Spot, Puff, and Yertle?
Each input line contains four non-negative integers: s, p, y, j. For each input line, print a line containing three integers: Spot's age, Puff's age, and Yertle's age. Ages are given in years, as described in the first paragraph.
Sample Input
5 5 10 9 5 5 10 10 5 5 11 10
Output for Sample Input
12 7 2 13 7 2 13 7 2
Problem Source: University of Waterloo Local Contest 1998.06.06
我用的是傻得无以复加的方法,而且差0.02s就超时了,好险!
//http://acm.zju.edu.cn/show_problem.php?pid=1110
#include<iostream>
using namespace std;
main()
{
const int d=12;
int s,p,y,j;
float sa,pa,ya;
while( scanf("%d%d%d%d",&s,&p,&y,&j)!=EOF)
{
for(ya=0.0;ya<=50;ya+=0.1)
{
for(pa=ya;pa<=ya+p+3;pa+=0.1)
{
for(sa=pa;sa<=ya+y+3;sa+=0.1)
{
if ( (int(sa-pa)==s) && (int(sa-ya)==y) && (int(pa-ya)==p) && (int(sa)+int(pa)+int(ya)==d+j) )
goto finish;
}
}
}
finish:
printf("%.0f %.0f %.0f\n",sa,pa,ya);
}
}
大家有更好的算法吗?
相关文章推荐
- 有没有更好的串口编程的方法?(源)
- 除了循环以外,有没有更好的方法统计数据窗口中处于选中状态的行数?
- 功能测试中数据重复的方法总结,大家有更好的可以留言或一起讨论
- 自己试验在spring的环绕通知里获取目标对象的类名和目标方法的参数类名,用于根据自定义注解判断访问权限,有没有更好的办法,高手指点一下
- 限速 P2P终结者不好使 有没有更好的方法 无线
- 有没有更好的方法
- 大家是否有更好的方法?
- xcode5中如何去掉ARC?难道必须用吗?大家有没有什么解决方法呢?
- 存储过程中 事务的处理 大家有更好的方法请分享 谢谢了。
- 给大家分享下隐藏整个界面软键盘的方法,如果大家有更好的方法也建议下,谢谢了
- (Swing) 在JTable中实现复选框,一种更好的方法
- 什么情况下用+运算符进行字符串连接比调用StringBuffer/StringBuilder对象的append方法连接字符串性能更好?
- 读文件的另外一套更好用的方法(SqlFileObject)
- 用python编写ASP脚本时遇到的问题,初步的解决方法,目前正在寻找更好的解决办法。
- 构造方法有没有必要写super()
- [面试题] - 有没有其他方法获取单例模式类实例
- 一个可能存在Bug的二分查找方法的实现,大家一起看看有什么问题没
- 大家有没有发现环信即时通讯云宕机严重,并且所使用的ejabberd违反了开源协议
- 六种方法,做一名更好的开发者
- 三个方法让你成为更好的程序员