zoukankan      html  css  js  c++  java
  • ZOJ 1081 Points Within

    Points Within

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    Statement of the Problem

    Several drawing applications allow us to draw polygons and almost all of them allow us to fill them with some color. The task of filling a polygon reduces to knowing which points are inside it, so programmers have to colour only those points.

    You're expected to write a program which tells us if a given point lies inside a given polygon described by the coordinates of its vertices. You can assume that if a point is in the border of the polygon, then it is in fact inside the polygon.

    Input Format

    The input file may contain several instances of the problem. Each instance consists of: (i) one line containing integers N, 0 < N < 100 and M, respectively the number of vertices of the polygon and the number of points to be tested. (ii) N lines, each containing a pair of integers describing the coordinates of the polygon's vertices; (iii) M lines, each containing a pair of integer coordinates of the points which will be tested for "withinness" in the polygon.

    You may assume that: the vertices are all distinct; consecutive vertices in the input are adjacent in the polygon; the last vertex is adjacent to the first one; and the resulting polygon is simple, that is, every vertex is incident with exactly two edges and two edges only intersect at their common endpoint. The last instance is followed by a line with a 0 (zero).

    Output Format

    For the ith instance in the input, you have to write one line in the output with the phrase "Problem i:", followed by several lines, one for each point tested, in the order they appear in the input. Each of these lines should read "Within" or "Outside", depending on the outcome of the test. The output of two consecutive instances should be separated by a blank line.

    Sample Input

    3 1
    0 0
    0 5
    5 0
    10 2
    3 2
    4 4
    3 1
    1 2
    1 3
    2 2
    0

    Sample Output

    Problem 1:
    Outside

    Problem 2:
    Outside
    Within

    #include <stdio.h>
    #include <math.h>

    double D,M,A,J,jtime, jtimeaccellimit, jtimespeedlimit, jtimedistlimit,
    atime, dist, delta, a, b, c, r;

    double cubrt(double x) {
    return (exp(log(x)/3));
    }

    main(){
    while (4 == scanf("%lf%lf%lf%lf",&D,&M,&A,&J)) {
    jtimeaccellimit = A/J;
    jtimespeedlimit = sqrt(M/J);
    jtimedistlimit = cubrt(D/2/J);
    jtime = jtimeaccellimit;
    if (jtimespeedlimit < jtime) jtime = jtimespeedlimit;
    if (jtimedistlimit < jtime) jtime = jtimedistlimit;
    atime = (M - J*pow(jtime,2))/A;
    a = 0.5*A;
    b = A*jtime + 0.5*J*pow(jtime,2);
    c = J * pow(jtime,3) - D/2;
    r = (-b + sqrt(b*b - 4*a*c))/2/a;
    if (r < atime) atime = r;
    dist = J * pow(jtime,3)
    + 0.5*J*pow(jtime,2)*atime + 0.5*A * pow(atime,2)
    + A * atime*jtime;
    printf("%0.1lf\n",4*jtime+2*atime+2*(D/2-dist)/M);
    }
    }
  • 相关阅读:
    利用树莓派把普通打印机变成网络打印机方法
    Python之datetime库
    CentOS7从默认/home中转移空间到根分区/
    更改Azure虚拟机账号密码
    创建一个托管磁盘的Windows定制镜像
    IO多路复用详解
    玩转redis
    EF Linq to Sql 多表left join查询并对结果group by分组之后进行count,max等处理
    免费,主流的在线办公/协作,会议,文档,调查,分享工具推荐(持续维护中)
    多sql查询count合并为一行
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2250031.html
Copyright © 2011-2022 走看看