2013年12月14日 星期六

[UVA] 10071 - Back to High School Physics

/*20131215 hanting*/
//****************************************//
//                                        //
//  (速度)|        /                     //
//        |      /b.                     //
//       v|..../....                     //
//        |a /.    .                     //
//      vo|/c . d  .                     //
//        |____.____.___                  //
//             t   2t  (時間)             //
//                                        //
//   所求等於  c+b+d = a+c+d = v*2t       //
//****************************************//
#include <iostream>
using namespace std;
int main()
{
    int v,t;
    while(cin>>v>>t)
    {
        cout<<v*t*2<<endl;
    }
    return 0;
}

[UVA] 12468 - Zapping

/*20131215 hanting*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b && a!=-1 && b!=-1)
    {
        int tem1=abs(b-a);
        int tem2=100-abs(b-a);
        if(tem1>tem2)
        {
            cout<<tem2<<endl;
        }
        else
        {
            cout<<tem1<<endl;
        }
    }
    return 0;
}

[UVA] 11364 - Parking

/*20131215 hanting*/
#include <iostream>
using namespace std;
void change(int &a,int &b)//兩數交換
{
    int tema=a;
    a=b;
    b=tema;
}
void compare(int a[],int n)//排大小
{
    for(int i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            change(a[i],a[i-1]);
            i=0;
        }
    }
}
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        int n;
        cin>>n;
        int address[n];
        for(int i=0;i<n;i++)
        {
            cin>>address[i];
        }
        compare(address,n);
        int total=0;
        for(int i=1;i<n;i++)
        {
            total+=address[i]-address[i-1];
        }
        cout<<2*total<<endl;
    }
    return 0;
}