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的更多相关文章

  1. HDU 3718 Similarity(KM最大匹配)

    HDU 3718 Similarity 题目链接 题意:给定一个标准答案字符串,然后以下每一行给一个串.要求把字符一种相应一种,要求匹配尽量多 思路:显然的KM最大匹配问题,位置相应的字符连边权值+1 ...

  2. 【HDU】3480 Division

    http://acm.hdu.edu.cn/showproblem.php?pid=3480 题意:一个n个元素的集合S要求分成m个子集且子集并为S,要求$\sum_{S_i} (MAX-MIN)^2 ...

  3. 【HDU 6036】Division Game (NTT+数学)

    多校1 1004 HDU-6036 Division Game 题意 有k堆石头(0~k-1),每堆n个.\(n=\prod_{i=0}^{m}p_i^{e_i}\).\(0\le m,k \le 1 ...

  4. hdu 3718

    一个二分图最大匹配的题: 匈牙利算法不熟: 建了个模,用最小费用最大流解决了 #include <iostream> #include <cstring> #define IN ...

  5. HDU 5845 Best Division

    $dp$,字典树. $dp$递推式很容易知道.dp[i]=max{dp[j]+1} a[j]^..^a[i]<=X,并且$[j,i]$长度不能超过$L$. 但是暴力来复杂度极高,所以需要用字典树 ...

  6. KM HDU 3718

    #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...

  7. hdu 3480 Division(斜率优化DP)

    题目链接:hdu 3480 Division 题意: 给你一个有n个数的集合S,现在让你选出m个子集合,使这m个子集合并起来为S,并且每个集合的(max-min)2 之和要最小. 题解: 运用贪心的思 ...

  8. HDU 6036 - Division Game | 2017 Multi-University Training Contest 1

    /* HDU 6036 - Division Game [ 组合数学,NTT ] | 2017 Multi-University Training Contest 1 题意: k堆石子围成一个圈,数量 ...

  9. HDU 6036 Division Game

    HDU 6036 Division Game 考虑每堆石头最多操作 $ \sum e $ 次,考虑设 $ f(x) $ 表示某一堆石头(最开始都是一样的)操作 $ x $ 次后变成了 $ 1 $ 的方 ...

随机推荐

  1. iOS uitableivewCell 下划线顶格

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath ...

  2. 标准库Allocator的使用(一)

    上一篇我们提到了new运算符以及它的工作步骤,其实无非是把两项工作独立出来: 1.申请原始内存 2.执行构造函数 delete也涉及了两个工作: 1.执行析构函数 2.释放原始内存 其实标准库提供了另 ...

  3. 自己如何正确获取MYSQL的ADO连接字符串

    1.下载安装MYSQL的ODBC数据库驱动程序(mysql-connector-odbc-5.3.4-win32.msi或者mysql-connector-odbc-5.3.4-winx64.msi) ...

  4. PHP实现查看邮件是否被阅读

      <? //当你在发送邮件时,你或许很想知道该邮件是否被对方已阅读.这里有段非常有趣的代码片段能够显示对方IP地址记录阅读//的实际日期和时间. error_reporting(0); Hea ...

  5. hdu4930 Fighting the Landlords(模拟 多校6)

    题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...

  6. matlab-非线性方程求根函数及函数曲线绘制

    Matlab中提供了很多求解非线性方程(y=f(x))的函数,刚開始使用,真的很困惑.全部.这里依据matlab的help文档对这些函数做一些小小的总结 fsolve函数 用来求解非线性方程组:F(x ...

  7. 利用 apache bench 模拟并发请求

    示意代码如下 ab -n 1000 -c 10 http://127.0.0.1/ -n 指的是总的请求,默认值是 1 -c 指的是并发数,默认值是 1 -t 指的是测试的总时间,测试所进行的最大秒数 ...

  8. CentOS 下Mysql数据库的安装与配置

    一.mysql简介 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle.sqlserver等等,这些数据库软件在windows上安装都非常 的方便,在Linux上如果要安装数据库, ...

  9. Java交通灯系统

    交通灯管理项目模拟了对十字路口交通灯的控制,一般在我们生活中的十字路口是有人行道的,而此项目没有考虑人行道.具体需求如下:  1.异步随机生成按照各个路线行驶的车辆.          例如:     ...

  10. Linux下性能分析工具汇总

    来自:http://os.51cto.com/art/201104/253114.htm 本文讲述的是:CPU性能分析工具.Memory性能分析工具.I/O性能分析工具.Network性能分析工具. ...