zoukankan      html  css  js  c++  java
  • Project Eular 144

    这题...关键在于.....计算几何能力...

    atan2的用法应该是

    atan2(y,x)而不是(x,y)

    代码:

    #include<set>
    #include<map>
    #include<list>
    #include<queue>
    #include<stack>
    #include<string>
    #include<math.h>
    #include<time.h>
    #include<vector>
    #include<bitset>
    #include<memory>
    #include<utility>
    #include<fstream>
    #include<stdio.h>
    #include<sstream>
    #include<iostream>
    #include<stdlib.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    const double eps=1e-8;
    struct point
    {
        double x;
        double y;
        point (double xx=0,double yy=0)
        {
            x=xx;
            y=yy;
        }
        bool is_ans()
        {
            if (((-0.01<x)&&(x<0.01))&&(y>0))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        double el_k()
        {
            return -4*x/y;
        }
        friend point operator + (const point &a,const point &b)
        {
            return point(a.x+b.x,a.y+b.y);
        }
        friend point operator * (const point &a,double b)
        {
            return point (a.x*b,a.y*b);
        }
        friend point operator / (const point &a,double b)
        {
            return point (a.x/b,a.y/b);
        }
        double val()
        {
            return 4*x*x+y*y;
        }
        void go(point k)
        {
            point l=point(x,y)+k*0.1;
            point r=point(x,y)+k*100;
            point mid;
            int i;
            for (i=0;i<=1000;i++)
            {
                mid=(l+r)/2;
                if (mid.val()<100)
                {
                    l=mid;
                }
                else
                {
                    r=mid;
                }
            }
            x=mid.x;
            y=mid.y;
        }
    };
    int main()
    {
        point k=point(1.4,-(10.1+9.6));
        point now;
        now.x=1.4;
        now.y=-9.6;
        int ans=0;
        for (;;)
        {
            if (now.is_ans()) break;
            ans++;
            double kk=now.el_k();
            double t1=atan2(k.y,k.x);
            double t2=atan(kk);
            t1=t2*2-t1;
            k.x=cos(t1);
            k.y=sin(t1);
            now.go(k);
        }
        printf("%d
    ",ans);
        system("pause");
        return 0;
    }
    

      

  • 相关阅读:
    JSON的在javascript中的常用方法
    JUQERY判断变量是数组还是对象
    JS正则表达式大全
    jquery对事件的监听方法addEventListener()
    Hive安装(二)之表不见了
    Hive安装(一)之环境配置
    Java锁(一)之内存模型
    遗传算法(二)之组卷算法
    Ubuntu 14 Trusty安装hue
    算法(三)粒子群算法之算法分类
  • 原文地址:https://www.cnblogs.com/absi2011/p/9236196.html
Copyright © 2011-2022 走看看