1 solutions
-
0
C++ :
#include<iostream> #include<cstdio> using namespace std; struct Region { double s, e; }r1[101], r2[101]; double min(double a, double b) { return a < b ? a : b; } double max(double a, double b) { return a > b ? a : b; } double cal(Region a, Region b) { // a是靠前的区间 double dif; char first; if (a.e < b.e) dif = a.e - max(a.s, b.s), first = 'a'; else dif = b.e - max(a.s, b.s), first = 'b'; if (dif > 0) { if (first == 'a') a.s = a.e, b.s = b.e; else a.s = b.e, b.s = b.e; return dif; } else return 0; } int main() { int n1, n2; while (cin >> n1) { for (int i = 0; i < n1; i++) cin >> r1[i].s >> r1[i].e; cin >> n2; for (int i = 0; i < n2; i++) cin >> r2[i].s >> r2[i].e; double ans = 0; for (int i = 0; i < n1; i++) for (int j = 0; j < n2; j++) { if (r1[i].s < r2[j].s) ans += cal(r1[i], r2[j]); else ans += cal(r2[j], r1[i]); } printf("%.3lf\n", ans); } return 0; }
- 1
Information
- ID
- 17856
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By