openjudge-swollen sticks

Source: Internet
Author: User
Tags asin cos

http://noi.openjudge.cn/ch0111/09/

Total time limit: 1000ms memory limit: 65536kB
Describe

When the temperature of a fine stick of length l is increased by n degrees, it expands to the new length l ' = (1+n*c) *l, where C is the coefficient of thermal expansion.

When a thin stick is heated between two walls, it expands to form an arc of the bow, and the bow chord is the original position of the stick before it is heated.

Your task is to calculate the offset distance from the center of the stick.

Input

Three nonnegative real numbers: The initial length of the stick (in millimeters), the temperature change (unit: degree), and the coefficient of thermal expansion of the material.
Ensure that the stick does not swell to 1.5 times times the original length.

Output

The offset distance (in millimeters) of the center of the stick, reserved to the third digit after the decimal point.

Sample input

1000 100 0.0001

Sample output

61.329

Reference:

http://blog.csdn.net/jeremygjy/article/details/49686943

http://blog.csdn.net/txl199106/article/details/49332261

1#include <stdio.h>2#include <math.h>3 #definePI (ACOs (-1))4 #defineEPS (1E-14)5 intMainintargcChar*argv[])6 {7     Doublel,n,c,l1;8     9     DoubleMincentralangle,maxcentralangle,centralangle;Ten     DoubleRadius,l2; One     Doubleans; A      -scanf"%LF%LF%LF",&l,&n,&C); -      the     if(n*c*l<=eps)//If the expansion amount is too small to calculate, the result is directly considered to be 0. -     { -printf"0.000\n"); -         return 0; +     } -      +L1= (1+N*C) *L; A      at     //Two-point enumeration under the face of central angle -     //(the amount of swelling does not exceed 1.5 times times the original, -     //analysis of the relationship between the half-perimeter pi*r and diameter 2*r of a circle central angle range 0~2*pi and impossible to take 2*pi) -mincentralangle=0;//the minimum value of the center angle -Maxcentralangle=pi;//the maximum value of the center angle -      while(mincentralangle<maxcentralangle-EPS) in     { -Centralangle= (Mincentralangle+maxcentralangle)/2; toradius=l/2/sin (centralangle/2); +l2=centralangle*radius; -         if(L2&GT;=L1)//When the chord length is fixed, the larger the central angle, the greater the arc length. themaxcentralangle=Centralangle; *         Else if(l2<L1) $mincentralangle=Centralangle;Panax Notoginseng     } -radius=l/2/sin (mincentralangle/2); theans=radius-l/2/tan (mincentralangle/2); +printf"%.3lf\n", ans); A     return 0; the}

Be sure to note that we need two points of content is the current angle, then the angle of the range can be easily found, because the length of the wood pipe is not more than 1.5 times times the angle of 0- π because if central angle too small will find the radius is very large root, in fact, this situation when the length of the stick change is very small then

if(n * c * L <= eps)
Judging if that's the direct output of 0.000,

Also note: When the chord length is fixed, the larger the central angle, the larger the arc length.

Netizen JEREMYGJY Code and analysis is very good, excerpt a bit:

Jeremygjy's Code:

1#include <cstdio>2#include <cmath>3#include <algorithm>4 using namespacestd;5 Const DoublePI = ASIN (1.0);6 Const DoubleEPS = 1e- -;7 intMain () {8     DoubleLen1, Len2, Temp, KS;9      while(SCANF ("%LF%LF%LF", &len1, &temp, &ks)! =EOF) {TenLen2 = (1.0+ Temp * KS) *Len1; One         DoubleL=0, r=PI; A         if(TEMP * ks * Len1 <=EPS) { -printf"%.3lf\n",0.0); -             Continue; the         } -          while(L < R-EPS) { -             DoubleMid = (L + r)/2.0; -             if(Len1/sin (mid) *pi* (MID/PI) >=Len2) +R =mid; -             ElseL =mid; +         } Aprintf"%.3lf\n", len1/2/sin (L)-len1/2/sin (L) *cos (l)); at     } -  -     return 0; -}
View Code

CSDN netizen Tank_long Analysis is more exciting, but the following figure of the formula seems a bit messy.

The formula is probably as follows:

The first thing to note is that the θ angle is half the center angle. Then according to the mathematical formula are:

Sinθ=2sin (Θ/2) cos (Θ/2)

1-cosθ=2sin (Θ/2) 2

Then also note that according to the definition of right triangle sine there are: l=2*r*sinθ

According to the ARC length formula has ll=2*r*θ

So h=r-r*cosθ=r* (1-cosθ) =l/(2*sinθ) * (1-cosθ) =l/(2*sinθ) * (2sin (Θ/2) 2) =l/(2*sin (Θ/2) *cos (Θ/2))) * (2sin (Θ/2) 2)

Last H=l/2*tan (Θ/2)

Note that θ is half of the center angle, so the θ interval is 0~pi, and according to the graph properties of the tangent function it is known that when L is fixed, h is proportional to θ.

Tank_long code: (Have to admire the math skills ah ...) )

1#include <stdio.h>2#include <stdlib.h>3#include <math.h>4 intMain ()5 {  6     DoubleL, LL, rig, Lef, Mid, N, c; 7scanf"%LF%LF%LF", &l, &n, &c); 8   9     if(l<1e- -)  Ten     {   Oneprintf"0.000\n");  A         return 0;  -     }   -ll=l* (1+n*c);  thelef=0.0;//the minimum value of the angle -Rig=asin (1.0);//the maximum value of the angle -     //because the trigonometric functions are converted, h= (L/2) *tan (@/2) is obtained, so H is only related to the angle @, and the nearest @ can be solved by using the dichotomy approximation method . -     //Note that the binary verification is to compare the original length l ' =ll*[email protected]/@ of the stick with the angle @ calculated by LL with the L ', and l ' is inversely proportional to the @ +      while(rig-lef>1e- -)//two points between maxima and minima, this local precision control is too must not.  The accuracy requirement is very high.  -     {   +Mid= (Rig+lef)/2;  A         if(Ll*sin (mid)/mid<=l) atrig=mid;  -         Else   -lef=mid;  -     }   -printf"%.3lf\n", l/2*tan (lef/2));  -     return 0;  in}
View Code

openjudge-swollen sticks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.