結果

問題 No.172 UFOを捕まえろ
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-03-26 23:33:26
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 5,582 bytes
コンパイル時間 4,178 ms
コンパイル使用メモリ 81,720 KB
実行使用メモリ 37,260 KB
最終ジャッジ日時 2024-06-29 01:06:44
合計ジャッジ時間 6,275 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,632 KB
testcase_01 AC 52 ms
37,004 KB
testcase_02 AC 53 ms
37,052 KB
testcase_03 AC 52 ms
37,076 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 52 ms
37,016 KB
testcase_16 AC 53 ms
36,880 KB
testcase_17 WA -
testcase_18 AC 54 ms
37,148 KB
testcase_19 AC 53 ms
36,980 KB
testcase_20 AC 52 ms
36,888 KB
testcase_21 AC 54 ms
37,260 KB
testcase_22 AC 52 ms
37,164 KB
testcase_23 AC 52 ms
37,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.awt.geom.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No172 {

    static final InputStream in = System.in;
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve(){
        Point p = new Point(abs(nextInt()),abs(nextInt()));
        int r = nextInt();
        int i;
        for (i=(int)p.x+1;; i++) {
            if (ptSegDist(new Line(new Point(i,0),new Point(0,i)),p) >= r) {
                break;
            }
        }
        out.println(i);
    }

    static final double EPS = 1E-9;
    static boolean epsEquals(double a, double b) { return abs(a-b) < EPS; };

    static double dot(Point a, Point b) { return a.x*b.x + a.y*b.y; }
    static double cross(Point a, Point b) { return a.x*b.y - a.y*b.x; }

    static double ptSegDist(Line s, Point p) {
        if (dot(s.p2.sub(s.p1),p.sub(s.p1)) < 0) return distance(p,s.p1);
        if (dot(s.p1.sub(s.p2),p.sub(s.p2)) < 0) return distance(p,s.p2);
        return ptLineDist(s,p);
    }

    static double ptLineDist(Line l, Point p) {
        return abs(cross(p.sub(l.p1),l.p2.sub(l.p1)))/l.p2.sub(l.p1).length();
    }

    static double distance(Point a, Point b) {
        return a.sub(b).length();
    }

    static class Point extends Point2D.Double implements Comparable {
        double x, y;
        public Point(double x, double y) {
            this.x = x; this.y = y;
        }

        Point sum(Point a) { return new Point(x + a.x,y + a.y); }
        Point sub(Point a) { return new Point(x - a.x,y - a.y); }
        Point mul(double a) { return new Point(x * a,y * a); }
        Point div(double a) { return new Point(x / a,y / a); }

        double norm() { return this.distanceSq(x,y); }
        double length() { return this.distance(x,y); }

        @Override
        public int compareTo(Object other) {
            Point p = (Point)other;
            if (!epsEquals(this.x,p.x)) return this.x < p.x ? -1 : 1;
            if (!epsEquals(this.y,p.y)) return this.y < p.y ? -1 : 1;
            return 0;
        }
    }

    static class Line extends Line2D.Double {
        Point p1, p2;
        double x1,y1,x2,y2;
        public Line(Point p1, Point p2) {
            if (p1.compareTo(p2) < 0) {
                this.x1 = p1.x; this.y1 = p1.y; this.x2 = p2.x; this.y2 = p2.y;
                this.p1 = p1; this.p2 = p2;
            }else {
                this.x1 = p2.x; this.y1 = p2.y; this.x2 = p1.x; this.y2 = p1.y;
                this.p1 = p2; this.p2 = p1;
            }
        }
    }

    public static void main(String[] args) throws Exception {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}

    static final byte[] buf = new byte[1024];
    static int ptr = 0;
    static int buflen = 0;

    static boolean hasNextByte() {
        if (ptr < buflen)
            return true;
        ptr = 0;
        try{
            buflen = in.read(buf);
        }catch (IOException e) {e.printStackTrace();}
        if (buflen <= 0)
            return false;
        return true;
    }

    static int readByte() { if (hasNextByte()) return buf[ptr++]; else return -1;}

    static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}

    static void skip() { while(hasNextByte() && !isPrintableChar(buf[ptr])) ptr++;}

    static boolean hasNext() {skip(); return hasNextByte();}

    static String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    static long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        boolean minus = false;
        long num = readByte();

        if(num == '-'){
            num = 0;
            minus = true;
        }else if (num < '0' || '9' < num){
            throw new NumberFormatException();
        }else{
            num -= '0';
        }
        
        while(true){
            int b = readByte();
            if('0' <= b && b <= '9')
                num = num * 10 + (b - '0');
            else if(b == -1 || !isPrintableChar(b))
                return minus ? -num : num;
            else
                throw new NoSuchElementException();
        }
    }

    static int nextInt() {
        long num = nextLong();
        if (num < Integer.MIN_VALUE || Integer.MAX_VALUE < num)
            throw new NumberFormatException();
        return (int)num;
    }

    static double nextDouble() {
        return Double.parseDouble(next());
    }

    static char nextChar() {
        if (!hasNext()) throw new NoSuchElementException();
        return (char)readByte();
    }

    static String nextLine() {
        while (hasNextByte() && (buf[ptr] == '\n' || buf[ptr] == '\r')) ptr++;
        if (!hasNextByte()) throw new NoSuchElementException();

        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (b != '\n' && b != '\r') {
            sb.appendCodePoint(b);
            b = readByte();
        }

        return sb.toString();
    }

    static int[] nextArrayInt(int n) {
        int[] a = new int[n];
        for (int i=0; i<n; i++) a[i] = nextInt();
        return a;
    }
}
0