当前位置:网站首页>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;
}边栏推荐
- Use Scrollview and tabhost to realize vertical scrollbars and tabs
- There are so many giants, why should we independently develop POS store cashier system?
- Computer graduation design PHP college classroom application management system
- Computer graduation design PHP animation information website
- 0211 embedded C language learning
- RDD conversion operator of spark
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- Xshell 7 Student Edition
- Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
- Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
猜你喜欢

Using SA token to solve websocket handshake authentication

Audio and video engineer YUV and RGB detailed explanation
![[solution] add multiple directories in different parts of the same word document](/img/22/32e43493ed3b0b42e35ceb9ab5b597.jpg)
[solution] add multiple directories in different parts of the same word document

从顶会论文看2022年推荐系统序列建模的趋势

RDD conversion operator of spark

Extracting key information from TrueType font files

Online reservation system of sports venues based on PHP

Use image components to slide through photo albums and mobile phone photo album pages

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

Know MySQL database
随机推荐
Use image components to slide through photo albums and mobile phone photo album pages
模板_快速排序_双指针
[eight part essay] what is the difference between unrepeatable reading and unreal reading?
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
01. Go language introduction
PHP campus financial management system for computer graduation design
Install redis
Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
Social networking website for college students based on computer graduation design PHP
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
Competition question 2022-6-26
Grabbing and sorting out external articles -- status bar [4]
General process of machine learning training and parameter optimization (discussion)
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
Shutter doctor: Xcode installation is incomplete
【coppeliasim】高效传送带
Computer graduation design PHP campus restaurant online ordering system
更换gcc版本后,编译出现make[1]: cc: Command not found
https://github.com/ZouJiu1/PAT