当前位置:网站首页>PAT甲级 1033 To Fill or Not to Fill
PAT甲级 1033 To Fill or Not to Fill
2022-07-06 02:11:00 【九是否非随机的称呼】
属于较难的题目,贪心方式要次次遍历,找后续oil station里价格最低的存在,若是不存在相对目前更低的,就是直接加满;若是存在相对更低的,去更低的地方
加满以后可能找到价格更低的地方,要减去oil bank剩的oil用距离表示即可
保证oil tank里的oil价格是最低的
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
typedef struct _gas{
float price;
float dis;
int items;
}gas;
bool compare(const gas &c, const gas &b){
if(c.dis < b.dis) return true;
else return false;
}
int main(int argc, char **argv){
int m, n, i, j, h, w, e, r, t;
float mon, z, x, y;
cin>>x>>y>>z>>m;
vector<gas> v;
gas gs;
for(i = 0; i < m; i++){
cin>>gs.price>>gs.dis;
v.push_back(gs);
}
sort(v.begin(), v.end(), compare);
v.erase(v.begin() + i, v.end());
gs.price = 0;
gs.dis = y;
v.push_back(gs);
for(i = 0; i < v.size(); i++){
v[i].items = i;
}
vector<float> rem, k;
rem.push_back(0);
mon = 0;
k.push_back(0);
if(v[0].dis > 0) {
printf("The maximum travel distance = 0.00");
return 0;
}
i = 0;
float minmin, allprice = 0, lefdis = 0;
gs = v[0];
while(gs.dis < y){
float maxdis = gs.dis + x * z, flags=0;
if(maxdis < v[gs.items + 1].dis){
printf("The maximum travel distance = %.2f", maxdis);
return 0;
}
gas mingss = {999999, 0.0, -1};
for(i = gs.items + 1; i <= m && v[i].dis <= maxdis; i++){
if(v[i].dis <= gs.dis) continue;
if(v[i].price < gs.price){
allprice += (float)((v[i].dis - gs.dis - lefdis)/(float)z) * gs.price;
gs = v[i];
lefdis = 0.0;
flags = 1;
break;
}
if(v[i].price < mingss.price){
mingss = v[i];
}
}
if(flags==0){
allprice += (float)(x - lefdis/z) * gs.price;
lefdis = maxdis - mingss.dis;
gs = mingss;
}
}
printf("%.2f", allprice);
return EXIT_SUCCESS;
}边栏推荐
- VIM usage guide
- sql表名作为参数传递
- Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
- Use Scrollview and tabhost to realize vertical scrollbars and tabs
- 通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
- Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
- How to set an alias inside a bash shell script so that is it visible from the outside?
- 【机器人手眼标定】eye in hand
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Social networking website for college students based on computer graduation design PHP
猜你喜欢

PHP campus movie website system for computer graduation design

Formatting occurs twice when vs code is saved
![[robot library] awesome robots Libraries](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[robot library] awesome robots Libraries

Redis如何实现多可用区?

leetcode3、实现 strStr()

Concept of storage engine

Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Jisuanke - t2063_ Missile interception

2022年PMP项目管理考试敏捷知识点(8)
随机推荐
竞价推广流程
Concept of storage engine
Dynamics 365 开发协作最佳实践思考
729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
[solution] every time idea starts, it will build project
SQL statement
机器学习训练与参数优化的一般过程 (讨论)
Accelerating spark data access with alluxio in kubernetes
阿裏測開面試題
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Extracting key information from TrueType font files
Redis daemon cannot stop the solution
Virtual machine network, networking settings, interconnection with host computer, network configuration
leetcode-2.回文判断
SPI communication protocol
PHP campus movie website system for computer graduation design
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
[depth first search] Ji Suan Ke: Betsy's trip
Ali test open-ended questions
好用的 JS 脚本
https://github.com/ZouJiu1/PAT