• 《信息学奥赛一本通》题库 1034 计算三角形面积——基础


    开始复健。

    用了不方便的算面积的方法,讨论了好多,还调了一个多小时- -

    发现 double 和 longdouble 的四舍五入是随机的,有时候舍5有时候入5。

    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    long double x[3],y[3],x2,y2,tx,ty,dc;
    double ans;
    int bj=-1;
    bool fx;
    int main()
    {
      for(int i=0;i<3;i++)
        scanf("%Lf%Lf",&x[i],&y[i]);
      for(int i=0;i<3;i++)
        {
          int d=i+1; if(d==3)d=0;
          /*printf("i=%d d=%d (%.1Lf,%.1Lf) (%.1Lf,%.1Lf)
    ",
        i,d,x[i],y[i],x[d],y[d]);*/
          x2=x[i]-x[d]; if(x2<0)x2=-x2;
          y2=y[i]-y[d]; if(y2<0)y2=-y2;
          dc+=x2*y2;
          /*printf("  x1=%.1Lf y1=%.1Lf dc=%.1Lf
    ",x2,y2,dc);
        printf("  tx=%.1Lf ty=%.1Lf
    ",tx,ty);*/
          if(i==0)tx=x2,ty=y2,bj=2,fx=1;
          else
        {
          if(x2>tx&&y2>ty)
            {
              bj=(i+2)%3; fx=1; tx=x2; ty=y2;
            }
          if(x2>tx)tx=x2,fx=0; if(y2>ty)ty=y2,fx=0;
          //printf("i=%d d=%d fx=%d
    ",i,d,fx);
        }
        }
      dc/=2;
      //printf("bj=%d fx=%d
    ",bj,fx);
      if(bj!=-1&&fx)
        {
          double tmp=0;
          /*for(int i=0;i<3;i++)
        {
          printf("x[%d]=%.2Lf y[%d]=%.2Lf
    ",
             i,x[i],i,y[i]);
        }
        printf("bj=%d
    ",bj);*/
          if(bj!=1)
        {
          swap(x[bj],x[1]); swap(y[bj],y[1]);
        }
          /*for(int i=0;i<3;i++)
        {
          printf("x[%d]=%.2Lf y[%d]=%.2Lf
    ",
             i,x[i],i,y[i]);
             }*/
          if((x[0]-x[2])*(y[0]-y[2])>=0)
        {
          if((y[0]-y[1])/(x[0]-x[1])<(y[0]-y[2])/(x[0]-x[2]))
            tmp=abs((x[1]-x[2])*(y[0]-y[1]));
          else tmp=abs((x[0]-x[1])*(y[1]-y[2]));
        }
          else
        {
          if((y[0]-y[1])/(x[0]-x[1])<(y[0]-y[2])/(x[0]-x[2]))
            tmp=abs((x[0]-x[1])*(y[1]-y[2]));
          else tmp=abs((x[1]-x[2])*(y[0]-y[1]));
        }
          dc+=tmp;
        }
      //printf("tx=%.1Lf ty=%.1Lf
    ",tx,ty);
      ans=tx*ty-dc;
      /*for(int i=0;i<3;i++)
        {
          int d=i+1; if(d==3)d=0;
          long double px=x[i]-x[d]; if(px<0)px=-px;
          long double py=y[i]-y[d]; if(py<0)py=-py;
          if(tx<px||ty<py)
        {
          printf("NO
    ");
          printf("x1=%Lf y1=%Lf px=%Lf py=%Lf
    ",
             x1,y1,px,py);
          return 0;
        }
        }
        printf("YES
    ");*/
      int d=floor(ans*1000); d%=10;
      if(d==5)ans+=0.001;
      printf("%.2lf
    ",ans);
      return 0;
    }
    View Code
    #include<cstdio>
    #include<ctime>
    #include<algorithm>
    using namespace std;
    int a,b; double c,d;
    int main()
    {
      srand(time(0));
      for(int i=0;i<3;i++)
        {
          a=rand()%100; b=rand()%100;
          c=(double)a/10; d=(double)b/10;
          printf("%lf %lf",c,d);
          if(i!=2)putchar(' '); else putchar('
    ');
        }
      return 0;
    }
    mk
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int cnt;
    int main()
    {
      while(1)
        {
          cnt++; printf("cnt=%d
    ",cnt);
          system("./mk > 1.in");
          system("./a < 1.in > zj.out");
          system("./TJ < 1.in > TJ.out");
          if(system("diff zj.out TJ.out"))break;
          if(cnt==1000)break;
        }
      return 0;
    }
    dp
  • 相关阅读:
    vue下使用echarts折线图及其横坐标拖拽功能
    vue下登录页背景图上下空白处自适应等高
    前端面试总结下~
    在C#中使用科大讯飞Web API进行语音合成
    C# Socket 发送&接收&返回
    AutoMapper在C#中的有趣应用
    RabbitMQ 在 C# 中简单应用
    .Net Core 读取配置文件
    C# / .Net Core 访问MongoDb库
    C#发送GET与POST请求
  • 原文地址:https://www.cnblogs.com/Narh/p/13326578.html
Copyright © 2020-2023  润新知