zoukankan      html  css  js  c++  java
  • hoj 13781 Wedding Selfie

    #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
    ",(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
    ",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
    ",theta);
            printf("Case %d:
    ",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;
    }
    

      学姐的代码我又打了一遍 比我的短一倍而且少了许多特判 代码写的好就是能规避很多需要特判的地方

  • 相关阅读:
    [BZOJ3398] [Usaco2009 Feb]Bullcow 牡牛和牝牛(动态规划)
    [BZOJ3399] [Usaco2009 Mar]Sand Castle城堡(排序)
    [VIJOS1003] 等价表达式(表达式解析)
    [BZOJ4690] Never Wait for Weights(并查集)
    sql server 查出数据库表结构
    sql server 时间日期转换
    LINQ语法详解
    方法练习题
    数组练习题
    第四章 JAVA数组知识点
  • 原文地址:https://www.cnblogs.com/MeowMeowMeow/p/7277001.html
Copyright © 2011-2022 走看看