zoukankan      html  css  js  c++  java
  • 三点顺序_nyoj_68(计算几何).java

    三点顺序

    时间限制: 1000 ms  |  内存限制: 65535 KB
    难度: 3
     
    描述

    现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给出的还是逆时针给出的?

    如:

    图1:顺时针给出

    图2:逆时针给出 

     

            <图1>                   <图2>

     
    输入
    每行是一组测试数据,有6个整数x1,y1,x2,y2,x3,y3分别表示A,B,C三个点的横纵坐标。(坐标值都在0到10000之间)
    输入0 0 0 0 0 0表示输入结束
    测试数据不超过10000组
    输出
    如果这三个点是顺时针给出的,请输出1,逆时针给出则输出0
    样例输入
    0 0 1 1 1 3
    0 1 1 0 0 0
    0 0 0 0 0 0
    样例输出
    0
    1
    来源
    计算几何基础
    import java.util.Scanner;
    
    public class Main{
    	public static void main(String[] args) {
    		Scanner input=new Scanner(System.in);
    		while(true){
    			Point f[]=new Point[3];
    			boolean ok=true;
    			for(int i=0;i<3;i++){
    				int a=input.nextInt();
    				int b=input.nextInt();
    				if(a!=0||b!=0)
    					ok=false;
    				f[i]=new Point(a,b);
    			}
    			if(ok)
    				break;
    			Point a1=new Point(f[1].x-f[0].x,f[1].y-f[0].y);//向量AB
    			Point b1=new Point(f[2].x-f[1].x,f[2].y-f[1].y);//向量BC
    			int ans=a1.x*b1.y-b1.x*a1.y;//向量的叉乘
    			if(ans<0)
    				System.out.println(1);
    			else
    				System.out.println(0);
    		}
    	}
    }
    class Point{
    	int x,y;
    	Point(int x,int y){
    		this.x=x;
    		this.y=y;
    	}
    }


  • 相关阅读:
    C语言I博客作业04
    C语言I博客作业03
    C语言1博客作业02
    作业1
    C语言||作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    笔记本
  • 原文地址:https://www.cnblogs.com/riskyer/p/3253552.html
Copyright © 2011-2022 走看看