PTA A1011&A1012

A1011 World Cup Betting (20 分)

題目內容

With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.
Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results -- namely W for win, T for tie, and L for lose. There was an odd assigned to each result. The winner's odd would be the product of the three odds times 65%.
For example, 3 games' odds are given as the following:
W T L
1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1
To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans, then the maximum profit would be (4.1×3.1×2.5×65%−1)×2=39.31 yuans (accurate up to 2 decimal places).

Input Specification:

Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W, T and L.

Output Specification:

For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.

Sample Input:

1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1

Sample Output:

T T W 39.31

單詞

trophy

英 /'trəʊfɪ/ 美 /trofɪ/

n. 獎品;戰利品;紀念品
vt. 用戰利品裝飾
adj. 顯示身份的;有威望的

n. (Trophy)人名;(法)特羅菲

triple

英 /'trɪp(ə)l/ 美 /'trɪpl/

n. 三倍數;三個一組
adj. 三倍的;三方的
vt. 使成三倍

vi. 增至三倍

lottery

英 /'lɒt(ə)rɪ/ 美 /'lɑtəri/

n. 彩票;碰運氣的事,難算計的事;抽彩給獎法

odd

英 /ɒd/ 美 /ɑd/

n. 奇數;怪人;奇特的事物
adj. 奇數的;古怪的;剩餘的;臨時的;零散的

n. (Odd)人名;(英、西、挪、瑞典)奧德

distinct

英 /dɪ'stɪŋ(k)t/ 美 /dɪ'stɪŋkt/
adj. 明顯的;獨特的;清楚的;有區別的

corresponding

英 /,kɒrɪ'spɒndɪŋ/ 美 /,kɔrə'spɑndɪŋ/
adj. 相當的,相應的;一致的;通信的

v. 類似(correspond的ing形式);相配

題目分析

按照題目給的公式套即可。

具體代碼

#include<stdio.h>
#include<stdlib.h>

double a[3];
char b[3] = { 'W','T','L' };
double c[3];

int main(void)
{
    for (int i = 0; i < 3; i++)
    {
        scanf("%lf %lf %lf",&a[0],&a[1],&a[2]);
        double max = 0;
        int temp = 0;
        for (int j = 0; j < 3; j++)
        {
            if (a[j] > max)
            {
                temp = j;
                max = a[j];
            }
        }
        printf("%c ", b[temp]);
        c[i] = max;
    }
    double res = (c[0] * c[1] * c[2] * 0.65 - 1) * 2;
    printf("%.2lf", res);
    system("pause");
}

A1012 The Best Rank (25 分)

題目內容

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C, M, E and A - Average of 4 students are given as the following:
StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output Specification:

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output N/A.

Sample Input:

5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999

Sample Output:

1 C
1 M
1 E
1 A
3 A
N/A

單詞

Linear Algrbra

線性代數

calculus

英 /'kælkjʊləs/ 美 /'kælkjələs/

n. [病理] 結石;微積分學

emphasizing

英 /'emfəsaiziŋ/ 美 /'emfəsaiziŋ/

v. 強調(emphasize的現在分詞)

題目分析

我真是太菜了,插入排序寫了半天,看來這裏要加強。
關於題目其實還好,題目很好懂,就是很麻煩,怎麼做都感覺很麻煩,我寧願做難一點的題,也不想做這種題=-=。

具體代碼

#include<stdio.h>
#include<stdlib.h>

struct student
{
    int id;
    double s[4];
};
char c[4] = { 'A','C','M','E' };
int rank[1000000][4];
int N, M;
struct student *d;

void sort(int n)
{
    for (int i = 1; i < N; i++)
    {
        struct student tmp = d[i];
        int p;
        for (p = i; p > 0 && d[p-1].s[n] < tmp.s[n]; p--)
        {
            d[p] = d[p-1];
        }
        d[p] = tmp;
    }
}

int main(void)
{
    scanf("%d %d", &N, &M);
    d = (struct student *)malloc(N*sizeof(struct student));
    for (int i = 0; i < N; i++)
    {
        scanf("%d %lf %lf %lf", &d[i].id, &d[i].s[1], &d[i].s[2], &d[i].s[3]);
        d[i].s[0] = (d[i].s[1] + d[i].s[2] + d[i].s[3]) / 3.0;
    }
    for (int n = 0; n < 4; n++)
    {
        sort(n);
        for (int i = 0; i < N; i++)
        {
            if (i != 0)
            {
                if (d[i].s[n] == d[i - 1].s[n])
                    rank[d[i].id][n] = i;
                else
                    rank[d[i].id][n] = i + 1;
            }
            else
                rank[d[i].id][n] = i + 1;
        }
    }
    for (int i = 0; i < M; i++)
    {
        int m;
        scanf("%d", &m);
        if (rank[m][0] == 0)
            printf("N/A\n");
        else
        {
            int temp = 0;
            int min = rank[m][0];
            for (int j = 0; j < 4; j++)
            {
                if (rank[m][j] < min)
                {
                    temp = j;
                    min = rank[m][j];
                }
            }
            printf("%d %c\n", min, c[temp]);
        }
    }
    system("pause");
}

參考博客

1012 The Best Rank (25 分)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章