当前位置:网站首页>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;
}边栏推荐
- 【coppeliasim】6自由度路径规划
- Computer graduation design PHP college student human resources job recruitment network
- General process of machine learning training and parameter optimization (discussion)
- Redis如何实现多可用区?
- Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
- Know MySQL database
- Overview of spark RDD
- 【clickhouse】ClickHouse Practice in EOI
- Global and Chinese market of commercial cheese crushers 2022-2028: Research Report on technology, participants, trends, market size and share
- Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
猜你喜欢

How does redis implement multiple zones?

Easy to use js script

2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
![[robot library] awesome robots Libraries](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[robot library] awesome robots Libraries

使用npm发布自己开发的工具包笔记

02. Go language development environment configuration

Black high-end responsive website dream weaving template (adaptive mobile terminal)

Redis list

Initial understanding of pointer variables

Jisuanke - t2063_ Missile interception
随机推荐
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
500 lines of code to understand the principle of mecached cache client driver
HDU_p1237_简单计算器_stack
UE4 - how to make a simple TPS role (I) - create a basic role
Bidding promotion process
VIM usage guide
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
【机器人手眼标定】eye in hand
Use the list component to realize the drop-down list and address list
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
PAT甲级 1033 To Fill or Not to Fill
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
Initial understanding of pointer variables
好用的 JS 脚本
Audio and video engineer YUV and RGB detailed explanation
Compact lidar global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
机器学习训练与参数优化的一般过程 (讨论)
Unity learning notes -- 2D one-way platform production method
The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
Install redis
https://github.com/ZouJiu1/PAT