hdoj 2552 三足鼎立 【math】

三足鼎立

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2412    Accepted Submission(s): 1340

Problem Description

MCA山中人才辈出,洞悉外界战火纷纷,山中各路豪杰决定出山拯救百姓于水火,曾以题数扫全场的威士忌,曾经高数九十九的天外来客,曾以一剑铸十年的亦纷菲,歃血为盟,盘踞全国各个要塞(简称全国赛)遇敌杀敌,遇佛杀佛,终于击退辽军,暂时平定外患,三人位置也处于稳态。

可惜辽誓不甘心,辽国征南大将军<耶律javac++>欲找出三人所在逐个击破,现在他发现威士忌的位置s,天外来客的位置u,不过很难探查到亦纷菲v所在何处,只能知道三人满足关系:

arctan(1/s) = arctan(1/u)+arctan(1/v)

注:(其中0 <= x <= 1)

定义 f(s, u, v) = v*u-s*u-s*v 的值 为<三足鼎立>

<耶律javac++>想计算<三足鼎立>的值

Input

首先输入一个t,表示有t组数据,跟着t行:

输入s, u (s <= 12^3, u <= 2^20 且 s, u, v > 0)

且s,u,v均为实数

Output

输出 v*u-s*u-s*v 的值,为了简单起见,如果是小数,直接取整

比如:答案是1.7 则输出 1

Sample Input

1
1 2

Sample Output

1

分析:这道题如果知道了atan就是arctan就好做了,但是还是会wa的,因为定义的double型是浮点型的所以直接取整有可能取错。例如输入是s = 2, 可能s实际上是2.0000001,又或者是1.999999999,这样的直接取整就错了,改ac的,一种是在算出结果之后加0.1再取整,一种是用.lf,四舍五入一下。

代码:

#include <stdio.h>
#include <string.h>
#include <math.h>
int main(){
    double s, u, v;
    int t;
    scanf("%d", &t);
    while( t --){
        scanf("%lf%lf", &s, &u);
        v = 1.0/(tan(atan(1.0/s)-atan(1.0/u)));
        printf("%.lf\n", (u*v-s*(u+v)));  //可以改成printf("%d\n", (int)(u*v-s*(u+v)+0.1));
    }
    return 0;
}
时间: 2024-08-30 11:39:01

hdoj 2552 三足鼎立 【math】的相关文章

HDU ACM 2552 三足鼎立

分析:数学公式推到: 1.tan(a+b) = ( tan(a) + tan(b) ) / (1 – tan(a) * tan(b) ) 2.tan( atan(x) ) = x 根据公式1和2有: arctan(1/s) = arctan(1/u)+arctan(1/v) 所以得1/s = tan( arctan(1/u)+arctan(1/v) ) = (tan(arctan(1/u)) + tan(arctan(1/v)))/(1-tan(arctan(1/u))*tan(arctan(1

hdoj 1757 A Simple Math Problem

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(

【HDOJ】5657 CA Loves Math

1. 题目描述对于给定的$a, n, mod, a \in [2,11], n \in [0, 10^9], mod \in [1, 10^9]$求出在$[1, a^n]$内的所有$a$进制下的数并且不含重复数字. 2. 基本思路这题比赛的时候,没人做出来,但是基本思路大家都有.显然可以直接将$n$改写为$\min(n,a)$.我比赛的代码TLE,思路是这样的:首先$mod$很小时,可以数位DP解:当$mod$很大时,可以先找到所有的排列然后,然后令$delta = fact(a)/fact(a

【HDOJ 1002】A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 238517    Accepted Submission(s): 45969 Problem Description I have a very simple problem for you. Given two integers A and B, you

【HDOJ】2424 Gary&#39;s Calculator

大数乘法加法,直接java A了. 1 import java.util.Scanner; 2 import java.math.BigInteger; 3 4 public class Main { 5 public static void main(String[] args) { 6 Scanner cin = new Scanner(System.in); 7 int n; 8 int i, j, k, tmp; 9 int top; 10 boolean flag; 11 int t

hdoj 1023 Train Problem II 【卡特兰】+【高精度】

题意:询问有多少种进站出站的顺序. 经典卡特兰.我对卡特兰目前的认识就是有n个1和n个-1,组成一个为2n的数列的方式有多少种.这就跟火车进站出站类似, 至于具体的卡特兰数的介绍,百度解释的很详细. 代码1(c语言): /* h(n) = h(n-1)*(4*n-2)/(n+1); */ #include <stdio.h> #include <string.h> #define M 110 int s[M][M] = {0}, b[M]; void init(){ s[1][0]

HDOJ 4965 Fast Matrix Calculation

(AB)^n=A*(BA)^(n-1)^B Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 576    Accepted Submission(s): 297 Problem Description One day, Alice and Bob felt bored again, B

HDOJ 2001 计算两点间的距离

计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 94573    Accepted Submission(s): 36296 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离. Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y

HDOJ 1715 大菲波数

JAVA大数.... 大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10812    Accepted Submission(s): 3653 Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值