codeforces-1027 C Minimum Value Rectangle

 1 #include <iostream>
 2 #include <unordered_map>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <queue>
 6 #define DEF 0x3f3f3f3f
 7 using namespace std;
 8
 9 int main()
10 {
11     int T;
12     scanf("%d",&T);
13     while(T --)
14     {
15         int n;
16         int hash[10001] {0};
17         vector<int> deal;
18         double diff = 10001;
19         int edge1 = 0,edge2 = 0;
20         int flag = 0;
21
22         scanf("%d\n",&n);
23         while(n --)
24         {
25             int tmp;
26             scanf("%d",&tmp);
27             hash[tmp] ++;
28             if(hash[tmp]==2)
29                 deal.emplace_back(tmp);
30             if(hash[tmp]==4)
31             {
32                 flag = 1;
33                 edge1 = edge2 = tmp;
34             }
35         }
36
37         if(flag)
38         {
39             printf("%d %d %d %d\n",edge1,edge1,edge2,edge2);
40             continue;
41         }
42         sort(deal.begin(),deal.end());
43         double minidiff = DEF;
44         for(int i = 0; i < deal.size()-1; i ++)
45         {
46             double tmp_diff = (double)deal[i+1]/(double)deal[i] + (double)deal[i]/(double)deal[i+1];
47         //    cout << deal[i+1] << " " << deal[i] << " " << tmp_diff << endl;
48             if(tmp_diff<diff)
49             {
50                 edge1 = deal[i];
51                 edge2 = deal[i+1];
52                 diff = tmp_diff;
53             }
54         }
55         printf("%d %d %d %d\n",edge1,edge1,edge2,edge2);
56     }
57     return 0;
58 }

原文地址:https://www.cnblogs.com/Asurudo/p/9510673.html

时间: 2024-08-30 18:29:33

codeforces-1027 C Minimum Value Rectangle的相关文章

[Swift Weekly Contest 116]LeetCode963. 最小面积矩形 II | Minimum Area Rectangle II

Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the x and y axes. If there isn't any rectangle, return 0. Example 1: Input: [[1,2],[2,1],[1,0],[0,1]]

LC 963. Minimum Area Rectangle II

Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the x and y axes. If there isn't any rectangle, return 0. Example 1: Input: [[1,2],[2,1],[1,0],[0,1]]

LeetCode 939. Minimum Area Rectangle

原题链接在这里:https://leetcode.com/problems/minimum-area-rectangle/ 题目: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes. If there isn't any rectangle, return

LeetCode 963. Minimum Area Rectangle II

原题链接在这里:https://leetcode.com/problems/minimum-area-rectangle-ii/ 题目: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the x and y axes. If there isn't

LeetCode - Minimum Area Rectangle

Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes. If there isn't any rectangle, return 0. Example 1: Input: [[1,1],[1,3],[3,1],[3,3],[2,2]] Output: 4 Ex

【leetcode】939. Minimum Area Rectangle

题目如下: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes. If there isn't any rectangle, return 0. Example 1: Input: [[1,1],[1,3],[3,1],[3,3],[2,2]] Output

Codeforces 730B:Minimum and Maximum(交互式问题)

http://codeforces.com/problemset/problem/730/B 题意:一个交互式问题,给出一个n代表有n个数字,你可以问下标为x和y的数的大小,会给出">","<"或"=",要求询问次数不能超过 ,最后输出最小的数和最大的数的下标. 思路:很新奇的题目.先将两两比较整理出一个max数组和min数组,这个时候前后较大的一个会在max数组中,较小的会在min数组中,这个时候询问了n/2次.接着我们只要对每个组

CodeForces 279D The Minimum Number of Variables 题解

题目大意: 有一组n个不相同的数字组成数串:a1,a2,a3-an. 1.一个数组b. 2.第一个操作我们将b0的值赋为a1.之后我们有n-1个操作,第k次操作我们将by=bi+bj(y,i,j可能相同). 3.每次操作结束后我们依次取出by.按顺序组成新串. 问操作结束后,我们获得的新串能否与a数串相同.如果可以输出数组b所需的最小长度.反之输出-1. 思路: 先介绍一个纯dfs的算法:每次依次枚举i,j,y,然而会T. 不过,可以发现,b中的数必定在a中出现过.因此,记忆化搜索,状态(s)中

Codeforces 805 D Minimum number of steps

题意: 给定一串字符串,将所有"ab"的子串替换为"bba",询问多少次操作后没有子串"ab". 分析: 观察可得,将"ab"替换为"bba"有两种结果. ①a移到了b的后面 ②增加了一个b 而且最终的结果一定是前面全是b,后面全是a. 所以可以猜想从后往前数,设置一个B_cnt, 每当碰到一个b, 就b_cnt++, 碰到A, 就先加上一个b_cnt(因为每替换一次会将a移动后一格,所以要替换b_cnt次

Codeforces 164 D Minimum Diameter

题目链接~~> 做题感悟:越来越感觉CF的题很好,很有深度. 解题思路: 这题需要注意 k 的大小,因为 k 只有 30 个,最终形成的点的直径一定是某个确定的值,所以我们可以枚举这个值,然后把大于这个值的边都取消(删除不大于k 个点),这样不断二分剩下点的最小直径,每次二分的时候判断是否合法.这里判断是否合法很重要,因为这需要用dfs去枚举,一不小心就会超时.dfs 在枚举删除每个点的时候主要枚举两个方面,(1)如果想删除与当前点相连的所有边,可以选择删除所有与之相连的点 (2)可以单独删除此