QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#498594#7674. SkiingMax_s_xaMWA 1ms5756kbC++145.7kb2024-07-30 16:29:142024-07-30 16:29:14

Judging History

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

  • [2024-07-30 16:29:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5756kb
  • [2024-07-30 16:29:14]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 260;
const lf eps = 1e-9;

int n; lf vy, ax;

struct Point
{
    lf x, y; int id;
    bool operator < (const Point &u) const { return (fabs(y - u.y) < eps ? id < u.id : y < u.y); }
}a[MAXN];

lf fmn[MAXN][MAXN], fmx[MAXN][MAXN];
int g[MAXN][MAXN];
int st[MAXN], top;

inline lf Calc1(lf v1, lf v2, lf t)
{
    lf h = (ax * t + v1 + v2) / 2;
    lf x1 = (ax * t + v2 - v1) / ax / 2, x2 = t - x1;
    return ((h + v1) * x1 + (h + v2) * x2) / 2;
}
inline lf Calc2(lf v1, lf v2, lf t)
{
    lf h = (-ax * t + v1 + v2) / 2;
    lf x1 = (ax * t + v1 - v2) / ax / 2, x2 = t - x1;
    return ((h + v1) * x1 + (h + v2) * x2) / 2;
}

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n), Read(vy), Read(ax);
    for (int i = 1, j = 1; i <= n; i++, j++)
    {
        Read(a[i].x), Read(a[i].y);
        if (a[i].y < 0) { i--, n--; continue; }
        a[i].y /= vy, a[i].id = j;
    }
    a[++n] = Point{0, 0, 0};
    sort(a + 1, a + n + 1);
    if (ax == 0)
    {
        bool flag = 0;
        for (int i = 1; i <= n; i++)
            if (a[i].x == 0) { cout << a[i].id << ' '; flag = 1; }
        if (!flag) cout << "Cannot visit any targets\n";
        return 0;
    }
    // for (int i = 1; i <= n; i++) cout << a[i].x << ' ' << a[i].y << '\n';
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= n; j++)
            fmn[i][j] = 1e18, fmx[i][j] = -1e18;
    fmn[1][0] = fmx[1][0] = 0;
    for (int i = 2; i <= n; i++)
    {
        for (int j = 1; j < i; j++)
        {
            for (int k = 1; k < i; k++)
            {
                if (fmn[k][j - 1] == 1e18 || fmx[k][j - 1] == -1e18) continue;
                lf len = a[i].y - a[k].y, dist = a[i].x - a[k].x;
                // cout << i << ' ' << j << ' ' << k << ' ' << len << ' ' << dist << ' ' << len * ax << "\n";
                // cout << fmx[k][j - 1] << '\n';
                // cout << Calc1(fmx[k][j - 1], fmx[k][j - 1] + len * ax, len) << ' ' << Calc2(fmn[k][j - 1], fmn[k][j - 1] - len * ax, len) << '\n';
                if (Calc1(fmx[k][j - 1], fmx[k][j - 1] + len * ax, len) < dist) continue;
                if (Calc2(fmn[k][j - 1], fmn[k][j - 1] - len * ax, len) > dist) continue;
                lf l = fmn[k][j - 1] - len * ax, r = fmx[k][j - 1] + len * ax, mid, L, R;
                while (r - l > eps)
                {
                    mid = (l + r) / 2;
                    if (Calc1(fmx[k][j - 1], mid, len) < dist) l = mid;
                    else r = mid;
                }
                L = l;
                l = fmn[k][j - 1] - len * ax, r = fmx[k][j - 1] + len * ax;
                while (r - l > eps)
                {
                    mid = (l + r) / 2;
                    if (Calc2(fmn[k][j - 1], mid, len) > dist) r = mid;
                    else l = mid;
                }
                R = l;
                if (R < L) continue;
                // cout << "Trans " << k << ' ' << j - 1 << " to " << i << ' ' << j << " : " << fmn[k][j - 1] << ' ' << fmx[k][j - 1] << ' ' << L << ' ' << R;
                if (fmx[i][j] < R) g[i][j] = k;
                // cout << " with " << g[i][j] << '\n';
                fmx[i][j] = max(fmx[i][j], R), fmn[i][j] = min(fmn[i][j], L);
            }
        }
    }
    int x = 1, y = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < i; j++)
            if (fmn[i][j] != 1e18 && fmx[i][j] != -1e18 && y < j)
                x = i, y = j;
    if (y == 0) return cout << "Cannot visit any targets\n", 0;
    // cout << "-----------\n";
    // cout << x << ' ' << y << "\n";
    while (x != 1)
    {
        st[++top] = a[x].id;
        x = g[x][y], y--;
    }
    for (int i = top; i >= 1; i--) cout << st[i] << ' '; cout << '\n';
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

input:

4 100 400
-100 100
50 200
-100 300
150 300

output:

1 2 4 

result:

ok single line: '1 2 4 '

Test #2:

score: 0
Accepted
time: 1ms
memory: 5620kb

input:

1 100 100
1000 10

output:

Cannot visit any targets

result:

ok single line: 'Cannot visit any targets'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5692kb

input:

0 100 100

output:

Cannot visit any targets

result:

ok single line: 'Cannot visit any targets'

Test #4:

score: 0
Accepted
time: 0ms
memory: 5716kb

input:

2 100 100
100 100
-100 100

output:

Cannot visit any targets

result:

ok single line: 'Cannot visit any targets'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

2 1000 2001
1000 1000
-1000 1000

output:

1 

result:

ok single line: '1 '

Test #6:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

3 10 30
10 10
-10 10
0 20

output:

1 

result:

ok single line: '1 '

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 5756kb

input:

3 10 31
10 10
-10 10
0 20

output:

2 3 

result:

wrong answer 1st lines differ - expected: '1 3', found: '2 3 '