hud 4438(Hunters)

Problem Description
Alice and Bob are the topmost hunters in the forest, so no preys can escape from them. However, they both think that its hunting skill is better than the other. So they need a match.
In their match, the targets are two animals, a tiger and a wolf. They both know that the tiger is living in the south of the forest and the wolf is living in the north of the forest. They decide that the one who kills the tiger scores X points and who kills the wolf scores Y points. If the one who kills both tiger and wolf scores X+Y points.
Before the match starts, Alice is in the east of the forest and Bob is in the west of the forest. When the match starts, Alice and Bob will choose one of the preys as targets. Because they haven't known the other's choice, maybe they choose the same target. There will be two situations:
(1) If they choose different targets, they both are sure of killing their respective targets.
(2) If they choose the same target, the probability of Alice killing the target is P, and the probability of Bob killing it is 1-P. Then they will hunt for the other prey, also the probability of Alice killing it is P and the probability of Bob killing it is 1-P.
But Alice knows about Bob. She knows that the probability of Bob choosing tiger as his first target is Q, and the probability of choosing wolf is 1-Q. So that Alice can decide her first target to make her expected score as high as possible.
 

 

Input
The first line of input contains an integer T (1≤T≤10000), the number of test cases.
Then T test cases follow. Each test case contains X, Y, P, Q in one line. X and Y are integers and 1≤X, Y≤1000000000. P and Q are decimals and 0≤P, Q≤1, and there are at most two digits after decimal point.
 

 

Output
For each test case, output the target Alice should choose and the highest expected score she can get, in one line, separated by a space. The expected score should be rounded to the fourth digit after decimal point. It is guaranteed that Alice will have different expected score between choosing tiger and wolf.
 

 

Sample Input
3
2 1 0.5 0.5
2 1 0 1
7 7 0.32 0.16
 

 

Sample Output
tiger 1.7500
wolf 1.0000
tiger 6.5968
 

 

Source
 
 
Problem analysis:
This is one of the most easiest problem in the asia regional contest;
There are only two animals,so just figure out the two expected scores of the two cases;
case 1: alice choose the tiger;
case 2: alice choose the wolf:
And the bigger score is the answer.
View Code
#include<iostream>
using namespace std;
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int x,y;
        double p,q;
        cin>>x>>y>>p>>q;
        double score1,score2;
        score1=x*(1-q)+q*(x+y)*p;
        score2=y*q+(1-q)*(x+y)*p;
        if(score1>score2)
            printf("tiger %.4lf\n",score1);
        else
        printf("wolf %.4lf\n",score2);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/heat-man/articles/2752058.html

以下是用C语言实现的代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> // 定义角色结构体 typedef struct { char name[20]; // 姓名 char camp; // 阵营 int proficiency; // 熟练度 int ban; // 是否被 ban } Role; // 比较函数,按照熟练度从高到低排序 int cmp(const void* a, const void* b) { Role* r1 = (Role*)a; Role* r2 = (Role*)b; return r2->proficiency - r1->proficiency; } int main() { int n, m; scanf("%d%d", &n, &m); // 读入角色信息 Role* survivors = (Role*)malloc(n * sizeof(Role)); Role* hunters = (Role*)malloc(m * sizeof(Role)); for (int i = 0; i < n; i++) { scanf("%s %c %d", survivors[i].name, &survivors[i].camp, &survivors[i].proficiency); survivors[i].ban = 0; } for (int i = 0; i < m; i++) { scanf("%s %c %d", hunters[i].name, &hunters[i].camp, &hunters[i].proficiency); hunters[i].ban = 0; } // 对角色按照熟练度从高到低排序 qsort(survivors, n, sizeof(Role), cmp); qsort(hunters, m, sizeof(Role), cmp); // 监管者 ban 掉求生者阵营熟练度最高的 5 个角色,求生者 ban 掉监管者阵营熟练度最高的 2 个角色 for (int i = 0; i < 5; i++) { survivors[i].ban = 1; } for (int i = 0; i < 2; i++) { hunters[i].ban = 1; } // 求生者从未被 ban 的角色中选择 4 个不同的角色 char survivor_picks[4][20]; int pick_count = 0; for (int i = 0; i < n && pick_count < 4; i++) { if (!survivors[i].ban) { strcpy(survivor_picks[pick_count], survivors[i].name); pick_count++; } } // 监管者从未被 ban 的角色中选择 1 个角色 char hunter_pick[20]; for (int i = 0; i < m; i++) { if (!hunters[i].ban) { strcpy(hunter_pick, hunters[i].name); break; } } // 输出结果 printf("Survivors' picks: %s, %s, %s, %s\n", survivor_picks[0], survivor_picks[1], survivor_picks[2], survivor_picks[3]); printf("Hunter's pick: %s\n", hunter_pick); // 释放内存 free(survivors); free(hunters); return 0; } ``` 需要注意的是,在使用字符串时,我们需要使用字符数组而不是指针,因为字符数组可以直接进行数组操作。此外,在使用字符串时,要注意空间分配和拷贝,避免出现内存泄漏或数据损坏的情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值