Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
- #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a,value) memset(a, value, sizeof(a))
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL) INF;
- const int MAX = 111;
- int X[MAX], Y[MAX];
- int DX[MAX], DY[MAX];
- int n, m, p;
- pair<double, int> E[MAX * MAX * MAX];
- double timeTo(double a, double b)
- {
- double ans = b - a;
- if (ans < 0)ans += 2 * n;
- return ans;
- }s
- bool ok(double x)
- {
- int sz = 0;
- FOR(i, 0, p)
- {
- if (DX[i] == 0)
- {
- int id = i + 1;
- E[sz++] = MP(0, id);
- }
- else if (DX[i] > 0)
- {
- double cur = .0;
- double pos = X[i];
- while (cur < 3 * n)
- {
- if (timeTo(x) < timeTo(2 * n - x))
- {
- pos = x;
- cur += timeTo(x);
- E[sz++] = MP(cur, DX[i] > 0 ? i + 1 : -(i+1));
- }
- }
- }
- }
- }
- double solve()
- {
- double l = .0;
- double r = n;
- FOR(i, 0, 60)
- {
- double m = (l + r) * .5;
- if (ok(m)) l = m;
- else r = m;
- }
- return l * m;
- }
- int main()
- {
- //freopen("in.txt", "r", stdin);
- //ios::sync_with_stdio(false); cin.tie(0);
- scanf("%d%d", &n, &m);
- scanf("%d", &p);
- FOR(i, 0, p)
- {
- scanf("%d%d%d%d", X + i, Y + i, DX + i, DY + i);
- }
- double ans = 1e100;
- FOR(it, 0, 2)
- {
- FOR(it2, 0, 2)
- {
- ans = min(ans, solve());
- FOR(i, 0, p)
- {
- swap(X[i], Y[i]);
- swap(DX[i], DY[i]);
- }
- }
- FOR(i, 0, p)
- {
- X[i] = n - X[i];
- DX[i] = -DX[i];
- }
- }
- ans = min(ans, solve());
- printf("%.7f", ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement