当前位置:网站首页>PAT甲级 1033 To Fill or Not to Fill
PAT甲级 1033 To Fill or Not to Fill
2022-07-06 02:11:00 【九是否非随机的称呼】
属于较难的题目,贪心方式要次次遍历,找后续oil station里价格最低的存在,若是不存在相对目前更低的,就是直接加满;若是存在相对更低的,去更低的地方
加满以后可能找到价格更低的地方,要减去oil bank剩的oil用距离表示即可
保证oil tank里的oil价格是最低的
#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;
}边栏推荐
- SPI communication protocol
- [depth first search notes] Abstract DFS
- Tensorflow customize the whole training process
- This time, thoroughly understand the deep copy
- [network attack and defense training exercises]
- Lecture 4 of Data Engineering Series: sample engineering of data centric AI
- [community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
- Online reservation system of sports venues based on PHP
- 竞价推广流程
- 【clickhouse】ClickHouse Practice in EOI
猜你喜欢

02. Go language development environment configuration

How to upgrade kubernetes in place

Audio and video engineer YUV and RGB detailed explanation

2022 edition illustrated network pdf
![[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

MySQL index

MySQL lethal serial question 1 -- are you familiar with MySQL transactions?

使用npm发布自己开发的工具包笔记
![NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]](/img/11/a01348dbfcae2042ec9f3e40065f3a.png)
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]

Computer graduation design PHP campus restaurant online ordering system
随机推荐
Redis key operation
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
Computer graduation design PHP part-time recruitment management system for College Students
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
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
Executing two identical SQL statements in the same sqlsession will result in different total numbers
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
RDD partition rules of spark
Using SA token to solve websocket handshake authentication
Dynamics 365 开发协作最佳实践思考
Selenium element positioning (2)
Flutter Doctor:Xcode 安装不完整
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
Extracting key information from TrueType font files
RDD creation method of spark
MySQL index
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
在线怎么生成富文本
https://github.com/ZouJiu1/PAT