Gym 101047K Training with Phuket's larvae

http://codeforces.com/gym/101047/problem/K

题目:给定n<=2000条绳子,要你找出其中三条,围成三角形,并且要使得围成的三角形面积最小

思路: 考虑一下三角形面积公式1/2a*b*sinO ,那么可以暴力枚举两条边,第三条边要尽量小,为什么呢?因为我要使得O角尽量小。sin值也小了。这是根据小边对小角得到的。所以要找到第一条>a-b的。这样就能使结果最优。这个找可以用二分啦。同理找一个<a+b的

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 2e3+20;
double a[maxn];
const double eps = 1e-6;
bool same(double a,double b)
{
    return fabs(a-b)<eps;
}
double S(double a,double b,double c)
{
    double q = (a+b+c)/2;
    return sqrt(q*(q-a)*(q-b)*(q-c));
}
bool check (double a,double b,double c)
{
    if (a-b>=c) return false;
    if (a-c>=b) return false;
    if (b-c>=a) return false;
    return true;
}
void work ()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
        scanf("%lf",&a[i]);
    const double gg=-1;
    double ans = gg;
    sort(a+1,a+1+n);
    for (int i=2;i<=n-1;++i)
    {
        for (int j=i+1;j<=n;++j)
        {
            double find = a[j]-a[i];
            int pos = upper_bound(a+1,a+1+n,find)-a;
            if (pos!=n+1&&pos!=j&&pos!=i&&check(a[i],a[j],a[pos]))
            {
                if (ans==-1) ans=S(a[i],a[j],a[pos]);
                else ans=min(ans,S(a[i],a[j],a[pos]));
            }
            find=a[j]+a[i];
            pos = lower_bound(a+1,a+1+n,find)-a;
            if (pos!=n+1&&pos-1!=j&&pos-1!=i&&check(a[i],a[j],a[pos-1]))
            {
                if (ans==-1) ans=S(a[i],a[j],a[pos-1]);
                else ans=min(ans,S(a[i],a[j],a[pos-1]));
            }
        }
    }
    if (same(ans,gg))
    {
        printf ("-1\n");
        return ;
    }
    printf ("%0.10f\n",ans);
    return ;
}

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    int t;
    scanf("%d",&t);
    while(t--) work();
    return 0;
}

Gym 101047K Training with Phuket's larvae

时间: 2024-10-10 04:04:26

Gym 101047K Training with Phuket's larvae的相关文章

ACM: Gym 101047K Training with Phuket&#39;s larvae - 思维题

Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Practice Description standard input/output Thai cuisine is known for combining seasonings so that every dish has flavors that are s

Codeforces Gym 100676G Training Camp 状压dp

http://codeforces.com/gym/100676 题目大意是告诉你要修n门课,每门课有一个权值w[i], 在第k天修该课程讲获得k*w[i]的学习点数,给出了课程与先修课程的关系,要修该课程必须修完先修课程.问最多能学到多少点数. 非常简单的一道状压dp(一开始我还误导队友写成两维的去了 T^T); dp[s] : s 的二进制存放的是已经选择的课程,在该状态下的能获得的最大的点数. 这时如果再学一门课程k,将转移到状态ss (s | (1 << k) ) ,能否转移需要判断合

补题——Spring Training Series B 1st Round-A Gym - 100502A

题意:n个机场,m条关系,每个关系又a,b,c三个数,分别代表a和b两个机场间要建立c个休息室,让你求所建休息室最小的数目,如果不可能则输出impossible 思路:先把两个点之间c为0和2的都确定下来,再考虑1的情况.剩下的就是判断二分图(涂色法:https://blog.csdn.net/li13168690086/article/details/81506044),因为剩下的就是两个点间为1的情况: #include <cstdio> #include<bits/stdc++.h

ACM: Gym 101047M Removing coins in Kem Kadr&#227;n - 暴力

Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Practice Description standard input/output Andréh and his friend Andréas are board-game aficionados. They know many of their friends

ecjtu-summer training #4

Gym - 100952A 水题,看谁的时间少谁就赢了,不然就是平局. 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #define ll long long 5 using namespace std; 6 7 int main(){ 8 int n; 9 cin>>n; 10 while(n--){ 11 int h1,h2,m2,m1,s1,s2; 12 cin &

Gym 100952D Time to go back 组合学、杨辉三角预处理组合数

D - D Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100952D Description standard input/output Statements You have been out of Syria for a long time, and you recently decided to come back. You

Gym 100952H Special Palindrome 非递减的回文串、dfs打表、查数列网站OEIS

H - H Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100952H Description standard input/output Statements A sequence of positive and non-zero integers called palindromic if it can be read the s

CodeForces Gym 101047L Putting plates on the tuk-tuks 快速幂

Putting plates on the tuk-tuks Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 101047L Description standard input/output The tuk-tuk (????), also known as "auto rickshaw," is a popular form of transportation

CodeForces Gym 101047M Removing coins in Kem Kadr&#227;n 暴力

Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 101047M Description standard input/output Andréh and his friend Andréas are board-game aficionados. They know many of their friends would lo