lightoj1022&&1072&&1107&&1118&&1178&&1216 "Basic Computational Geometry"

Source: Internet
Author: User
Tags acos cos sin x2 y2 cmath

1022-circle in Square
PDF (中文版) Statistics Forum
Time Limit: 0.5 second (s) Memory Limit: MB

A circle is placed perfectly into a square. The term perfectly placed means the side of the square are touched by the circle, but the circle doesn ' t has any ove Rlapping part with the square. See the picture below.


Now is given the radius of the circle. You have to find the area of the shaded region (blue part). Assume that pi = 2 * ACOs (0.0) (acos means cos inverse).

Input

Input starts with an integer T (≤1000), denoting the number of test cases.

Each case contains a floating point number R (0 < r≤1000) denoting the radius of the circle. And you can assume this R contains at the very four digits after the decimal point.

Output

For each case, print the case number and the shaded area rounded to both places after the decimal point.

Sample Input Output for Sample Input

3

20

30.091

87.0921

Case 1:343.36

Case 2:777.26

Case 3:6511.05

Note

This problem doesn ' t has special judge. So, being careful about precision problems. Better to add a small value to your the result to avoid precision problems. For example, add 10-9 to your result.


#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < algorithm> #include <cmath> #include <list> #include <vector> #include <queue> #define PI ACOs ( -1.0) using namespace Std;int main () {int t,test=1;double r;scanf ("%d", &t), while (t--) {scanf ("%lf", &r);p rintf ("Case%d:%.2lf\n", test++,4.0*r*r-pi*r*r);} return 0;}


1072-calm down
PDF (中文版) Statistics Forum
Time Limit: 2 second (s) Memory Limit: MB

George B. Wants to is 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 was, he wants a special revolver that would allow him to shoot more often than just the usual six times. This is the He can fool and kill the enemy easily (at least that's what's he thinks, and that's the best he can think). George has kidnapped ... uh, I mean ... "Invited" you and would only let you go if you are him with the math. The piece of the revolver that contains the bullets looks like this (examples for 6 and bullets):


There is a large circle with radius R and N little circles each have radius R, is placed INS The IDE on the border of the large circle. George wants his bullets to being as large as possible, so there should is no space between the circles. George would decide how large the whole revolver would be is and how many bullets it shall contain. Your job is, given R and N, to compute R. You have decided-to-help, because-know that a idiot can ' t make a revolver even if you help him with the math.

Input

Input starts with an integer T (≤125), denoting the number of test cases.

Each case contains a real number R (0 < R < $ and contains up-to-places after the decimal po int) and an integer n (2≤n≤100).

Output

For each test case, print the case number and R in a single line. Errors less than 10-6 'll be ignored.

Sample Input Output for Sample Input

4

4.0 6

4.0 17

3.14 100

42 2

Case 1:1.3333333333

Case 2:0.6209067545

Case 3:0.0956260953

Case 4:21

Finding the solution of the angle column equation of the center of the two circle and the Circle center

#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < algorithm> #include <cmath> #include <list> #include <vector> #include <queue> #define PI ACOs ( -1.0) using namespace Std;int main () {int t,i,j,k,test=1;double r,n;scanf ("%d", &t), while (t--) {scanf ("%lf%lf", &r,&n);d ouble angle=2.0*pi/n;printf ("Case%d:%.7lf\n", test++, (R*sin (angle/2.0)/(1+sin (angle/2.0)));} return 0;}

1107-how Cow
PDF (中文版) Statistics Forum
Time Limit: 2 second (s) Memory Limit: MB

Mr Kopa Samsu is a farmer. He has a land of rectangular shape. But there is cows that disturb him a lot. The cows use-enter his land and ruin his crops. Now Mr Kopa samsu have become smarter. He has a GPS system, that would help him to know the position of the cows. So, can think he land as a 2D grid, and cows can is treated as points. Now is given the information of his land and cows. Him whether a cow is inside he land or not.

Input

Input starts with an integer T (≤50), denoting the number of test cases.

The first line of each case contains four integers x1 y1 x2 y2, where (x1, y1) was the lower left Coordin Ate of his land and (x2, y2) are the upper right coordinate of he land. You can assume this sides of the land is axis parallel. The next line contains an integer M (1≤m≤100) denoting the number of cows. Each of the next M lines contains and integers each denoting x y -the position of a cow. You can safely assume that no cow would lie on the boundary of the rectangle. All the coordinates would lie in the range [0, 10000].

Output

For each case, you had to print the case number in a line first. Then for each cow, you had to print ' Yes ' or ' No ' depending whether the cow was inside the land or not.

Sample Input Output for Sample Input

1

1 2 8 10

7

0 0

5 6

1 0

7 9

3 5

10 10

1 11

Case 1:

No

Yes

No

Yes

Yes

No

No


#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < algorithm> #include <cmath> #include <queue> #include <list> #include <vector>using namespace Std;const int Maxn=10010;int main () {int x1,x2,y1,y2,t,x,y,test=1;scanf ("%d", &t), while (t--) {int n,i; scanf ("%d%d%d%d", &x1,&y1,&x2,&y2), scanf ("%d", &n);p rintf ("Case%d:\n", test++); for (i=0;i<n ; ++i) {scanf ("%d%d", &x,&y), if (x>=x1&&x<=x2&&y>=y1&&y<=y2) {printf (" Yes\n ");} else {printf ("no\n");}}} return 0;}


1118-incredible molecules
PDF (中文版) Statistics Forum
Time Limit: 0.5 second (s) Memory Limit: MB

In the biological lab, you were examining some of the molecules. You got some interesting behavior about some of the molecules. There is some circular molecules, when both of the them collide, they overlap with all other, and it's hard-to-find that whic H one is over the other one.

Given, molecules as circles, you are to find the common area of the Given molecules, which is shaded in the picture.


Overlapping molecules

Input

Input starts with an integer T (≤12), denoting the number of test cases.

Each case contains six integers x1, y1, R1 and x2, y2,R2. Where (x1, y1) is the center of the first molecule and R1 are the radius and (x2, y2) is the cen ter of the second molecule and R2 is the radius. Both the radiuses is positive. No integer would contain more than 3 digits.

Output

For each test case, print the case number and the common area of the given molecules. Errors less than 10-6 'll be ignored.

Sample Input Output for Sample Input

3

0 0 10 15 0 10

-10-10 5 0-10 10

100 100 20 100 110 20

Case 1:45.3311753978

Case 2:35.07666099

Case 3:860.84369


Intersection area of two circles


 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm># include<cmath> #include <queue> #include <vector> #define EPS 1e-6#define PI acos ( -1.0) using namespace Std;double area (double x1,double y1,double r1,double x2,double y2,double r2) {double d=sqrt ((x1-x2) * (X1-X2) + (y1-y2) * ( y1-y2));d ouble angle1,angle2,h1,h2,s1,s2;if (d>=r1+r2) {return 0;} if (D<=fabs (R1-R2)) {return min (PI*R1*R1,PI*R2*R2);} Angle1=acos ((D*D+R1*R1-R2*R2)/(2*D*R1)) Angle2=acos ((D*D+R2*R2-R1*R1)/(2*D*R2)); h1=angle1*r1*r1;h2=angle2*r2* R2;s1=r1*r1*cos (angle1) *sin (angle1); S2=r2*r2*cos (Angle2) *sin (angle2); return h1+h2-(S1+S2);} int main () {int t,test=1;double x1,y1,x2,y2,r1,r2;scanf ("%d", &t), while (t--) {scanf ("%lf%lf%lf%lf%lf%lf", &x1 , &Y1,&R1,&X2,&Y2,&R2);p rintf ("Case%d:%.7lf\n", Test++,area (X1,Y1,R1,X2,Y2,R2));} return 0;} 


1178-trapezium
PDF (中文版) Statistics Forum
Time Limit: 0.5 second (s) Memory Limit: MB

You is given the length of the four sides of a trapezium; Calculate the area. In geometry a 4-sided figure with exactly one pair of parallel sides is called a trapezium.


Input

Input starts with an integer T (≤20), denoting the number of test cases.

Each case contains four real numbers a b c D denoting the sides of the trapezium. Here a and C denote the parallel sides. You can safely assume so the given Trapezium is valid. Each of the numbers would be positive and isn't more than . And no number contains more than 4 digits after the decimal point.

Output

For each case, print the case number and the area. Errors less than 10-6 'll be ignored.

Sample Input Output for Sample Input

2

6 5 12 5.0

9 5 6 4

Case 1:36

Case 2:30

#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < algorithm> #include <cmath> #include <list> #include <queue> #include <vector>using namespace Std;const int Maxn=10010;int main () {int t,test=1;double a,b,c,d;scanf ("%d", &t), while (t--) {scanf ("%lf% Lf%lf%lf ", &a,&b,&c,&d);d ouble x=fabs (a-c);d ouble p= (b+d+x)/2;double tarea=sqrt (p* (p-d) * (p-b) * (p-x ));d ouble h=tarea*2/x;printf ("Case%d:%.7lf\n", Test++,min (a,c) *h+tarea);} return 0;}

1216-juice in the Glass
PDF (中文版) Statistics Forum
Time Limit: 2 second (s) Memory Limit: MB

Once upon a time, there lived a mad programmer. He loved to solve creative problems and other than anything. His wife loved him quite a lot, but disliked he curiosity for the problems. One day he came from office, his wife gave him a glass of cold lime juice. She is in a romantic mood and waiting for some romantic stuff. But the programmer asked she curiously, "If I give u radius of the top and bottom part of the glass and the height, can yo U come up with the volume of the glass? " He wife became a bit disappointed but as she's smart she replied with a smile, "You already has drunk some juice, and t He glass is no full. If I give you the height of the juice, can you find the volume of the remaining juice in the glass? " Then the programmer kissed he wife and said, "You is the best problem setter in the world!"


Now he sets the same problem for you. The radius of the upper part R1 and lower part R2 is given. If height of the glass is H and height of the juice are p What are the volume of the juice in the glass?

Input

Input starts with an integer T (≤100), denoting the number of test cases.

Each case starts with a line containing four integers r1 R2 h P (1≤r2 < r1≤100, 1≤p≤h≤100).

Output

For each case, print the case number and the volume of the juice in the glass. Errors less than 10-6 'll be ignored.

Sample Input Output for Sample Input

2

5 2 3 2

5 2 3 3

Case 1:58.643062867

Case 2:122.52211349

#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < algorithm> #include <cmath> #include <queue> #include <list> #include <vector> #define PI ACOs ( -1.0) using namespace Std;int main () {int t,test=1;double h,p,r1,r2;scanf ("%d", &t), while (t--) {scanf ("%lf%lf%lf% LF ", &r1,&r2,&h,&p);d ouble h= (h/(R1-R2)) *r1;double r3=r2+ ((R1-R2)/h) *p;double v1=pi*r3*r3* (H-h+p)/ 3.0;double v2=pi*r2*r2* (h-h)/3.0;printf ("Case%d:%.7lf\n", test++,v1-v2);} return 0;}


lightoj1022&&1072&&1107&&1118&&1178&&1216 "Basic Computational Geometry"

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.