首页 > 其他分享 >ZOJ Monthly, August 2014 ZOJ - 3806 计算几何+二分

ZOJ Monthly, August 2014 ZOJ - 3806 计算几何+二分

时间:2023-04-24 23:38:35浏览次数:36  
标签:2.0 August Monthly double ZOJ mid tpow include define

A triangle is one the basic shapes in geometry. It’s a polygon with three vertices and three sides which are line segments. A triangle with vertices A, B, C is denoted ΔABC. And its three sides, BC, CA, AB are often denoted a, b and c.

The incircle of a triangle is the largest circle contained in the triangle, it is tangent to the three sides. The center of the incircle is called the triangle’s incenter and the radius of the incircle is called inradius, which is denoted r.

The circumcircle of a triangle is the circle which passes through all its three vertices. The center of the this circle is called circumcenter and its radius is called circumradius, which is denoted R.

It’s very easy to calculate r and R after knowing a, b and c. Now you are given r and R, can you calculate a valid triple (a, b, c)?

Input
There are multiple cases. Each case has two positive integers r and R in one line. (r and R are less than 105)

Ouput
For each case, print three floating numbers a, b and c in one line if it’s possible to get r and R. If there are no possible tuples, print “NO Solution!”.

The judge program uses your a, b and c to calculate the inradius and circumradius. Only the relative error of your inradius and circumradius less than 10-8 will be accepted.

Sample Input
1 2
2 5
9 9
Sample Ouput
3.464101615137754587 3.464101615137754587 3.464101615137754587
6 8 10
NO Solution!

考虑有解的情况:
我们可以构造一个等腰三角形,然后二分底边的长度,再通过等面积法算出内切圆半径,与题目所给进行比较,缩小范围

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 800005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-10
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    a = a % mod;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

double tpow(double a) {
    return a * a;
}


int main()
{
    //ios::sync_with_stdio(false);
    double r, R;
    while (cin >> r >> R) {
        if (r*2 > R) {
            cout << "NO Solution!" << endl;
        }
        else {
            double lft = 0, rig = sqrt(3.0)*R;
            while (rig - lft > eps) {
                double mid = (rig + lft) / 2.0;
                double x = sqrt(tpow(sqrt(tpow(R) - tpow(mid / 2.0)) + R) + tpow(mid / 2.0));
                double area = (sqrt(tpow(R) - tpow(mid / 2.0)) + R)*mid / 2.0;
                double pp = (x + x + mid) / 2.0;
                double rr = area / pp;
                if (rr - r > eps)rig = mid;
                else lft = mid;
            }
            double x = sqrt(tpow(sqrt(tpow(R) - tpow(lft / 2.0)) + R) + tpow(lft / 2.0));
            double y = lft;
            printf("%.15f %.15f %.15f\n", x, x, y);
        }
    }
}

标签:2.0,August,Monthly,double,ZOJ,mid,tpow,include,define
From: https://blog.51cto.com/u_15657999/6221985

相关文章

  • bzoj3032 七夕祭
    七夕祭题目链接解析:如果交换左右两边的位置每一行感兴趣的摊位数量不变同理交换上下两边的位置每一列感兴趣的摊位数量不变所以该问题可以分解为两个一维的问题:用最少的步数使每一行的摊位数目相等用最少的步数使每一列的摊位数目相等前提是总的行数上的感兴趣的数目或......
  • BZOJ 2038 小Z的袜子(hose) (莫队离线)
    题目地址:BZOJ2038裸的莫队算法。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>#include<set>#include<stdio.h>#incl......
  • ZOJ 3886 Nico Number (线段树)
    题目地址:ZJU3886这个题需要想到一点,因为对一个数x不断取模的话,而且设定他小于模才会进行取余操作的话,那么最多只会进行logx次,因为每次取模都会使x最少折半。然后想到了这点就很好做了。对于区间取模更新操作可以直接暴力更新,维护一个最大值,如果这个区间的最大值小于模的话,就......
  • BZOJ 2243 [SDOI2011] 染色 (树链剖分)
    题目地址:BZOJ2243普通的树链剖分,用线段树维护区间段数与最左边和最右边的颜色。然后当合并区间的时候判断一下左儿子的右端与右儿子的左端是否相同,若相同,则将和减去1.同样,在迭代求值的过程中,也要记录下上条链的最顶端的颜色。代码如下:#include<iostream>#include<strin......
  • BZOJ 1036 [ZJOI2008] 树的统计Count (树链剖分)
    题目地址:BZOJ1036树链剖分裸题,需要用线段树同时维护最大值与和值两个信息,只是代码量大一点而已。。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>#include<set&g......
  • ZOJ 3348 Schedule(map运用+网络流之最大流)(竞赛问题升级版)
    题目地址:ZOJ3348仍然是一道竞赛问题的网络流问题,但是这道题再用上次的竞赛建图方法就不行了,5000场比赛,明显会超时,于是需要换种建图思路了。上一道经典竞赛问题戳这里上一道的胜负转换是利用专门给比赛建一个点,通过对比赛双方的流向来控制胜负关系,这里的建图方法更加巧妙(膜拜想出这......
  • ZOJ - 3469 Food Delivery(区间DP)
    题目大意:有一个餐厅,在X这个位置,送餐速度为v的-1次方,有N个顾客,分别在pos位置,每个顾客都有一个displeasure值,当餐送到该顾客手上时,该顾客的displeasure总值为displeasure值*到手时间问所有顾客的最小displeasure总值和是多少解题思路:首先按位置排个序设dp[i][j][0]为[i,j]这个区......
  • ZOJ - 2421 Recaman's Sequence(打表水题)
    题目大意:A0=0Am=A(m-1)-m,如果Am小于0或者Am前面已经出现过了,那么Am=A(m-1)+m解题思路:打表水题我用的是map,纪录数是否出现过了#include<cstdio>#include<cstring>#include<map>usingnamespacestd;constintN=500010;typedeflonglongLL;map<LL,int>Ma......
  • bzoj 4237 稻草人
    4237:稻草人TimeLimit: 40Sec  MemoryLimit: 256MBSubmit: 791  Solved: 353[Submit][Status][Discuss]DescriptionJOI村有一片荒地,上面竖着N个稻草人,村民们每年多次在稻草人们的周围举行祭典。有一次,JOI村的村长听到了稻草人们的启示,计划在荒......
  • bzoj 3622 已经没有什么好害怕的了
    3622:已经没有什么好害怕的了TimeLimit: 10Sec  MemoryLimit: 256MBSubmit: 805  Solved: 377[Submit][Status][Discuss]DescriptionInputOutputSampleInput42535154540201030SampleOutput4HINT输入的2*n个数字保证全不相同。......