zoukankan      html  css  js  c++  java
  • B. Cover Points Codeforces Round #511 (Div. 2)【数学】

    题目:

    There are nn points on the plane, (x1,y1),(x2,y2),,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn).

    You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.

    Input

    First line contains one integer nn (1n10^5).

    Each of the next nn lines contains two integers xixi and yiyi (1xi,yi10^9).

    Output

    Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.

    Examples
    input
    3
    1 1
    1 2
    2 1
    output
    3
    input
    4
    1 1
    1 2
    2 1
    2 2
    output
    4
    Note

    Illustration for the first example:

    Illustration for the second example:

    题意分析:

    在二维平面坐标系,给你N个坐标点(都在第一象限),让你找一条直线,使这条直线能够与两条坐标轴围成一个等腰三角形,这个三角形能包含所有的点。求这个三角形最短的边长。

    边长最短,肯定就是这些点中最外层的点刚好在直线上即可。因为是等腰三角形,所以斜率必然为-1。那么这条直线的表达式为:X+Y= d; 那么所有的点满足X+Y <= d。

    这个d的最小值就是我们所要求的,转换一下,相当于就是求输入坐标的x+y的最大值。

    代码:

     

    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    int Max(const int a, const int b)
    {
        return a>b?a:b;
    }
    
    int main()
    {
        int N, a, b, ans = 0;
        while(~scanf("%d", &N))
        {
            for(int i = 0; i < N; i++)
            {
                scanf("%d %d", &a, &b);
                ans = Max(ans, a+b);
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    springboot -jar部署
    base64前端对登陆密码编码,后端解码
    数字择优( 计算一个数与一组数字中的哪一个数字大小最接近)
    求两个数组的最小差值
    url.openConnection()远程获取图片缺失
    HttpURLConnection 用法详解
    Eureka集群入门搭建
    Django基础(五)- form组件及django序列化
    django基础(四)- 分页组件
    Django基础(四)-cookie与session
  • 原文地址:https://www.cnblogs.com/dybala21/p/9692071.html
Copyright © 2011-2022 走看看