ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

hdu 3718 Different Division

2019-05-03 16:53:41  阅读:227  来源: 互联网

标签:Division hdu point 3718 CD points each line side


Different Division

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 234    Accepted Submission(s): 90

Problem Description Now we will give you a graph, there are many points in the graph. We will choose two different points arbitrarily, and connect them as a line. Please tell us that whether these points (Include the two points referred above) is on the left side of the line, or lying on the line. or on the right side of the line. For example,

There are four points in the graph: A, B, C, D. we connect C and D. Now C and D form a new line “CD”. Obviously, C and D are lying on the line “CD”. A is on the right side of CD, and B is on the left side of CD. What’s more, A is on the left side of line DC, and B is on the right side of line DC. So line “CD” and “DC” are different in this problem;
 
Input The first line of input is a single integer T, indicating the number of test cases. Then exactly T test cases followed. In each case, the first line contains one integer: N, the number of points. Then N lines followed, each line contains two real numbers X, Y, indicating the coordinates of points. Then one line follows, contains two integers P1 and P2 indicate the P1th point and the P2th point in this case.
1<= T <= 100
2 <= N <= 1000
1<= P1, P2 <= N, P1 != P2
-1000 < X, Y < 1000;
 
Output For each case, print N lines. According to the order of input, for each point print “Left” if this point is on the left side of line P1P2 , or ”On” if this point is lying on line P1P2 , or ”Right” if this is on the right side of line P1P2.  
Sample Input
1
4
1 1 
1 2 
3 3 
2 1 
1 3

 

Sample Output
On
Left
On
Right

 
思路:叉积
<span style="font-size:18px;">#include <cstdio>
#include <iostream>
using namespace std;
#define N 1005
double a[N],b[N];

int main()
{
	int t;
	double x1,x2,y1,y2,sum;
	scanf("%d",&t);
	while(t--)
	{
		int n,i;
		scanf("%d",&n);
		for(i = 1; i <= n; i++)
			scanf("%lf%lf",&a[i],&b[i]);
		int p1,p2;
        scanf("%d%d",&p1,&p2);
		
		 x1 = a[p2] - a[p1];
		 y1 = b[p2] - b[p1];
		
		for(i=1; i<=n; i++)
		{
			 x2 = a[i] - a[p1];
			 y2 = b[i] - b[p1];

		    sum = x1*y2 - x2*y1;
			if(sum < 0)
				printf("Right\n");
			else if(sum > 0)
				printf("Left\n");
			else printf("On\n");
        }
	}
	return 0;
}</span>


标签:Division,hdu,point,3718,CD,points,each,line,side
来源: https://www.cnblogs.com/ldxsuanfa/p/10805552.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有