顯示具有 UVa 標籤的文章。 顯示所有文章
顯示具有 UVa 標籤的文章。 顯示所有文章

2012年4月3日 星期二

UVa 591

#include <cmath>

using namespace std;

int main()
{
    int n = 0, counter = 1;

    while ( cin >> n && n != 0 )
    {
        int *ptr, sum = 0, average = 0;
        ptr = new int [n];

        for (int i = 0; i < n; i++)
        {
            cin >> ptr[i];
            sum += ptr[i];
        }

        sum /= n;

        for (int i = 0; i < n; i++)
        {
            average += abs(sum - ptr[i]);
        }

        cout << "Set #" << counter << endl;
        cout << "The minimum number of moves is " << average / 2 << "." << endl << endl;

        counter++;
        delete [] ptr;
    }

    return 0;
}

UVa 476

#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    char word;
    int endPtr = 0, counter = 0;
    
    double ptr[11][5];
    for (int i = 0; i < 11; i++)
        for (int j = 0; j < 5; j++)
            ptr[i][j] = 0.0;
        
    while ( true )
    {
        cin >> word;
        if (word == '*')
        {
            endPtr = counter;
            break;
        }

        cin >> ptr[counter][1] >> ptr[counter][2] >> ptr[counter][3] >> ptr[counter][4];
        counter++;
    }

    double x = 0.0, y = 0.0;
    int dot = 1;
    while (cin >> x >> y && (x != 9999.9 && y != 9999.9))
    {
        bool have = true;
        for (int i = 0; i <= endPtr; i++)
        {
            if ( (x > ptr[i][1] && x < ptr[i][3] && (y > ptr[i][4] && y < ptr[i][2])))
            {
                cout << "Point " << dot << " is contained in figure " << i << endl;
                have = false;
            }
        }

        if ( have )
            cout << "Point " << dot << " is not contained in any figure" << endl;

        dot++;
    }


    return 0;
}