当前位置:网站首页>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;
}边栏推荐
- [width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
- PHP campus financial management system for computer graduation design
- Use the list component to realize the drop-down list and address list
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- genius-storage使用文档,一个浏览器缓存工具
- 更改对象属性的方法
- 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
- Ali test open-ended questions
- Spark accumulator
- Ali test Open face test
猜你喜欢

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

selenium 等待方式

Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022

Audio and video engineer YUV and RGB detailed explanation

数据工程系列精讲(第四讲): Data-centric AI 之样本工程

leetcode3、实现 strStr()

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

Kubernetes stateless application expansion and contraction capacity

Adapter-a technology of adaptive pre training continuous learning
随机推荐
A basic lintcode MySQL database problem
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
sql表名作为参数传递
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
Executing two identical SQL statements in the same sqlsession will result in different total numbers
RDD creation method of spark
Computer graduation design PHP campus restaurant online ordering system
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
Thinking about the best practice of dynamics 365 development collaboration
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
This time, thoroughly understand the deep copy
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?
Spark accumulator
SPI communication protocol
[robot library] awesome robots Libraries
Virtual machine network, networking settings, interconnection with host computer, network configuration
使用npm发布自己开发的工具包笔记
Lecture 4 of Data Engineering Series: sample engineering of data centric AI
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
https://github.com/ZouJiu1/PAT