国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

1033.To Fill or Not to Fill (25)

2019-11-11 07:22:30
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1033.To Fill or Not to Fill (25)

pat-al-1033

2017-02-05

貪心在起始處沒(méi)有加油站所以一步也走不了的情況特殊處理一下分三種情況,一是油箱加滿也到不了下一個(gè)加油站(直接PRint能到的最遠(yuǎn)處然后return 0)、二是能走到的距離內(nèi)有比當(dāng)前站油價(jià)低的(就加夠可以行駛到那一站的油就可以了)、三是能走到的距離內(nèi)有加油站但沒(méi)有比當(dāng)前油價(jià)低的(那就加滿油,行駛到油價(jià)最低的站點(diǎn))注意:油箱內(nèi)剩余油量的更新/** * pat-al-1033 * 2017-02-05 * Cpp version * Author: fengLian_s */#include<stdio.h>#include<vector>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;struct STA{ double price; double dist;};bool cmp(STA a, STA b){ return a.dist < b.dist;}int main(){ freopen("in.txt", "r", stdin); int maxC, maxDist, avgDis, n; scanf("%d%d%d%d", &maxC, &maxDist, &avgDis, &n); vector<STA> sta(n+1); sta[0].price = 0; sta[0].dist = maxDist; for(int i = 1;i <= n;i++) { scanf("%lf%lf", &sta[i].price, &sta[i].dist); } sort(sta.begin(), sta.end(), cmp); double tmpDist = 0, maxCanReach = 0, tmpPrice = 0, totalPrice = 0, tmpC = 0;//tmpC是目前油箱里的油量 if(sta[0].dist != 0) { printf("The maximum travel distance = 0.00/n"); return 0; } else tmpPrice = sta[0].price; while(tmpDist < maxDist) { maxCanReach = tmpDist + maxC * avgDis; double minPrice = INF, minPriceDist; int flagFind = 0; for(int i = 1;i <= n && sta[i].dist <= maxCanReach;i++) { if(sta[i].dist <= tmpDist) continue; if(sta[i].price < tmpPrice) { //printf("sta.price = %.2lf, tmpPrice = %.2lf/n", sta[i].price, tmpPrice); totalPrice += ((sta[i].dist - tmpDist) / avgDis - tmpC) * tmpPrice; //printf("falgFind, totalPrice = %.2lf, tmpDist = %d/n", totalPrice, (int)tmpDist); tmpC = 0; tmpPrice = sta[i].price; tmpDist = sta[i].dist; flagFind = 1; break; } if(sta[i].price < minPrice) { minPrice = sta[i].price; minPriceDist = sta[i].dist; //printf("minPriceDist = %d, minPrice = %.2lf/n", (int)minPriceDist, minPrice); } } if(flagFind == 0 && minPrice == INF) { printf("The maximum travel distance = %.2lf/n", maxCanReach); return 0; } if(flagFind == 0 && minPrice != INF) { totalPrice += (maxC - tmpC) * tmpPrice; tmpC = maxC - (minPriceDist - tmpDist) / avgDis; //printf("totalPrice = %.2lf, tmpDist = %d/n", totalPrice, (int)tmpDist); tmpPrice = minPrice; tmpDist = minPriceDist; //printf("minPriceDist = %d, minPrice = %.2lf/n", (int)minPriceDist, minPrice); } } printf("%.2lf/n", totalPrice); return 0;}

-FIN-


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 博湖县| 三台县| 武功县| 乡宁县| 聂拉木县| 招远市| 宁河县| 龙门县| 温州市| 赤水市| 游戏| 贵溪市| 双牌县| 虞城县| 巩义市| 青田县| 惠安县| 静乐县| 青浦区| 孙吴县| 肥乡县| 庆元县| 兴业县| 巍山| 师宗县| 交城县| 五峰| 东山县| 即墨市| 深水埗区| 绩溪县| 建昌县| 津市市| 曲水县| 夹江县| 增城市| 台中市| 西青区| 新河县| 新河县| 靖州|