当前位置:网站首页>Pat grade a 1033 to fill or not to fill
Pat grade a 1033 to fill or not to fill
2022-07-06 02:20:00 【IX. is it a non random title】
It belongs to a more difficult topic , Greedy way to traverse again , Find follow-up oil station There is the lowest price in , If there is no lower , Is to fill it up directly ; If there is a relatively lower , Go to a lower place
After filling up, you may find a place with a lower price , To subtract oil bank The rest oil It can be expressed by distance
Guarantee oil tank Inside oil The price is the lowest
#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;
}
边栏推荐
- Adapter-a technology of adaptive pre training continuous learning
- Bigder:34/100 面试感觉挺好的,没有收到录取
- Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
- 【coppeliasim】6自由度路径规划
- 2022 edition illustrated network pdf
- [coppeliasim] efficient conveyor belt
- Gbase 8C database upgrade error
- Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
- leetcode3、實現 strStr()
- Genius storage uses documents, a browser caching tool
猜你喜欢
零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
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
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
Using SA token to solve websocket handshake authentication
Computer graduation design PHP campus restaurant online ordering system
Pangolin Library: subgraph
How to improve the level of pinduoduo store? Dianyingtong came to tell you
UE4 - how to make a simple TPS role (I) - create a basic role
Use the list component to realize the drop-down list and address list
Derivation of Biot Savart law in College Physics
随机推荐
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
Paper notes: graph neural network gat
RDD conversion operator of spark
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
vs code保存时 出现两次格式化
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Number conclusion LC skimming review - 1
Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
Competition question 2022-6-26
Selenium element positioning (2)
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
FTP server, ssh server (super brief)
[robot library] awesome robots Libraries
General process of machine learning training and parameter optimization (discussion)
Derivation of Biot Savart law in College Physics
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
[depth first search notes] Abstract DFS
ftp上传文件时出现 550 Permission denied,不是用户权限问题
【clickhouse】ClickHouse Practice in EOI