标签:整数 struct map 难度 type bool fst tab str
2 2 8 6 1 1 4 5 2 10 6 4 5 6 5
1 2
#include<iostream> #include<cstdio> #include<cstring> #include<sstream> #include<algorithm> #include<queue> #include<vector> #include<cmath> #include<map> #include<stack> #include<set> #include<fstream> #include<memory> #include<list> #include<string> using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MAXN 10003 #define INF 1000000009 /* 喷水装置2 在给定装置(位置X确定)中选尽量少的 可以得出贡献长方形的长度,转化为线段 在一堆线段中选择尽量少的覆盖所有: 按起点排序,遍历一遍即可 */ int T; double n, w, h, E, r[MAXN], x[MAXN]; struct node { double beg, end; }; vector<node> v; bool cmp(node a, node b) { return a.beg < b.beg; } int main() { int T; scanf("%d", &T); while (T--) { cin >> n >> w >> h; node tmp; v.clear(); E = 0.0; for (int i = 0; i < n; i++) { cin >> x[i] >> r[i]; if (r[i] * r[i] - (h / 2)*(h / 2) > 0) { tmp.beg = x[i] - sqrt(r[i] * r[i] - (h / 2)*(h / 2)); //tmp.beg = max(0.0, tmp.beg); tmp.end = x[i] + sqrt(r[i] * r[i] - (h / 2)*(h / 2)); //tmp.end = min(w, tmp.end); v.push_back(tmp); } } sort(v.begin(), v.end(),cmp); int i = 0,cnt = 0; while(E<w) { double m = 0.0; for (i = 0; i < v.size() && v[i].beg <= E; i++) { m = max(m, v[i].end - E); } if (m!=0) { cnt++; E += m; } else break; } if (E < w) cout << 0 << endl; else cout << cnt << endl; } }
标签:整数 struct map 难度 type bool fst tab str
原文地址:http://www.cnblogs.com/joeylee97/p/6815682.html