当前位置:网站首页>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;
}
边栏推荐
- Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
- LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
- Selenium element positioning (2)
- 500 lines of code to understand the principle of mecached cache client driver
- 零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
- Use Scrollview and tabhost to realize vertical scrollbars and tabs
- Paper notes: graph neural network gat
- Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
- UE4 - how to make a simple TPS role (I) - create a basic role
- 机器学习训练与参数优化的一般过程 (讨论)
猜你喜欢
【无标题】数据库中一条查询SQL执行的过程
Paper notes: graph neural network gat
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
Computer graduation design PHP animation information website
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
Derivation of Biot Savart law in College Physics
2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Structural theme model (I) STM package workflow
随机推荐
leetcode3、實現 strStr()
How to generate rich text online
PAT甲级 1033 To Fill or Not to Fill
RDD conversion operator of spark
UE4 - how to make a simple TPS role (I) - create a basic role
一位博士在华为的22年
SPI communication protocol
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
500 lines of code to understand the principle of mecached cache client driver
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
[robot hand eye calibration] eye in hand
VIM usage guide
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
MySQL index
sql表名作为参数传递
Compact lidar global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
抓包整理外篇——————状态栏[ 四]
有没有sqlcdc监控多张表 再关联后 sink到另外一张表的案例啊?全部在 mysql中操作
Overview of spark RDD