QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#719529 | #513. Pizza Cutting | kevinyang# | WA | 0ms | 4276kb | C++20 | 3.3kb | 2024-11-07 03:01:12 | 2024-11-07 03:01:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T> int sgn(T x) { return (x > 0 )- (x < 0) ; }
template <class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x = 0, T y = 0) : x(x), y(y) {}
bool operator<(P p) const {return tie(x,y) < tie(p.x,p.y); }
bool operator== (P p) const {return tie(x,y)== tie(p.x,p.y); }
P operator+(P p) const { return P(x+p.x,y+p.y); }
P operator-(P p) const { return P(x-p.x,y-p.y); }
P operator*(T d) const { return P(x*d,y*d); }
P operator/(T d) const { return P(x/d,y/d); }
T dot(P p) const { return x*p.x + y*p.y; }
T cross(P p) const { return x*p.y - y*p.x; }
T cross(P a, P b) const { return (a-*this).cross(b-*this); }
T dist2() const { return x*x+y*y;}
double dist() const { return sqrt((double)dist2()); }
double angle() const { return atan2(y,x);}
P unit() const { return *this/dist(); }
P perp() const { return P(-y,x); }
P normal() const { return perp().unit(); }
P rotate(double a) const {
return P(x*cos(a)-y*sin(a), x*sin(a)+y*cos(a));
}
friend ostream& operator<<(ostream& os, P p) {
return os << "(" << p.x << "," << p.y << ")";
}
};
typedef Point<double> P;
#define arg(p, q) atan2(p.cross(q), p.dot(q))
double circlePoly(P c, double r, vector<P> ps) {
auto tri = [&](P p, P q) {
auto r2 = r*r/2;
P d = q-p;
auto a = d.dot(p)/d.dist2(), b = (p.dist2()-r*r)/d.dist2();
auto det = a*a-b;
if (det <= 0) return arg(p,q)*r2;
auto s = max(0., -a-sqrt(det)), t = min(1., -a+sqrt(det));
if (t < 0 || 1 <= s) return arg(p, q) * r2;
P u = p+d*s, v=p+d*t;
return arg(p,u) * r2 + u.cross(v)/2 + arg(v,q)*r2;
};
auto sum = 0.0;
rep(i,0,sz(ps))
sum += tri(ps[i] - c, ps[(i+1)%sz(ps)] - c);
return sum;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int DX, DY, X, Y;
double R, PR;
cin >>R >> DX >> DY >> X >> Y >> PR;
while (X < R) X += DX;
while (X >= R) X -= DX;
while (Y < R) Y += DY;
while (Y >= R) Y -= DY;
double dx = DX;
double dy = DY;
P orig{0,0};
auto eval_square = [&](double cx, double cy) -> double {
vector<P> ps;
ps.push_back(P{cx,cy});
ps.push_back(P{cx+dx,cy});
ps.push_back(P{cx+dx,cy+dy});
ps.push_back(P{cx,cy+dy});
double a = circlePoly(orig, R, ps);
return a;
};
vector<double> areas;
int cx = X, cy = Y;
while (true) {
while (true) {
// eval square
double a = eval_square(cx, cy);
if (a > 1e-9) areas.push_back(a);
if (cx < -R) break;
cx -= DX;
}
if (cy < -R) break;
cy -= R;
cx = X;
}
sort(areas.begin(), areas.end());
int ans = 0;
int N = areas.size()-1;
const double EPS = 1e-6;
double yy = areas.back();
for (int i = 0; i < N; ++i) {
double xx = areas[i];
if (xx/yy <= PR + EPS) ++ans;
}
cout << ans << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4252kb
input:
100 45 90 0 -20 0.1
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4276kb
input:
100 45 90 0 -20 .999
output:
14
result:
ok single line: '14'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 4176kb
input:
3 1 1 2 -2 .9
output:
4
result:
wrong answer 1st lines differ - expected: '12', found: '4'