QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137632 | #2350. Integer Cow | dzy521 | WA | 3ms | 3672kb | C++23 | 6.9kb | 2023-08-10 14:59:05 | 2023-08-10 14:59:08 |
Judging History
answer
#define _CRT_SEstartE_NO_DEPRECATE
#pragma warning(disable : 4996)
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
#define ACcode ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e6 + 7;
const ll maxm = 7e6 + 7;
constexpr ll mod = 998244353;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int Prime = 100007;
const double eps = 1e-10;
const double pi = acos(-1.0);
using namespace std;
using point_t = long long;
template <typename T>
struct point
{
T x, y;
point() {}
point(T _x, T _y) { x = _x, y = _y; }
point operator+(const point &b) const { return {x + b.x, y + b.y}; }
point operator-(const point &b) const { return {x - b.x, y - b.y}; }
point operator/(const T &k) const { return {x / k, y / k}; }
point operator*(const T &k) const { return {x * k, y * k}; }
T operator*(const point &b) const { return (x * b.x + y * b.y); }
T operator^(const point &b) const { return x * b.y - y * b.x; }
// 浮点数运算
T len2() const { return (*this) * (*this); }
T dis2(const point &a) const { return (a - (*this)).len2(); }
long double len() const { return sqrtl(len2()); }
long double dis(const point &a) const { return sqrtl(dis2(a)); }
};
using Point = point<point_t>;
template <typename T>
struct line
{
point<T> p, v; // 直线上一点和方向向量
line() {}
line(T k, T b) { p = {0, b}, v = {1, k}; }
line(point<T> _p, point<T> _v) { p = _p, v = _v; }
point<T> proj(const point<T> &a) const // 点在直线上的投影
{
return p + v * ((v * (a - p)) / (v * v));
}
long double dis(const point<T> &a) const // 点到直线距离
{
return abs(v ^ (a - p)) / v.len();
}
};
using Line = line<point_t>;
struct Circle
{
Point c;
long double r;
// 点与圆的关系
// -1 圆上 | 0 圆外 | 1 圆内
int is_in(const Point &p) const
{
const long double d = p.dis(c);
return abs(d - r) <= eps ? -1 : d < r - eps;
}
// 直线与圆关系
// 0 相离 | 1 相切 | 2 相交
int relation(const Line &l) const
{
const long double d = l.dis(c);
if (d > r + eps)
return 0;
if (abs(d - r) <= eps)
return 1;
return 2;
}
// 直线与圆的交点
vector<Point> inter(const Line &l) const
{
const long double d = l.dis(c);
const Point p = l.proj(c);
const int t = relation(l);
if (t == 0)
return vector<Point>();
if (t == 1)
return vector<Point>{p};
const long double k = sqrt(r * r - d * d);
return vector<Point>{p - (l.v / l.v.len()) * k, p + (l.v / l.v.len()) * k};
}
};
void solve()
{
cout << fixed << setprecision(0);
Point pc;
Circle cir;
cin >> cir.c.x >> cir.c.y >> cir.r >> pc.x >> pc.y;
if (cir.is_in(pc) != 0)
{
cout << 0 << '\n';
cout << pc.x << " " << pc.y << '\n';
return;
}
Line l1(pc, {pc.x - cir.c.x, pc.y - cir.c.y});
vector<Point> temp = cir.inter(l1);
Point cro;
if (pc.dis2(temp[0]) < pc.dis2(temp[1]))
cro = temp[0];
else
cro = temp[1];
Point ans;
ll ansdis = 4e18;
for (ll x = max(cir.c.x - (ll)cir.r, cro.x - 30000); x <= min(cir.c.x + (ll)cir.r, cro.x + 30000); x++)
{
if (cro.y >= cir.c.y)
{
ll l = cir.c.y, r = 3e9;
while (l < r)
{
ll mid = l + r >> 1;
Point now(x, mid);
if (cir.c.dis2(now) < cir.r * cir.r)
l = mid + 1;
else
r = mid;
}
for (int y = l - 20; y <= l + 20; y++)
{
Point now(x, y);
if (cir.is_in(now) != 0)
{
ll dis2 = pc.dis2(now);
if (dis2 < ansdis)
ans = now, ansdis = dis2;
}
}
}
else
{
ll l = -3e9, r = cir.c.y;
while (l < r)
{
ll mid = l + r >> 1;
Point now(x, mid);
if (cir.c.dis2(now) <= cir.r * cir.r)
r = mid;
else
l = mid + 1;
}
for (int y = l - 20; y <= l + 20; y++)
{
Point now(x, y);
if (cir.is_in(now) != 0)
{
ll dis2 = pc.dis2(now);
if (dis2 < ansdis)
ans = now, ansdis = dis2;
}
}
}
}
for (ll y = max(cir.c.y - (ll)cir.r, cro.y - 30000); y <= min(cir.c.y + (ll)cir.r, cro.y + 30000); y++)
{
if (cro.x >= cir.c.x)
{
ll l = cir.c.x, r = 3e9;
while (l < r)
{
ll mid = l + r >> 1;
Point now(mid, y);
if (cir.c.dis2(now) < cir.r * cir.r)
l = mid + 1;
else
r = mid;
}
for (int x = l - 15; x <= l + 15; x++)
{
Point now(x, y);
if (cir.is_in(now) != 0)
{
ll dis2 = pc.dis2(now);
if (dis2 < ansdis)
ans = now, ansdis = dis2;
}
}
}
else
{
ll l = -3e9, r = cir.c.y;
while (l < r)
{
ll mid = l + r >> 1;
Point now(mid, y);
if (cir.c.dis2(now) <= cir.r * cir.r)
r = mid;
else
l = mid + 1;
}
for (int x = l - 15; x <= l + 15; x++)
{
Point now(x, y);
if (cir.is_in(now) != 0)
{
ll dis2 = pc.dis2(now);
if (dis2 < ansdis)
ans = now, ansdis = dis2;
}
}
}
}
cout << 1 << '\n';
cout << pc.x << " " << pc.y << " " << ans.x << " " << ans.y << '\n';
}
signed main()
{
ACcode;
// freopen("house.in", "r", stdin);
// freopen("house.out", "w", stdout);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
input:
3 1 2 1 1 2 3 2 5 -10 3 0 0 1 10 0
output:
0 1 2 1 -10 3 -2 2 1 10 0 1 0
result:
ok correct (3 test cases)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
1 0 0 1 0 0
output:
0 0 0
result:
ok correct (1 test case)
Test #3:
score: 0
Accepted
time: 1ms
memory: 3656kb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-1 4 1 -7 7 1 6 1 2 0 2 -1 1 -7 -7 -7 -6 1 -9 -6 -8 2 1 -10 -9 -10 -8 1 7 -2 2 1 1 8 3 -1 7 1 2 -2 3 -3 1 -8 2 -3 -5 1 -1 0 -2 -1 0 -5 5 1 -4 -1 -3 5 1 -3 -7 -10 6 1 2 -3 -5 -3 1 -4 6 -3 6 1 -3 5 1 3 1 9 9 1 9 1 8 -10 2 -2 1 7 -1 5 1 ...
result:
ok correct (100 test cases)
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 3616kb
input:
100 -52 -13 72 44 58 79 -58 32 60 11 -50 21 75 95 65 -37 -61 21 -74 -40 0 -88 14 11 -49 10 -80 46 79 -17 75 -94 90 61 -34 -80 19 85 -7 -20 -72 42 56 67 -89 21 51 39 20 88 82 32 56 88 -82 3 51 31 -45 -53 50 12 91 9 46 -45 29 25 76 27 -19 -14 81 22 97 5 93 35 98 64 54 90 88 -100 63 -60 -18 81 -20 8 34...
output:
1 44 58 7 28 1 60 11 68 -28 1 95 65 22 42 1 -74 -40 -54 -49 1 11 -49 5 -75 1 79 -17 43 -48 0 61 -34 0 -7 -20 1 67 -89 -30 5 0 20 88 1 88 -82 82 -24 1 -45 -53 -4 21 0 9 46 1 76 27 -20 29 1 22 97 9 62 1 98 64 39 85 1 -100 63 -33 84 0 -20 8 1 62 16 46 51 1 -46 66 -79 -27 1 62 -91 -11 -54 1 -55 -54 73 -...
result:
wrong answer the distance of your solution has travelled is longer than expected. (test case 12)