QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137670#2350. Integer Cow4k2kokWA 7ms3740kbC++202.7kb2023-08-10 16:26:182023-08-10 16:26:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 16:26:22]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3740kb
  • [2023-08-10 16:26:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define db long double

const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;

struct point {
    double x, y;
};
// typedef struct point point;
double xmult(point p1, point p2, point p0) {
    return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
double distance(point p1, point p2) {
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
//点到直线的距离
double disptoline(point p, point l1, point l2) {
    return fabs(xmult(p, l1, l2)) / distance(l1, l2);
}
//求两直线交点
point intersection(point u1, point u2, point v1, point v2) {
    point ret = u1;
    double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y) * (v1.x - v2.x))
    / ((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y) * (v1.x - v2.x));
    ret.x += (u2.x - u1.x) * t;
    ret.y += (u2.y - u1.y) * t;
    return ret;
}

void intersection_line_circle(point c, double r, point l1, point l2, point& p1, point& p2) {
    point p = c;
    double t;
    p.x += l1.y - l2.y;
    p.y += l2.x - l1.x;
    p = intersection(p, c, l1, l2);
    t = sqrt(r * r - distance(p, c) * distance(p, c)) / distance(l1, l2);
    p1.x = p.x + (l2.x - l1.x) * t;
    p1.y = p.y + (l2.y - l1.y) * t;
    p2.x = p.x - (l2.x - l1.x) * t;
    p2.y = p.y - (l2.y - l1.y) * t;
}

double r;

void solve() {
    point p, c;
    cin >> c.x >> c.y >> r >> p.x >> p.y;
    if(distance(c, p) <= r) {cout << "1\n" << p.x << " " << p.y << '\n'; return; }
    point p1, p2, o;
    intersection_line_circle(c, r, c, p, p1, p2);
    if(distance(p1, p) < distance(p2, p)) o = p1;
    else o = p2;
    point t = {-1 * (p.y - c.y) / distance(c, p), (p.x - c.x) / distance(c, p)};
    double minn = 4e9;
    point ans;
    for(int i = -1e5; i <= 1e5; i++) {
        point to = t;
        to.x *= i, to.y *= i;
        to.x += o.x, to.y += o.y;
        for(int u = -1; u <= 1; u++) {
            for(int v = -1; v <= 1; v++) {
                double xx = (ll)to.x + u;
                double yy = (ll)to.y + v;
                if(distance(c, {xx, yy}) <= r && minn > distance({xx, yy}, p)) {
                    minn = distance({xx, yy}, p);
                    ans = {xx, yy};
                }
            }
        }
    }
    cout << "1\n" << p.x << " " << p.y << " " << ans.x << ' ' << ans.y << '\n';
}

signed main(){
    io;
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 3740kb

input:

3
1 2 1 1 2
3 2 5 -10 3
0 0 1 10 0

output:

1
1 2
1
-10 3 -2 2
1
10 0 1 0

result:

wrong answer the destination point isn't inside the circle. (test case 1)