Wednesday, February 22, 2012

My UVA 11715 Cars solution


http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2762


#include <cstdio>
#include <cmath>
#include <iostream>


using namespace std;


int main(int ar, char*av[])
{
    int T=1;
    int c;
    
    while(true)
    {
      cin>>c;
      if(c==0)return 0;


      double u,v,t,a,s;
      
      if(c==1)
      {
        cin>>u>>v>>t;
        a=(v-u)/t;
        s=u*t+0.5*a*(pow(t,2.0));
        printf("Case %d: %.3f %.3f\n",T,s,a);                
      }
      else if(c==2)
      {
        cin>>u>>v>>a;
        t=(v-u)/a;
        s=u*t+0.5*a*(pow(t,2.0));
        printf("Case %d: %.3f %.3f\n",T,s,t);                
      }
      else if(c==3)
      {
        cin>>u>>a>>s;
        t=(sqrt(u*u+2.0*s*a)-u)/(a);
        v=t*a+u;      
        printf("Case %d: %.3f %.3f\n",T,v,t);                
      }
      else if(c==4)
      {
        cin>>v>>a>>s;
        u=sqrt(v*v-2.0*s*a);
        t=(v-u)/a;
        printf("Case %d: %.3f %.3f\n",T,u,t);                
      }
      
      T++;
    };
    
    return 0;
}

No comments:

Post a Comment