当前位置:网站首页>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;
}
边栏推荐
- 使用npm发布自己开发的工具包笔记
- Multi function event recorder of the 5th National Games of the Blue Bridge Cup
- Formatting occurs twice when vs code is saved
- Pangolin Library: subgraph
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022 edition illustrated network pdf
- Selenium waiting mode
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- Grabbing and sorting out external articles -- status bar [4]
- Prepare for the autumn face-to-face test questions
猜你喜欢
Unity learning notes -- 2D one-way platform production method
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
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
Redis list
SQL statement
Audio and video engineer YUV and RGB detailed explanation
【机器人库】 awesome-robotics-libraries
Jisuanke - t2063_ Missile interception
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
随机推荐
ftp上传文件时出现 550 Permission denied,不是用户权限问题
Adapter-a technology of adaptive pre training continuous learning
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
Redis string type
Paper notes: limit multi label learning galaxc (temporarily stored, not finished)
Structural theme model (I) STM package workflow
Redis daemon cannot stop the solution
Know MySQL database
Online reservation system of sports venues based on PHP
Jisuanke - t2063_ Missile interception
Use the list component to realize the drop-down list and address list
500 lines of code to understand the principle of mecached cache client driver
Text editing VIM operation, file upload
好用的 JS 脚本
SQL statement
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
HDU_p1237_简单计算器_stack
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
genius-storage使用文档,一个浏览器缓存工具