zoukankan      html  css  js  c++  java
  • 【水】tyvj1523 平面几何入门

    大意:给出三角形的三个顶点,求点X在其的内外还是边界上。

    入门题,看程序吧。

    program p1523;
    
    type
     point=record
       x,y:double;
     end;
     vector=point;
    
    Var
     a,b,c,x:point;
     ans:longint;
    
    procedure readpoint(var p:point);
    var
     s:string;
     code:longint;
      begin
      readln(s);
      val(copy(s,2,pos(',',s)-2),p.x,code);
      val(copy(s,pos(',',s)+1,length(s)-pos(',',s)-1),p.y,code);
      //writeln('(',p.x,',',p.y,')');
    end;
    
    function minus(a,b:point):vector;begin with minus do begin x:=a.x-b.x;y:=a.y-b.y; end; end;
    function max(a,b:double):double;begin if a>b then exit(a);exit(b); end;
    function min(a,b:double):double;begin if a<b then exit(a);exit(b); end;
    procedure getans(P:longint);begin if ans=0 then ans:=p; end;
    function cross(a,b:vector):double;begin exit(a.x*b.y-a.y*b.x); end;
    function pinline(p,a,b:point):boolean;begin exit((p.x>=min(a.x,b.x)) and (p.x<=max(a.x,b.x))); end;
    function equal(a,b:vector):boolean;begin exit((a.x=b.x) and (a.y=b.y)); end;
    
      begin
      readpoint(a);
      readpoint(b);
      readpoint(c);
      readpoint(x);
      ans:=0;
      if equal(x,a) or equal(x,b) or equal(x,c) then getans(4);
      if cross(minus(b,a),minus(x,a))=0 then
        if Pinline(x,a,b) then getans(3) else getans(2);
      if cross(minus(c,a),minus(x,a))=0 then
        if Pinline(x,a,c) then getans(3) else getans(2);
      if cross(minus(c,b),minus(x,b))=0 then
        if Pinline(x,b,c) then getans(3) else getans(2);
      if (cross(minus(b,a),minus(x,a))*cross(minus(b,a),minus(c,a))>0) and (cross(minus(c,a),minus(x,a))*cross(minus(c,a),minus(b,a))>0) and (cross(minus(c,b),minus(x,b))*cross(minus(c,b),minus(a,b))>0) then getans(1) else getans(2);
      writeln(ans);
    
    end.
    
  • 相关阅读:
    JSP显示新闻
    servlet应用
    J2EE_第二次作业_登陆页面
    J2EE第一次作业
    软工最后一次作业
    第三次作业(赵清和李靖)
    第二次作业
    第一次作业
    分布式系统架构之构建你的任务调度中心
    【原创】新零售の从单体系统向微服务演变历程(一)
  • 原文地址:https://www.cnblogs.com/htfy/p/3065553.html
Copyright © 2011-2022 走看看