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;
    }
    

      

  • 相关阅读:
    笔记3
    笔记
    指令操作、例子
    python文件操作
    pandas处理excel
    Flask资源
    ImportError: DLL load failed while importing _ssl: 找不到指定的模块。 Failed
    WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    selenium 安装与 chromedriver安装
    ubuntu 更换清华源
  • 原文地址:https://www.cnblogs.com/absi2011/p/9236196.html
Copyright © 2011-2022 走看看