麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

NYOJ3—多邊形重心問題(計(jì)算幾何)&&hdu1115 Lifting the Stone

2019-11-14 08:44:49
字體:
供稿:網(wǎng)友

多邊形重心問題

時(shí)間限制:3000 ms  |  內(nèi)存限制:65535 KB難度:5描述在某個(gè)多邊形上,取n個(gè)點(diǎn),這n個(gè)點(diǎn)順序給出,按照給出順序?qū)⑾噜彽狞c(diǎn)用直線連接, (第一個(gè)和最后一個(gè)連接),所有線段不和其他線段相交,但是可以重合,可得到一個(gè)多邊形或一條線段或一個(gè)多邊形和一個(gè)線段的連接后的圖形; 如果是一條線段,我們定義面積為0,重心坐標(biāo)為(0,0).現(xiàn)在求給出的點(diǎn)集組成的圖形的面積和重心橫縱坐標(biāo)的和;輸入第一行有一個(gè)整數(shù)0<n<11,表示有n組數(shù)據(jù);每組數(shù)據(jù)第一行有一個(gè)整數(shù)m<10000,表示有這個(gè)多邊形有m個(gè)頂點(diǎn);輸出輸出每個(gè)多邊形的面積、重心橫縱坐標(biāo)的和,小數(shù)點(diǎn)后保留三位;樣例輸入
330 10 20 331 10 00 141 10 00 0.50 1樣例輸出
0.000 0.0000.500 1.0000.500 1.000
#include<cstdio>int cases,n;double a[10002],b[10002],t,xx,yy,area;inline double fun(int i){	return (a[i]*b[i+1]-a[i+1]*b[i])/2;}inline double ffabs(double i){	return i>0?i:-i;}int main(){	scanf("%d",&cases);	while(cases--){		xx=yy=area=0;		scanf("%d",&n);		for(int i=1;i<=n;i++)		scanf("%lf%lf",&a[i],&b[i]);		a[n+1]=a[1],b[n+1]=b[1];		for(int i=1;i<=n;i++){			t=fun(i);			area+=t;			xx+=t*(a[i]+a[i+1]);			yy+=t*(b[i]+b[i+1]);		}	xx=xx/3/area;	yy=yy/3/area;	area=ffabs(area);	if(area<1e-8)	PRintf("0.000 0.000/n");	else	printf("%.3lf %.3lf/n",area,xx+yy);}return 0;}

*①質(zhì)量集中在頂點(diǎn)上* n個(gè)頂點(diǎn)坐標(biāo)為(xi,yi),質(zhì)量為mi,則重心* X = ∑( xi×mi ) / ∑mi* Y = ∑( yi×mi ) / ∑mi* 特殊地,若每個(gè)點(diǎn)的質(zhì)量相同,則* X = ∑xi / n* Y = ∑yi / n*②質(zhì)量分布均勻* 特殊地,質(zhì)量均勻的三角形重心:* X = ( x0 + x1 + x2 ) / 3* Y = ( y0 + y1 + y2 ) / 3*③三角形面積公式:S = ( (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) ) / 2 ;*做題步驟:1、將多邊形分割成n-2個(gè)三角形,根據(jù)③公式求每個(gè)三角形面積。* 2、根據(jù)②求每個(gè)三角形重心。* 3、根據(jù)①求得多邊形重心。**/

兩種方法:

一種是將n個(gè)點(diǎn),以其中一個(gè)點(diǎn)為標(biāo)準(zhǔn),分成n-2個(gè)三角形,再進(jìn)行求重心。

另一種是以原點(diǎn)為依據(jù)分成n+1個(gè)三角形,再進(jìn)行求重心。

Lifting the Stone

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7885    Accepted Submission(s): 3331Problem DescriptionThere are many secret openings in the floor which are covered by a big heavy stone. When the stone is lifted up, a special mechanism detects this and activates poisoned arrows that are shot near the opening. The only possibility is to lift the stone very slowly and carefully. The ACM team must connect a rope to the stone and then lift it using a pulley. Moreover, the stone must be lifted all at once; no side can rise before another. So it is very important to find the centre of gravity and connect the rope exactly to that point. The stone has a polygonal shape and its height is the same throughout the whole polygonal area. Your task is to find the centre of gravity for the given polygon.  InputThe input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer N (3 <= N <= 1000000) indicating the number of points that form the polygon. This is followed by N lines, each containing two integers Xi and Yi (|Xi|, |Yi| <= 20000). These numbers are the coordinates of the i-th point. When we connect the points in the given order, we get a polygon. You may assume that the edges never touch each other (except the neighboring ones) and that they never cross. The area of the polygon is never zero, i.e. it cannot collapse into a single line.  OutputPrint exactly one line for each test case. The line should contain exactly two numbers separated by one space. These numbers are the coordinates of the centre of gravity. Round the coordinates to the nearest number with exactly two digits after the decimal point (0.005 rounds up to 0.01). Note that the centre of gravity may be outside the polygon, if its shape is not convex. If there is such a case in the input data, print the centre anyway.  Sample Input
245 00 5-5 00 -541 111 111 111 11 Sample Output
0.00 0.006.00 6.00 SourceCentral Europe 1999
#include<cstdio>int cases,n;double a[10002],b[10002],t,xx,yy,area;inline double fun(int i){	return (a[i]*b[i+1]-a[i+1]*b[i])/2;}inline double ffabs(double i){	return i>0?i:-i;}int main(){	scanf("%d",&cases);	while(cases--){		xx=yy=area=0;		scanf("%d",&n);		for(int i=1;i<=n;i++)		scanf("%lf%lf",&a[i],&b[i]);		a[n+1]=a[1],b[n+1]=b[1];		for(int i=1;i<=n;i++){			t=fun(i);			area+=t;			xx+=t*(a[i]+a[i+1]);			yy+=t*(b[i]+b[i+1]);		}	xx=xx/3/area;	yy=yy/3/area;	printf("%.2lf %.2lf/n",xx,yy);}return 0;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 成人在线视频免费看 | 色操网| 国产流白浆高潮在线观看 | 久久久久夜色精品国产老牛91 | 欧美性生交zzzzzxxxxx | 国产亚洲精彩视频 | 国产亚洲精品久久久久婷婷瑜伽 | 国产亚洲欧美视频 | 国产99久久久国产精品下药 | 精品一区二区久久久久 | 天天色宗合 | 成人在线视频免费看 | 成人午夜看片 | 国产精品美女久久久久久不卡 | 精品一区二区三区日本 | 91嫩草丨国产丨精品入口 | caoporn国产一区二区 | 免费国产精品视频 | 亚洲欧洲av在线 | av91肉丝一区二区电影 | 国产资源在线免费观看 | 亚洲婷婷日日综合婷婷噜噜噜 | 亚洲精品免费播放 | 新久草在线视频 | 久久免费视频1 | 免费一级毛片在线播放视频 | www久| 久久久久久久久久性 | 亚洲欧美aⅴ| 天堂精品| 中文字幕观看 | 草草视频免费 | 天天舔夜夜操 | 暴力强行进如hdxxx | 中文字幕在线网站 | 在线播放一区二区三区 | 精品国产乱码久久久久久久久 | 欧美aaaaaaaa| 欧美 亚洲 视频 | 日韩免费黄色 | 空姐一级毛片 |