区间贪心算法,后一个区间的起点较前一区间偏移多少,区间终点也会偏移多少,所以不用考虑油箱容积的变化。另外浮点数需使用double,float不能通过测试。 #include <iostream> #include <algorithm> using namespace std; struct station { double price; int distance; }; bool compare(station a, station b) { return a.price <= b.price; } int main() { int cmax, d, davg,...