PAT 甲级 1011 World Cup Betting 模拟
地址 https://pintia.cn/problem-sets/994805342720868352/problems/994805504927186944
题目大意是给出三场比赛的胜负比 要求我们得出搭配回报最大的选择方法和最后回报的数目(投注额为2元) 例如,以下是三场比赛的赔率: W T L 1.1 2.5 1.7 1.2 3.1 1.6 4.1 1.2 1.1 第一场选取 T 2.5 第二场选取 T 3.1 第二场选取 W 4.1 那么在投注2元的情况下 最大利润是 (2.5x3.1x4.1x65%−1)x2=39.31元 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
算法1
模拟 每次比较三个输入的胜率比 得到最大的比例数和它属于的类别 WTL
然后输出结果
#include <iostream> using namespace std; double arr[3][3]; char mapp[3] = {'W','T','L'}; int main() { double greatest[3]; char ans[3]; for(int i = 0; i < 3;i++){ greatest[i] = -1.0; for(int j = 0; j < 3;j++){ cin >> arr[i][j]; if(arr[i][j] - greatest[i] > 1e-8){ greatest[i] = arr[i][j]; ans[i] = mapp[j]; } } } for(int i = 0; i < 3;i++){ cout << ans[i] << " "; } printf("%.2lf\n", (greatest[0]*greatest[1]*greatest[2]*0.65 -1)*2) ; return 0; }
作 者: itdef
欢迎转帖 请保持文本完整并注明出处
技术博客 http://www.cnblogs.com/itdef/
B站算法视频题解
https://space.bilibili.com/18508846
qq 151435887
gitee https://gitee.com/def/
欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
如果觉得不错,欢迎点赞,你的鼓励就是我的动力
欢迎转帖 请保持文本完整并注明出处
技术博客 http://www.cnblogs.com/itdef/
B站算法视频题解
https://space.bilibili.com/18508846
qq 151435887
gitee https://gitee.com/def/
欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
如果觉得不错,欢迎点赞,你的鼓励就是我的动力