銆愰瑙c戯細榪欓姝hВ搴旇鏄敤綰挎ц鍒掑仛鐨勶紝鍙儨鎴戜笉鎳傘?br /> 鐢ㄦ帓搴忓姞璐績鍔犲皬浼樺寲鍘嬬潃鏃墮棿榪囦簡銆?br /> 棣栧厛瑕佽椽蹇冨緱鍑轟竴涓粨璁猴紝灝辨槸姣忎漢閮借窇浜哾綾充箣鍚庯紝鍓╀笅鐨勮礬紼嬩竴瀹氭槸鐢變竴涓漢鎴栬呮渶澶氫袱涓漢璺戝畬銆?br />
浠ヤ笅緇欏嚭璇佹槑錛?br /> 鍋囪鏈変笁涓互涓婄殑浜鴻窇鍓╀笅鐨勮窛紱伙紝浠誨彇鍏朵腑涓変釜浜篴,b,c錛屼笖sa>sb>sc.
鏄劇劧鎴戜滑鍙互寰楀嚭涓緇剎,y鏄叧浜庢柟紼?sb = x * sa + y * sc鐨勮В涓攛 + y = 1.
鐒跺悗鏈変袱縐嶆儏鍐碉細
鑻?tb < x * ta + y * tc . 鏄劇劧鎴戜滑鎶?a 鍜?c鎵璺戠殑璺▼灝藉彲鑳芥寜姣斾緥鎹㈡垚b璺戯紝榪欐牱鏈鍧忔儏鍐典笅鐨勬椂闂翠笉浼氬彉錛屼絾鏈濂芥儏鍐典笅鐨勬椂闂村噺灝戜簡銆?br /> 鍚岀悊,鑻?tb >= x * ta + y * tc. 鎴戜滑灝卞彲浠ユ妸b璺戠殑璺▼灝藉彲鑳芥崲鎴恆鍜宑璺戯紝榪欐牱鏈濂芥儏鍐典笅鐨勬椂闂翠篃鏄噺灝戠殑銆?br /> 鐢辨鍙緱錛屾渶鍚庝竴瀹氭渶澶氬彧鏈変袱涓漢鍦ㄨ窇鍓╀笅鐨勮窛紱匯?br /> 鐒跺悗鐩存帴鏋氫婦浠繪剰涓や釜浜哄氨鍙互綆楀嚭絳旀銆?br /> 鎴戝姞浜嗙偣灝忎紭鍖栧氨鏄綋si<sj涓攖i<tj鏃訛紝j榪欎釜浜烘樉鐒舵槸澶氫綑鐨勶紝鍙互鐩存帴蹇界暐涓嶈銆?br />
銆愪唬鐮併戯細
1 #include "iostream"
2 #include "cstdio"
3 #include "cstring"
4 #include "algorithm"
5 #include "vector"
6 #include "queue"
7 #include "cmath"
8 #include "string"
9 #include "cctype"
10 #include "map"
11 #include "iomanip"
12 using namespace std;
13 #define pb push_back
14 #define lc(x) (x << 1)
15 #define rc(x) (x << 1 | 1)
16 #define lowbit(x) (x & (-x))
17 #define ll long long
18 #define maxn 10050
19 int n;
20 double d, l, w;
21 double ans, good;
22 struct Person {
23 double s, t;
24 bool operator <(const Person &a) const {
25 if(s != a.s) return s < a.s;
26 return t < a.t;
27 }
28 }p[maxn];
29
30 void solve() {
31 sort(p + 1, p + n + 1);
32 int tot = 1;
33 for(int i = 2; i <= n; i++) {
34 if(p[i].t < p[tot].t) p[++tot] = p[i];
35 }
36 double ans = 1e25;
37 for(int i = 1; i <= tot; i++) {
38 if(l * p[i].s > w) break;
39 ans = min(ans, good + l * p[i].t);
40 for(int j = i + 1; j <= tot; j++) {
41 double ww = l * p[j].s;
42 if(ww > w) ww = w;
43 double y = (ww - l * p[i].s) / (p[j].s - p[i].s);
44 ans = min(ans, good + y * p[j].t + (l - y) * p[i].t);
45 }
46 }
47 if(ans > 1e24) printf("No solution\n");
48 else printf("%.2f\n", ans);
49 }
50 int main() {
51 int T;
52 scanf("%d", &T);
53 while(T--) {
54 good = 0.0;
55 scanf("%d%lf%lf%lf", &n, &d, &l, &w);
56 for(int i = 1; i <= n; i++) {
57 scanf("%lf%lf", &p[i].s, &p[i].t);
58 w -= p[i].s * d;
59 good += p[i].t * d;
60 }
61 l -= d * n;
62 if(w < 0 || l < 0) {
63 printf("No solution\n");
64 continue;
65 }
66 solve();
67 }
68 return 0;
69 }

]]>