lightoj1022&&1072&&1107&&1118&&1178&&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 doesn‘t have any overlapping part with the square. See the picture below.

Now you are 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 that r contains at most four digits after the decimal point.

Output

For each case, print the case number and the shaded area rounded to two 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 have special judge. So, be careful about precision problems. Better to add a small value to your 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);
		printf("Case %d: %.2lf\n",test++,4.0*r*r-PI*r*r);
	}
	return 0;
}

1072 - Calm Down

   PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

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

There is a large circle with radius R and n little circles each having radius r, are placed inside on the border of the large circle. George wants his bullets to be as large as possible, so there should
be no space between the circles. George will decide how large the whole revolver will be and how many bullets it shall contain. Your job is, given R and n, to compute r. You have decided to help, because you
know that an 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 < 1000 and contains up to at most two places after the decimal point) 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 will 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

求出两圆心与大圆圆心的夹角列方程求解即可

#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);
		double 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 (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

Mr Kopa Samsu is a farmer. He has a land of rectangular shape. But there are cows that disturb him a lot. The cows use to enter his land and ruin his crops. Now Mr Kopa Samsu has become smarter. He has a GPS system that will help him to know the position
of the cows. So, you can think his land as a 2D grid, and cows can be treated as points. Now you are given the information of his land and cows. You have to tell him whether a cow is inside his 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) is the lower left coordinate of his land and (x2, y2) is
the upper right coordinate of his land. You can assume that the sides of the land are axis parallel. The next line contains an integer M (1 ≤ M ≤ 100) denoting the number of cows. Each of the next M lines contains two integers
each denoting x y - the position of a cow. You can safely assume that no cow will lie on the boundary of the rectangle. All the coordinates will lie in the range [0, 10000].

Output

For each case you have to print the case number in a line first. Then for each cow, you have to print ‘Yes‘ or ‘No‘ depending whether the cow is 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);
		printf("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 (English) Statistics Forum
Time Limit: 0.5 second(s) Memory Limit: 32 MB

In the biological lab, you were examining some of the molecules. You got some interesting behavior about some of the molecules. There are some circular molecules, when two of them collide, they overlap with each other, and it‘s hard to find that which one
is over the other one.

Given two molecules as circles, you have to find the common area of the given molecules that 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 is
the radius and (x2, y2) is the center of the second molecule and r2 is the radius. Both the radiuses are positive. No integer will 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 will 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

两圆相交面积

#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));
	double 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);
		printf("Case %d: %.7lf\n",test++,area(x1,y1,r1,x2,y2,r2));
	}
	return 0;
}

1178 - Trapezium

   PDF (English) Statistics Forum
Time Limit: 0.5 second(s) Memory Limit: 32 MB

You are given the length of the four sides of a trapezium; you have to 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 that the given trapezium is valid. Each of the numbers will
be positive and not more than 200. 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 will be ignored.

Sample Input

Output for Sample Input


2

6 5 12 5.0

9 5 6 4


Case 1: 36

Case 2: 30.0000000

#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);
		double x=fabs(a-c);
		double p=(b+d+x)/2;
		double tarea=sqrt(p*(p-d)*(p-b)*(p-x));
		double h=tarea*2/x;
		printf("Case %d: %.7lf\n",test++,min(a,c)*h+tarea);
	}
	return 0;
}

1216 - Juice in the Glass

   PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

Once upon a time, there lived a mad programmer. He loved to solve creative problems other than anything. His wife loved him quite a lot but disliked his curiosity for the problems. One day he came from office, his wife gave him a glass of cold lime juice.
She was in a romantic mood and waiting for some romantic stuff. But the programmer asked her curiously, "If I give u radius of the top and bottom part of the glass and the height, can you come up with the volume of the glass?" His wife became a bit disappointed
but as she is smart she replied with a smile, "You already have drunk some juice, and the glass is not 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 his wife and said,
"You are the best problem setter in the world!"

Now he set 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 is p what is 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 will 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);
		double 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;
}
时间: 2024-08-29 15:37:12

lightoj1022&&1072&&1107&&1118&&1178&&1216【基础计算几何】的相关文章

poj1584 A Round Peg in a Ground Hole 判断多边形凹凸,点到线的距离【基础计算几何】

大致思路:首先对于所给的洞的点,判断是否是凸多边形,图形的输入和输出可以是顺时针或者逆时针,而且允许多点共线 Debug 了好几个小时,发现如下问题 判断三点是否共线,可用斜率公式判断 POINT point_A, point_B, point_C; if(point_A.x == point_B.x || point_B.x == point_C.x){ if(point_A.x == point_B.x && point_B.x == point_C.x) continue; }els

LightOJ 1062 - Crossed Ladders 基础计算几何

http://www.lightoj.com/volume_showproblem.php?problem=1062 题意:问两条平行边间的距离,给出从同一水平面出发的两条相交线段长,及它们交点到水平面的高. 思路:计算几何怎么可能直接算出答案orz解了好久方程觉得不对,应该是二分枚举平行边的距离,通过相似三角形,算出交点的高,与题目比较,小于误差范围就行了. /** @Date : 2016-12-10-18.18 * @Author : Lweleth ([email protected])

Kuangbin 带你飞-基础计算几何专题 题解

专题基本全都是模版应用.贴一下模版 const double eps = 1e-8; const int INF = 0x3f3f3f3f; int sgn(double x) { if (fabs(x) < eps) return 0; if (x < 0) return -1; return 1; } struct Point { double x,y; Point(){} Point(double tx,double ty) { x = tx; y = ty; } Point opera

基础计算几何

结构体的定义 struct point { double x, y; point(double _x, double _y):x(_x), y(_y){} // 点-点=向量 point operator-(const point &v){ return point(x-v.x, y-v.y); } }; int dcmp(double x){ if (fabs(x)<eps) return 0; else return x<0?-1:1; } bool operator == (co

计算几何及其应用——计算几何基础

写在前面:当时开计算几何这个专题神奇的从解析几何开始了,然后最近发现<计算几何及应用(金博)>这本书前面那章忽略掉了一些重要的东西比如说点定位.半平面相交之类的东西,恰好还有一些和计算几何扯上边但是不需要算法的简单题目没有整理,故在此开辟一块小空间. 我们再来看一道有关几何的问题.(Problem source:hdu2073)    数理分析:虽然这道题异常的简单,基本算不上计算几何这个专题当中的题目,但是把它拿到这里来,是源于这道简单几何题的思路其实体现了计算几何整个体系中比较重要的思维.

CG_Hadoop:基于MapReduce的计算几何

原作:Ahmed Eldawy:Mohamed F.Mokbel (UMN) 翻译:Leo(CAU) 注:由于本人翻译水平有限,如有错误,敬请谅解,可以在评论中指出,欢迎交流! 摘要:Hadoop使用了MapReduce编程范式,目前已经被公认为是分布式环境中分析大数据的标准框架.然而,它并不能很好的应用于大规模的计算几何处理.本文介绍的CG_Hadoop是一套可伸缩的和高效的MapReduce算法,用于处理各种基本计算几何问题,例如多边形合并.skyline(轮廓线).convex hull(

ZSTU我的编程之路

浙江理工大学我的编程之路答案 语言:C/C++ 推荐编译器:Dev-C++ / CodeBlocks 严禁直接复制提交 作弊行为将会被ACM校队禁止入队 作者:JokerNoCry 1000: 送分题-A+B Problem #include <iostream> using namespace std; int main (){ int a,b; cin>>a>>b; cout<<a+b; } 零基础学C/C++ oj 题目1001--1199 1001:

2017暑假集训前总结和规划

距离大一进来已经一年了啊,感觉还是啥也不会,哎,太差了,总结一下这一年都学了写什么吧! 大一寒假开始专题,刷过的有:dp,dfs和bfs,数论(gcd拓展gcd,欧拉定理等等,但是中国剩余定理没学,等复习的时候再学吧),并查集,最短路(bellman-fprd,dijkstra,floyd-warshall,spfa),最小生成树(prim,kruskal),线段树,二分三分 大一下学期有:拓扑排序,基础计算几何(直线线段相交,快速排除实验,跨立实验),矩阵快速幂,博弈基础(nim博弈,威佐夫博

学习,兴趣与娱乐

学习>兴趣>娱乐 排名应该就是这样了,但是总是控制不住我自己,从而变成了,娱乐>学习>兴趣(几乎没有) (一,手机问题),被手机消耗的时间极多,简直不可描述,自己都不知道自己在玩什么,所以我刚刚打开了qq浏览器,突然兴奋试试了qq浏览器的识别花的功能,然后看了一个新闻,然后看了一个笑话,,,,原来这就是手机的"正确"操作?我用手机好像并不是用来做这种事情的,正确姿势就是:一,联系父母和同学.二,学习英语,三,吃饭付款.四,收集图片存到微云里. 所以要控制自己玩手