hoj 13781 Wedding Sel?e
Posted MeowMeowMeow
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hoj 13781 Wedding Sel?e相关的知识,希望对你有一定的参考价值。
#include <iostream> #include <algorithm> #include <stdio.h> #include <queue> #include <limits.h> #include <string.h> #include <vector> #include <map> #include <math.h> #define LL unsigned long long #define INF 2100000000 #define fi first #define se second #define lowbit(x) (x&(-x)) #define eps 5e-7 using namespace std; const int maxn=(int)1e2 +30; const int MOD=(int)1e9+10; const double PI=acos(-1.0) ; int sgn(double x){return (x>eps)-(x<-eps);} template<class T>inline void MAX(T &a,T b){if(a<b)a=b;} template<class T>inline void MIN(T &a,T b){if(a>b)a=b;} struct point { double x,y; point(){} point(double x,double y):x(x),y(y){} void input(){scanf("%lf%lf",&x,&y);} void output(){printf("%.6lf %.6lf\n",(sgn(x)==0)? 0.0:x,(sgn(y)==0)? 0.0:y); } point rotate(double a){return point(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a));} //应创立新的点而不是在原有点上更改****important }; point p[maxn]; double area(point &a,point &b,point &c){ return fabs(0.5*(a.x*b.y+a.y*c.x+b.x*c.y-b.y*c.x-a.y*b.x-a.x*c.y)); } double angle(point &a,point &b){ return -atan2(a.y-b.y,a.x-b.x);// atan2定义很棒 } double ar[maxn]; int main(){ #ifdef shuaishuai freopen("C:\\Users\\hasee\\Desktop\\a.txt","r",stdin); //freopen("C:\\Users\\hasee\\Desktop\\b.txt","w",stdout); #endif int t,kas=1; int n; scanf("%d",&t); while(t--){ scanf("%d",&n); p[0].input();p[1].input(); ar[0]=ar[1]=0.0; for(int i=2;i<n;i++){ p[i].input(); ar[i]=ar[i-1]+area(p[i],p[i-1],p[0]); } double tot=ar[n-1]; int mid=2; while(mid<n&&ar[mid]*2.0<tot)mid++; // printf("mid :%d\n",mid); double arl=tot*0.5-ar[mid-1 ]; point L=p[mid-1],R=p[mid]; double l=arl/(ar[mid]-ar[mid-1]); point m; m.x=L.x+l*(R.x-L.x);m.y=L.y+l*(R.y-L.y); double theta=angle(m,p[0])-0.5*PI; //-0.5PI就是旋转到Y负的角度 // m.output(); // printf("theta :%.3lf\n",theta); printf("Case %d:\n",kas);kas++; // for(int i=0;i<n;i++)p[i].output(); for(int i=0;i<n;i++){ (p[i].rotate(theta)).output(); } } return 0; }
学姐的代码我又打了一遍 比我的短一倍而且少了许多特判 代码写的好就是能规避很多需要特判的地方
以上是关于hoj 13781 Wedding Sel?e的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp HOJ - 302:最大平均值[AC]; http://hoj.twbbs.org/judge/judge/submission/21872