LightOJ 1072 - Calm Down 【二分】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1072

解法:考虑角度的关系 二分r

代码:

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string.h>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>  

using namespace std;

const double PI = acos(-1);

double R;
int n;

bool is_ok(double mid)
{
    double y = R - mid;
    double tmp = asin(mid/y);
    int tn = (PI / tmp);
    if (tn >= n) return true;
    else return false;
}

int main()
{
    int cases = 1;
    int t;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%lf %d", &R, &n);
        double left = 0, right = R;

        while (right - left > 1e-8)
        {
            double mid = (left + right) / 2;
            if (is_ok(mid)) left = mid;
            else right = mid;
        }
        printf("Case %d: %.8lf\n", cases++, right);
    }
    return 0;
}

版权声明:转载请注明出处。

时间: 2024-08-25 07:04:10

LightOJ 1072 - Calm Down 【二分】的相关文章

LightOJ 1307 Counting Triangles 二分查找

[题解整理]二分题 题目类型: 二分查找: 二分答案. 大致解题思路: 查找注意有序和返回值: 浮点数注意精度: 整数注意返回值,建议另外维护一个变量,用于储存可行解. 题目 分类 传送门 WA点 poj 2785 二分查找 题解 lightoj 1088 二分查找 题解 lightoj 1307 二分查找 题解 longlong poj 2456 整数二分答案 题解 poj 3104 整数二分答案 题解 poj 3258 整数二分答案 题解 poj 3273 整数二分答案 题解 lightoj

lightoj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

lightoj-1072 - Calm Down(找出等价关系)

1072 - Calm Down PDF (English) Statistics ForumTime Limit: 2 second(s) Memory Limit: 32 MBGeorge B. wants to be more than just a good American. He wants to make his daddy proud and become a hero. You know, like Shakib Khan. But sneaky as he is, he wa

lightoj1022&amp;&amp;1072&amp;&amp;1107&amp;&amp;1118&amp;&amp;1178&amp;&amp;1216【基础计算几何】

1022 - Circle in Square    PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB A circle is placed perfectly into a square. The term perfectly placed means that each side of the square is touched by the circle, but the circle

light oj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

Lightoj 1043 - Triangle Partitioning【二分】

题目链接:http://lightoj.com/volume_showproblem.php?problem=1043 题意:一个三角形ABC,DE//BC,已知三角形ADE和四边形BDEC的面积的比,求AD的长度. 解法:二分AD边即可 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include

Lightoj 1235 - Coin Change (IV) 【二分】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1235 题意: 有N个硬币(N<=18).问是否能在每一个硬币使用不超过两次的情况下支付正好K的面额. 思路 : dfs构造出用这些硬币用前一半能支付的全部费用和后一半能支付的全部费用. 之后排序,枚举前一半的每一个面值在第二个里面二分寻找就可以.(或者用set保存). 代码:(set) #include <stdio.h> #include <ctime>

LightOJ 1048 - Conquering Keokradong 【二分】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1048 题意:有N 个数,将它们按顺序分成M份,M<=min(N,300).使得每一份的和的最大值最小.有很多中情况,这些情况中第一天.第二天--的和最大的情况. 思路 : 二分最大的和,得到一个数mid.判断是否符合条件. 代码:(不能AC 实在是找不出来了,先放着) #include <stdio.h> #include <ctime> #include

Lightoj 1062 - Crossed Ladders【二分】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1062 题意: 两个梯子靠墙放,一个长度是x一个长度是y,它们交点到地面的距离是c.求这两个梯子底部的距离. 思路:二分底部的距离t,往计算t' ,根据t和t'的大小关系更新上下界即可. 设宽为mid,那么可以求得 c/sqrt( y^2 - mid^2 ) + c/sqrt( x^2 - mid ^2 ) = 1 代码: #include <stdio.h> #includ