当前位置:网站首页>Li Kou ----- the maximum profit of operating Ferris wheel
Li Kou ----- the maximum profit of operating Ferris wheel
2022-07-05 21:22:00 【qq_ thirty-seven million seven hundred and sixty thousand seven】
int minOperationsMaxProfit(int* customers, int customersSize, int boardingCost, int runningCost){
int Record=0;
int top=0;
int stack[1000000];
int count=0;
int max=-10000;
int index;
for(int a=0;a<customersSize;a++){
Record=Record+customers[a];
if(Record>4){
count=count+4*boardingCost-runningCost;
stack[top++]=count;
Record=Record-4;
}
else{
count=count+customers[a]*boardingCost-runningCost;
stack[top++]=count;
Record=0;
}
if(stack[top-1]>max){
max=stack[top-1];
index=top-1;
}
}
if(Record>0){
while(1){
if(Record>4){
count=count+4*boardingCost-runningCost;
stack[top++]=count;
Record=Record-4;
}
else{
count=count+Record*boardingCost-runningCost;
stack[top++]=count;
if(stack[top-1]>max){
max=stack[top-1];
index=top-1;
}
break;
}
if(stack[top-1]>max){
max=stack[top-1];
index=top-1;
}
}
}
if(max<=0){
return -1;
}
return index+1;
}
边栏推荐
- Opérations de lecture et d'écriture pour easyexcel
- [case] Application of element display and hiding -- element mask
- Generics of TS
- Deployment of Jenkins under win7
- 第05章_存储引擎
- Traps in the explode function in PHP
- Influence of oscilloscope probe on signal source impedance
- EasyExcel的讀寫操作
- Uni app Bluetooth communication
- What should I do to prepare for the interview algorithm position during school recruitment?
猜你喜欢
Introduction of ArcGIS grid resampling method
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
Five layer network protocol
Wood board ISO 5660-1 heat release rate mapping test
校招期间 准备面试算法岗位 该怎么做?
示波器探头对信号源阻抗的影响
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application
五层网络协议
Influence of oscilloscope probe on signal source impedance
随机推荐
使用WebAssembly在浏览器端操作Excel
Simple getting started example of Web Service
Sequence alignment
[daily training] 729 My schedule I
PHP deserialization +md5 collision
2022-07-03-cka- latest feedback from fans
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
事项研发工作流全面优化|Erda 2.2 版本如“七”而至
100 cases of shell programming
Prior knowledge of machine learning in probability theory (Part 1)
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
示波器探头对测量带宽的影响
Longest swing sequence [greedy practice]
示波器探头对信号源阻抗的影响
校招期间 准备面试算法岗位 该怎么做?
shell编程100例
Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
Display DIN 4102-1 Class B1 fire test requirements
SQL series (basic) - Chapter 2 limiting and sorting data