zoukankan      html  css  js  c++  java
  • Twin Buildings CodeForces

    http://codeforces.com/problemset/problem/1252/H

    As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of the same size. Now, their problem is to find land to build the buildings.

    There are NN lands available for sale. The ithith land has a rectangular shape of size Li×WiLi×Wi. For a good feng shui, the building's side should be parallel to the land's sides.

    One way is to build the two buildings on two different lands, one on each land (not necessarily with the same orientation). A building of size A×BA×B can be build on the ithith land if and only if at least one of the following is satisfied:

    • ALiA≤Li and BWiB≤Wi, or
    • AWiA≤Wi and BLiB≤Li.

    Alternatively, it is also possible to build two buildings of A×BA×B on the ithith land with the same orientation. Formally, it is possible to build two buildings of A×BA×B on the ithith land if and only if at least one of the following is satisfied:

    • A×2LiA×2≤Li and BWiB≤Wi, or
    • A×2WiA×2≤Wi and BLiB≤Li, or
    • ALiA≤Li and B×2WiB×2≤Wi, or
    • AWiA≤Wi and B×2LiB×2≤Li.

    Your task in this problem is to help ICPC Jakarta to figure out the largest possible buildings they can build given NNavailable lands. Note that ICPC Jakarta has to build two buildings of A×BA×B; output the largest possible for A×BA×B.

    Input

    Input begins with a line containing an integer: NN (1N1000001≤N≤100000) representing the number of available lands. The next NN lines each contains two integers: LiLi WiWi (1Li,Wi1091≤Li,Wi≤109) representing the size of the land.

    Output

    Output in a line a number representing the largest building that ICPC Jakarta can build with exactly one decimal point (see sample input/output for clarity).

    Examples

    Input
    2
    5 5
    3 4
    
    Output
    12.5
    
    Input
    2
    2 5
    4 3
    
    Output
    8.0
    
    Input
    3
    10 1
    9 8
    7 6
    
    Output
    42.0
    

    Note

    Explanation for the sample input/output #1

    Two buildings of 2.5×52.5×5 can be built both on the first land.

    Explanation for the sample input/output #2

    Two buildings of 2×42×4 can be built each on the first and second lands.

    Explanation for the sample input/output #3

    Two buildings of 7×67×6 can be built each on the second and third lands.

    巧妙的思维题

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 struct node
     6 {
     7     long long x, y;
     8 }a[100005];
     9 
    10 bool cmp(struct node a, struct node b)
    11 {
    12     return a.y > b.y;
    13 }
    14 
    15 int main()
    16 {
    17     int n, i;
    18     cin >> n;
    19     long long re = 0;
    20     for (i = 1; i <= n; i++)
    21     {
    22         cin >> a[i].x >> a[i].y;
    23         re = max(re, a[i].x*a[i].y);
    24         if(a[i].x > a[i].y) swap(a[i].x, a[i].y);
    25     }
    26     sort(a + 1, a + n + 1, cmp);
    27     long long xx = 0;
    28     for (int i = 1; i <= n; i++)
    29     {
    30         re = max(re, min(xx, a[i].x) * a[i].y * 2);
    31         xx = max(xx, a[i].x);
    32     }
    33     if (re % 2)
    34         printf("%lld.5
    ", re / 2);
    35     else
    36         printf("%lld.0
    ", re / 2);
    37     return 0;
    38 }
  • 相关阅读:
    LEFT JOIN个别问题
    phporjquery生成二维码
    杂项(乌班图、flex的使用实例)
    mysql创建用户并授权,解决1045
    jar运行指定jdk
    Flutter升级版本后,运行项目报错
    spring boot执行jar包指定active profile
    centos7 安装clamav 进行病毒扫描查杀
    CentOS7上安装MySQL 5.7.32(超详细)
    Centos7.5 安装elasticsearch 7.13.2 遇到的问题记录
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11783759.html
Copyright © 2011-2022 走看看