zoukankan      html  css  js  c++  java
  • CodeForces Round 195 Div2

    A. Vasily the Bear and Triangle
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.

    Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you to find two points A = (x1, y1) and C = (x2, y2), such that the following conditions hold:

    the coordinates of points: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1 < x2;
    the triangle formed by point A, B and C is rectangular and isosceles ( is right);
    all points of the favorite rectangle are located inside or on the border of triangle ABC;
    the area of triangle ABC is as small as possible.
    Help the bear, find the required points. It is not so hard to proof that these points are unique.

    Input
    The first line contains two integers x, y ( - 109 ≤ x, y ≤ 109, x ≠ 0, y ≠ 0).

    Output
    Print in the single line four integers x1, y1, x2, y2 — the coordinates of the required points.

    Sample test(s)
    input
    10 5
    output
    0 15 15 0
    input
    -10 5
    output
    -15 0 0 15

    #include<stdio.h>
    int main()
    {
        __int64 x,y,x1,x2,y1,y2;
        scanf("%I64d%I64d",&x,&y);
        if (x>0 && y>0)
        {
            x1=0;
            y1=x+y;
            x2=x+y;
            y2=0;
        }
        else if (x<0 && y>0)
        {
            x1=x-y;
            y1=0;
            x2=0;
            y2=y-x;
        }
        else if (x<0 && y<0)
        {
            x1=(x+y);
            y1=0;
            x2=0;
            y2=(x+y);
        }
        else
        {
            x1=0;
            y1=y-x;
            x2=x-y;
            y2=0;
        }
        printf("%I64d %I64d %I64d %I64d
    ",x1,y1,x2,y2);
        return 0;
    }

     

     

    B. Vasily the Bear and Fly
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    One beautiful day Vasily the bear painted 2m circles of the same radius R on a coordinate plane. Circles with numbers from 1 to m had centers at points (2R - R, 0), (4R - R, 0), ..., (2Rm - R, 0), respectively. Circles with numbers from m + 1 to 2m had centers at points (2R - R, 2R), (4R - R, 2R), ..., (2Rm - R, 2R), respectively.

    Naturally, the bear painted the circles for a simple experiment with a fly. The experiment continued for m2 days. Each day of the experiment got its own unique number from 0 to m2 - 1, inclusive.

    On the day number i the following things happened:

    The fly arrived at the coordinate plane at the center of the circle with number  ( is the result of dividing number x by number y, rounded down to an integer).
    The fly went along the coordinate plane to the center of the circle number  ( is the remainder after dividing number x by number y). The bear noticed that the fly went from the center of circle v to the center of circle u along the shortest path with all points lying on the border or inside at least one of the 2m circles. After the fly reached the center of circle u, it flew away in an unknown direction.
    Help Vasily, count the average distance the fly went along the coordinate plane during each of these m2 days.

    Input
    The first line contains two integers m, R (1 ≤ m ≤ 105, 1 ≤ R ≤ 10).

    Output
    In a single line print a single real number — the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.

    Sample test(s)
    input
    1 1
    output
    2.0000000000
    input
    2 2
    output
    5.4142135624

    #include<math.h>
    #include<stdio.h>
    double dis(int x,double R)
    {
        if (x==1) return 2*R+sqrt(2.0)*R;
        return (2*x-2)*R+sqrt(8.0)*R;
    }
    int main()
    {
        double m,R;
        int i;
        scanf("%lf%lf",&m,&R);
        double tot=m*2*R;
        for (i=1;i<m;i++) tot+=dis(i,R)*(m-i)*2;
        double ave=tot/(m*m*1.0);
        printf("%.10lf
    ",ave);
        return 0;
    }

     

     

  • 相关阅读:
    一键清理 Nexus 中无用的 Docker 镜像
    python 获取Linux和Windows硬件信息
    基于Docker安装破解版Jira(无坑)
    vim安装vundle时遇到的问题
    SpringBoot注解大全
    SpringBoot 应用JPA中的一些知识点
    记录初学SpringBoot使用Redis序列化的坑
    Spring Boot连接MySql报错
    钉钉扫码登录中的签名算法在python中的实现
    让Linux的history命令显示用户名和时间
  • 原文地址:https://www.cnblogs.com/dramstadt/p/3251388.html
Copyright © 2011-2022 走看看