计算几何 hihocoder 1183 Integral
来源:互联网 发布:laravel nginx伪静态 编辑:程序博客网 时间:2024/06/05 10:16
转换成求多边形的面积和重心.....
#include <iostream>#include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 200005#define maxm 2000005#define eps 1e-10#define mod 1000000007#define INF 0x3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R#define pii pair<int, int>//#pragma comment(linker, "/STACK:16777216")typedef long long LL;typedef unsigned long long ULL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}// headint sgn(double x){if(fabs(x) < eps) return 0;if(x < 0) return -1;else return 1;}struct Point{double x, y;Point() {}Point(double _x, double _y) {x = _x;y = _y;}bool operator == (Point b) const {return sgn(x - b.x) == 0 ? sgn(y - b.y) < 0 : x < b.x;}bool operator < (Point b) const {return sgn(x - b.x) == 0 ? sgn(y - b.y) < 0 : x < b.x;}Point operator - (const Point& b) const {return Point(x - b.x, y - b.y);}double operator ^ (const Point& b) const{return x * b.y - y * b.x;}double operator * (const Point& b) const {return x * b.x + y * b.y;}Point operator + (const Point& b) const {return Point(x + b.x, y + b.y);}Point operator * (const double& k) const {return Point(x * k, y * k);}Point operator / (const double& k) const {return Point(x / k, y / k);}void input(void){scanf("%lf%lf", &x, &y);}};struct Line{Point s, e;Line() {}Line(Point _s, Point _e) {s = _s;e = _e;}};struct polygon{int n;Point p[maxn];Line l[maxn];void input(int _n){n = _n;for(int i = 0; i < n; i++)p[i].input();}void getline(){for(int i = 0; i < n; i++)l[i] = Line(p[i], p[(i+1) % n]);}Point getbarycentre(){Point ret(0, 0);double area = 0;for(int i = 1; i < n-1; i++) {double tmp = (p[i] - p[0]) ^ (p[i+1] - p[0]);area += tmp;ret.x += (p[0].x + p[i].x + p[i+1].x) / 3 * tmp;ret.y += (p[0].y + p[i].y + p[i+1].y) / 3 * tmp;}if(sgn(area)) ret = ret / area;return ret;}double getarea(){double sum = 0;for(int i = 0; i < n; i++) {sum += (p[i] ^ p[(i+1) % n]);}return fabs(sum) / 2;}}t;Point ans;void work(void){int n;scanf("%d", &n);t.input(n);t.getline();ans = t.getbarycentre();double res = (ans.x + ans.y) * t.getarea();printf("%.2f\n", res);}int main(void){int _;while(scanf("%d", &_)!=EOF) {while(_--) {work();}}return 0;}
0 0
- 计算几何 hihocoder 1183 Integral
- hihoCoder 1064 时间结界 计算几何
- hihoCoder 1040 : 矩形判断 计算几何
- hihoCoder - 1040 - 矩形判断 (简单计算几何~)
- Opencv中integral计算积分图
- [Offer收割]编程练习赛2 hihocoder 1275 扫地机器人 (计算几何+模拟 比较烦)
- hihocoder 1582 : Territorial Dispute (计算几何 凸包)(2017 北京网络赛E)
- 计算几何几何函数库
- 计算几何-几何库
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- tokumx的安装和使用
- 武新:新型MPP数据库将支撑起大数据时代
- 版本控制软件的发展史
- svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
- 16周项目2--字符串(数组名作形参)
- 计算几何 hihocoder 1183 Integral
- Excel操作——使用Com操作和NPOI操作
- Android:SpannableString属性详解
- 为什么要学习操作系统课程?
- 判断SD卡是否存在
- C++写cgi 获取网页ur问号后的内容
- 第16周【项目 2-用指针玩字符串】⑤
- 第十六周项目二(1)字符串连接(数组名形参)
- ajax 表单提交技巧