hdu 3718 Different Division

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>

hdu 3718 Different Division,布布扣,bubuko.com

时间: 2024-08-07 14:41:13

hdu 3718 Different Division的相关文章

HDU 3718 Similarity(KM最大匹配)

HDU 3718 Similarity 题目链接 题意:给定一个标准答案字符串,然后下面每一行给一个串,要求把字符一种对应一种,要求匹配尽量多 思路:显然的KM最大匹配问题,位置对应的字符连边权值+1 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MAXNODE = 27; typede

【HDU】3480 Division

http://acm.hdu.edu.cn/showproblem.php?pid=3480 题意:一个n个元素的集合S要求分成m个子集且子集并为S,要求$\sum_{S_i} (MAX-MIN)^2$最小.(n<=10000, m<=5000) #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <iostream>

KM HDU 3718

1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 7 #define MAXN 50 8 #define inf 65553566 9 int love[MAXN][MAXN]; /// 记录每个妹子和每个男生的好感度 10 int ex_girl[MAXN]; /// 每个妹子的期望值 11

HDU 5845 Best Division

dp,字典树. dp递推式很容易知道.dp[i]=max{dp[j]+1} a[j]^..^a[i]<=X,并且[j,i]长度不能超过L. 但是暴力来复杂度极高,所以需要用字典树维护这个东西.将前缀异或和插入到字典树中,然后不断维护a[i]位置之前L个前缀异或和就好了. 跑了405ms,第一次排到第一,有点激动~~~ #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #in

【图论】二分图匹配总结

二分图匹配总结 二分图匹配 1.二分图最大匹配.求两个集合内,每一个元素仅仅能用一次.两集合间存在一些匹配关系,求最大匹配多少对,利用匈牙利算法,对于每一个结点不断去找增广路去匹配 有几个重要性质: 1.最小点覆盖 = 最大匹配 2.最大独立集 = 总结点 - 最大匹配 模板: bool dfs(int u) { for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (vis[v]) continue; vis[v] = 1; i

HDU 3130 Sir Bedavere’s Bogus Division Solutions(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3130 Problem Description The wise Sir Bedavere often uses non-standard logic, yet achieves positive results1.Well, it seems he has been at it again, this time with division. He has determined that cancel

hdu 3480 Division (斜率优化)

Division Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 999999/400000 K (Java/Others) Total Submission(s): 2676    Accepted Submission(s): 1056 Problem Description Little D is really interested in the theorem of sets recently. There's a pro

HDU 6036 Division Game

HDU 6036 Division Game 考虑每堆石头最多操作 $ \sum e $ 次,考虑设 $ f(x) $ 表示某一堆石头(最开始都是一样的)操作 $ x $ 次后变成了 $ 1 $ 的方案数量. 明显的,某一堆石头操作了 $ x $ 次后仍然没有变成 $ 1 $ 的方案数量是 $ f(x+1) $.因为最后一次操作必然是把石头从某个数字拿到1.(这个算个小trick吧?) 那么对于第 \(k\) 堆石头答案就是 $ f^{k-1}(x+1) f^{m-i+1}(x) $ 因为前 $

hdu 2615 Division(暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2615 题解:挺简单的暴力枚举,小小的分治主要是看没人写题解就稍微写一下 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; typedef long long ll; ll a[123] , ans , sum[123