锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
銆愰瑙c戯細(xì)
浠ヤ笅涓簑atashi鐨勯瑙o細(xì)
寰堢粡鍏哥殑鎺掑簭鍔犺椽蹇冩ā鍨嬨傞鍏堟寜b鎺掑簭錛岀劧鍚庢壂鎻忔瘡涓+鍏碉紝姣忔閫夊彇灝介噺灝忕殑婊¤凍a<w<b鐨勬鍣ㄨ澶囪澹叺銆?br />
鍒氬紑濮嬪繕璁板啓浜屽垎錛岀洿鎺(n*m)鐨勫鏉傚害榪囦簡錛?00MS錛屽悗闈㈡兂璧鋒潵鍙互鐢ㄤ簩鍒嗗姞閫燂紝澶嶆潅搴︿負(fù)O(nlogm)錛?0MS銆?br /> 絎竴嬈$敤multiset錛屾劅瑙変笉閿欙紝寰堟柟渚褲?br />
銆愪唬鐮併戯細(xì)
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 #include "set"
13 using namespace std;
14 #define pb push_back
15 #define mp make_pair
16 #define fi first
17 #define se second
18 #define sof(x) sizeof(x)
19 #define lc(x) (x << 1)
20 #define rc(x) (x << 1 | 1)
21 #define lowbit(x) (x & (-x))
22 #define ll long long
23 #define MAX 40010
24 #define maxn 3000
25 typedef pair<int, int> pii;
26 int n, m;
27 pii p[maxn];
28 bool cmp(const pii &a, const pii &b) {
29 return a.se < b.se;
30 }
31
32 int main() {
33 multiset<int> s;
34 multiset<int>::iterator it;
35 while(cin >> n >> m) {
36 s.clear();
37 for(int i = 0; i < n; i++) cin >> p[i].fi >> p[i].se;
38 for(int i = 0, a; i < m; i++) {
39 cin >> a;
40 s.insert(a);
41 }
42 sort(p, p + n, cmp);
43 int ans = 0;
44 for(int i = 0; i < n; i++) {
45 it = s.lower_bound(p[i].fi);
46 if(it != s.end() && *it <= p[i].se) {
47 ans++;
48 s.erase(it);
49 }
50 }
51 cout << ans << endl;
52 }
53 return 0;
54 }
55
銆愰瑙c戯細(xì)榪欓姝hВ搴旇鏄敤綰挎ц鍒掑仛鐨勶紝鍙儨鎴戜笉鎳傘?br /> 鐢ㄦ帓搴忓姞璐績鍔犲皬浼樺寲鍘嬬潃鏃墮棿榪囦簡銆?br /> 棣栧厛瑕佽椽蹇冨緱鍑轟竴涓粨璁猴紝灝辨槸姣忎漢閮借窇浜哾綾充箣鍚庯紝鍓╀笅鐨勮礬紼嬩竴瀹氭槸鐢變竴涓漢鎴栬呮渶澶氫袱涓漢璺戝畬銆?br />
浠ヤ笅緇欏嚭璇佹槑錛?br /> 鍋囪鏈変笁涓互涓婄殑浜鴻窇鍓╀笅鐨勮窛紱伙紝浠誨彇鍏朵腑涓変釜浜篴,b,c錛屼笖sa>sb>sc.
鏄劇劧鎴戜滑鍙互寰楀嚭涓緇剎,y鏄叧浜庢柟紼?sb = x * sa + y * sc鐨勮В涓攛 + y = 1.
鐒跺悗鏈変袱縐嶆儏鍐碉細(xì)
鑻?tb < x * ta + y * tc . 鏄劇劧鎴戜滑鎶?a 鍜?c鎵璺戠殑璺▼灝藉彲鑳芥寜姣斾緥鎹㈡垚b璺戯紝榪欐牱鏈鍧忔儏鍐典笅鐨勬椂闂翠笉浼?xì)鍙樺Q屼絾鏈濂芥儏鍐典笅鐨勬椂闂村噺灝戜簡銆?br /> 鍚岀悊,鑻?tb >= x * ta + y * tc. 鎴戜滑灝卞彲浠ユ妸b璺戠殑璺▼灝藉彲鑳芥崲鎴恆鍜宑璺戯紝榪欐牱鏈濂芥儏鍐典笅鐨勬椂闂翠篃鏄噺灝戠殑銆?br /> 鐢辨鍙緱錛屾渶鍚庝竴瀹氭渶澶氬彧鏈変袱涓漢鍦ㄨ窇鍓╀笅鐨勮窛紱匯?br /> 鐒跺悗鐩存帴鏋氫婦浠繪剰涓や釜浜哄氨鍙互綆楀嚭絳旀銆?br /> 鎴戝姞浜嗙偣灝忎紭鍖栧氨鏄綋si<sj涓攖i<tj鏃訛紝j榪欎釜浜烘樉鐒舵槸澶氫綑鐨勶紝鍙互鐩存帴蹇界暐涓嶈銆?br />
銆愪唬鐮併戯細(xì)
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 }