zoukankan      html  css  js  c++  java
  • BC之Run

    Problem Description
    AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and AFA will start his runing in a chair and end in this chair.Between two chairs,she running in a line.she want the the trace can be a regular triangle or a square or a regular pentagon or a regular hexagon.
    Please tell her how many ways can her find.
    Two ways are same if the set of chair that they contains are same.
     
    
    Input
    There are multiply case.
    In each case,there is a integer n(1 < = n < = 20)in a line.
    In next n lines,there are two integers xi,yi(0 < = xi,yi < 9) in each line.
     
    
    Output
    Output the number of ways.
     
    
    Sample Input
    
    4
    0 0
    0 1
    1 0
    1 1
    
    Sample Output
    
    1
    
    Source
    BestCoder Round #50 (div.2)
     
    Recommend
    hujie   |   We have carefully selected several similar problems for you:  5368 5367 5362 5361 5360 
     
    官方题解:
    地球人都知道整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可。假如你不是地球人,那么即使暴力枚举正三边形和稍微不那么暴力地找正五边形和正六边形也是可以通过的(反正找不到)。
    
    地球人都知道,我当时尽然猪脑子的没怎么注意这点,各种几何,各种优化,之后原来竟然酱紫......
    
    

    反证法:假设存在坐标平面上的三个整点,组成了正三角形 则将其平移,将其一个顶点与坐标原点重合,则另两个顶点仍然是整点 设一个非原点的顶点M坐标为(a,b) ,另一个顶点为N(c,d), a、b、c、d都是整数

    则MO的斜率=,倾斜角=arctan() 则NO的倾斜角=arctan()+

    NO的斜率=

    因为a、b不全等于0,所以c和d至少有一个是无理数 这和c、d都是整数矛盾 所以坐标平面上的三个整点,一定不能组成正三角形

    至于正五边形和正六边形,就交给你们自己去证明了。

    判断正方形: 用一个数组用于保存四个点之间的距离,求出两两点之间的距离,若数组不存在所求的距离数值,则添加进数组,若数组超过三个数值,则返回FALSE,否则返回true(其实只要两个就行了,不用距离平方比为1/2,自己举例证明...) 也可以直接算出6个点之间的距离,排下序,前四个相同后两个相同就是正方形....
    #include<cstdio>
    #include<cmath>
    #include<stdlib.h>
    #include<map>
    #include<set>
    #include<time.h>
    #include<vector>
    #include<queue>
    #include<string>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define LL long long
    #define rd(a) scanf("%d",&a)
    #define rdLL(a) scanf("%I64d",&a)
    #define rdd(a,b) scanf("%d%d",&a,&b)
    #define max(a,b) ((a)>(b)?(a):(b))
    #define min(a,b) ((a)<(b)?(a):(b))
    #define MOD 1000000007
    #define mem0(a) memset(a,0,sizeof(a))
    #define mem1(a) memset(a,1,sizeof(a))
    typedef pair<int , int> P;
    
    int x[25],y[25];
    
    double getdis(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
    }
    
    int judge(int temp[]){///判断是不是正方形
     int dis[3], coun=0;
     for(int xx=0;xx<4;xx++)
        for(int yy=xx+1;yy<4;yy++){
           int distmp = getdis(x[ temp[xx] ],y[  temp[xx]  ],x[  temp[yy]  ],y[ temp[yy]  ]);
           if(coun==0) dis[coun++]= distmp;
           else if(coun==1)
                {
                  if(distmp!=dis[0])
                   dis[coun++] = distmp;
                }
           else if(distmp != dis[0] && distmp != dis[1]) return false;
        }
        return true;
    }
    
    int main()
    {
        int n;
        while(~rd(n)){
            for(int i=0;i<n;i++)
                rdd(x[i],y[i]);
            int coun = 0;
            for(int i=0;i<n;i++)
              for(int j=i+1;j<n;j++)
                 for(int k = j+1;k<n ; k++)
                   for(int l = k+1 ; l<n ; l++){
                    int temp[4]={i,j,k,l};
                    if(judge(temp)) coun++;
                 }
            printf("%d
    ",coun);
        }
     return 0;
    }

  • 相关阅读:
    Core上传图片
    Pytho学习(3)——注释
    zabbix实操随笔
    1900型USB接口扫描枪设置虚拟串口模式提升扫描速度
    SQLServer设置单用户
    入门安装环境
    centos下载
    java学习资料
    错误模块名称: KERNELBASE.dll
    iis部署WebService出现"因 URL 意外地以 结束,请求格式无法识别"的解决方法
  • 原文地址:https://www.cnblogs.com/zswbky/p/5431932.html
Copyright © 2011-2022 走看看