当前位置:网站首页>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;
}
边栏推荐
- Redis list
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
- 0211 embedded C language learning
- Bidding promotion process
- 02.Go语言开发环境配置
- Leetcode sum of two numbers
- Leetcode3. Implement strstr()
- 同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
- Overview of spark RDD
- 01.Go语言介绍
猜你喜欢
[solution] add multiple directories in different parts of the same word document
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
Computer graduation design PHP college student human resources job recruitment network
Computer graduation design PHP college classroom application management system
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
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
0211 embedded C language learning
2022年PMP项目管理考试敏捷知识点(8)
NumPy 数组索引 切片
[depth first search] Ji Suan Ke: Betsy's trip
随机推荐
Use the list component to realize the drop-down list and address list
PHP campus financial management system for computer graduation design
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
[coppeliasim] 6-DOF path planning
leetcode-2.回文判断
729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
RDD partition rules of spark
729. My schedule I / offer II 106 Bipartite graph
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
[coppeliasim] efficient conveyor belt
General process of machine learning training and parameter optimization (discussion)
Use image components to slide through photo albums and mobile phone photo album pages
机器学习训练与参数优化的一般过程 (讨论)
Redis daemon cannot stop the solution
[solution] every time idea starts, it will build project
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
Selenium element positioning (2)
Numpy array index slice
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
竞价推广流程