update
This commit is contained in:
parent
bf213d134c
commit
04c2bd2ff2
2
.gitignore
vendored
2
.gitignore
vendored
@ -34,6 +34,6 @@
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
# *.out
|
||||
*.app
|
||||
|
||||
|
41
src/12/c6/Restaurant_Reviews.cpp
Normal file
41
src/12/c6/Restaurant_Reviews.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
|
||||
有一家餐厅,并且有1~5档整数评分,给出每档评分人数,求出到指定评分需要刷多少好评。好评指(5或者4星)
|
||||
|
||||
好评指的是4星或5星的评分。为了最小化需要添加的评分数量,我们应该优先添加5星评分,因为它对提高平均评分的贡献最大。
|
||||
|
||||
解决思路
|
||||
计算当前总分和总人数:
|
||||
总分 S = C1*1 + C2*2 + C3*3 + C4*4 + C5*5
|
||||
总人数 T = C1 + C2 + C3 + C4 + C5
|
||||
判断当前平均评分是否已经达到目标K:
|
||||
如果 S / T >= K,则不需要添加任何评分,输出 0。
|
||||
处理特殊情况当目标K为5:
|
||||
只有当所有评分都是5星时,才能达到平均评分5。
|
||||
如果当前总分 S == 5*T,则输出 0。
|
||||
否则,不可能达到平均评分5,输出 -1。
|
||||
|
||||
(S+5N)/(T+N)>=K
|
||||
N>=(K*T-S)/(5-K)
|
||||
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
using ll = int64_t;
|
||||
|
||||
int main(){
|
||||
ll c[6];
|
||||
double s=0.0;
|
||||
ll t=0;
|
||||
for(ll i=1;i<=5;i++){
|
||||
std::cin>>c[i];
|
||||
t+=c[i];
|
||||
s+=double(i)*double(c[i]);
|
||||
}
|
||||
double k;
|
||||
std::cin>>k;
|
||||
std::cout<<std::ceil((k*double(t)-s)/(5.0-k)-1e-9)<<'\n';
|
||||
}
|
0
src/12/c6/Restaurant_Reviews.md
Normal file
0
src/12/c6/Restaurant_Reviews.md
Normal file
2
src/12/c6/homework.txt
Normal file
2
src/12/c6/homework.txt
Normal file
@ -0,0 +1,2 @@
|
||||
BST
|
||||
USACO
|
2
src/12/c6/r.in
Normal file
2
src/12/c6/r.in
Normal file
@ -0,0 +1,2 @@
|
||||
10 20 30 25 15
|
||||
4.0
|
1
src/12/c6/r.out
Normal file
1
src/12/c6/r.out
Normal file
@ -0,0 +1 @@
|
||||
85
|
Loading…
Reference in New Issue
Block a user