PAT甲级1033
差兩分拿不到。。。抓狂!
#include<iostream> #include<algorithm> using namespace std;struct NODE{double p, dis; }node[505];bool cmp(NODE a, NODE b){return a.dis < b.dis; }int main(){int N;double Cmax, D, Davg, k, m, Dmax;cin >> Cmax >> D >> Davg >> N;Dmax = Cmax * Davg;for (int i = 0; i < N; i++){cin >> k >> m;node[i] = {k, m};}sort(node, node + N, cmp);node[N] = {0, D};double temp = 0, tank = 0, nowd = 0, nowp = node[0].p, res = 0, fill = 0;for (int i = 1; i <= N; i++){if (node[i].dis - nowd > Dmax){nowd += Dmax;printf("The maximum travel distance = %.2f", nowd);return 0;}else if (node[i].p <= nowp && node[i].dis - nowd <= Dmax){temp = node[i].dis - nowd;fill = temp/Davg - tank;if (fill < 0) fill = 0;tank += fill;res += fill * nowp;nowd += temp;nowp = node[i].p;tank = tank - temp/Davg;}else if (node[i].p > nowp && node[i + 1].dis - nowd > Dmax){fill = Cmax - tank;if (fill < 0) fill = 0;tank += fill;res += fill * nowp;temp = node[i].dis - nowd;nowd += temp;nowp = node[i].p;tank = tank - temp/Davg;}}printf("%.2f", res); }總結
- 上一篇: 执行python generate_tf
- 下一篇: SSL通信和域前置