zoukankan      html  css  js  c++  java
  • 我用超白痴的方法解出了这道题,大家有没有更好的方法

    题目如下

    Dick and Jane

    Time 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);

        }

    }


    大家有更好的算法吗?

  • 相关阅读:
    关于命题“网络规划中一个VLAN要对应一个网段”的证明
    详谈为何两台主机网络掩码不一致可能导致ping不通
    为什么电脑的ip地址要和网关的ip同一个子网才可以上网?
    快速理解VirtualBox的四种网络连接方式(最详细)
    Ubuntu 16.04下安装OpenStack(juno)之add the compute service报错分析
    Ubuntu 16.04下安装OpenStack(juno) 之add the image service报错分析
    曲线
    Best Cow Fences
    愤怒的牛
    斐波那契数
  • 原文地址:https://www.cnblogs.com/Jonlee/p/274279.html
Copyright © 2011-2022 走看看