http://acm.uestc.edu.cn/#/problem/show/802

Just a Line

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

There are N points on a plane, among them N−1 points will form a line, your task is to find the point that is not on the line.

Input

The first line contains a single number N, the number of points. (4≤N≤50000)

Then come N lines each with two numbers (xi,yi), giving the position of the points. The points are given in integers. No two points' positions are the same. (−109≤xi,yi≤109)

Output

Output the position of the point that is not on the line.

Sample input and output

Sample Input Sample Output
5
0 0
1 1
3 4
2 2
4 4
3 4

题目很简单,我一直wa的原因在于两点:%g与%.0f没有用好,遇到double型等的整数,别用%g,用%d或%.0f(我一直不晓得%g哪里错了,难道说有的整数强转后还能转出几位小数出来不成);另一点是eps,精度之前调为1e-10竟然精度还不够,以后就直接上-20.

代码1:

 #include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> using namespace std; #define PI acos(-1.0)
#define EPS 1e-20
#define lll __int64
#define ll long long
#define INF 0x7fffffff double a[][];
int n; inline double K(int i,int j);//斜率
inline bool F(double i,double j); int main(){
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
scanf("%d",&n);
n-=;
for(int i=;i<;i++) scanf("%lf %lf",&a[i][],&a[i][]);
double k01=K(,);
double k02=K(,);
double k03=K(,);
double k12=K(,);
double k13=K(,);
double k23=K(,);
if(F(k01,k02)&&F(k01,k03)&&F(k03,k02)) printf("%.0f %.0f\n",a[][],a[][]);
else if(F(k01,k12)&&F(k01,k13)&&F(k13,k12)) printf("%.0f %.0f\n",a[][],a[][]);
else if(F(k12,k02)&&F(k12,k23)&&F(k23,k02)) printf("%.0f %.0f\n",a[][],a[][]);
else if(F(k03,k13)&&F(k23,k03)&&F(k23,k13)) printf("%.0f %.0f\n",a[][],a[][]);
else{
double k04,k14,k24;
for(int i=;i<n;i++){
scanf("%lf %lf",&a[][],&a[][]);
k04=K(,);
k14=K(,);
k24=K(,);
if(F(k04,k14)&&F(k04,k24)&&F(k14,k24)){
printf("%.0f %.0f\n",a[][],a[][]);
break;
}
}
}
return ;
}
inline double K(int i,int j){
if(a[i][]==a[j][]) return (double)INF;
else return (a[i][]-a[j][])/(a[i][]-a[j][]);
}
inline bool F(double i,double j){
return fabs(i-j)>EPS;
}

代码2:

 #include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> using namespace std; #define PI acos(-1.0)
#define EPS 1e-20
#define lll __int64
#define ll long long
#define INF 0x7fffffff
#define INT 2147483646 double a[][];
int n; inline double K(int i,int j); int main(){
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
double kk[];
int cnt;
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%lf%lf",&a[i][],&a[i][]);
for(int i=;i<n;i++){
cnt=;
for(int j=;j<;j++){
if(i==j) continue;
kk[cnt++]=K(i,j);
}
if(fabs(kk[]-kk[])>EPS&&fabs(kk[]-kk[])>EPS&&fabs(kk[]-kk[])>EPS){
printf("%.0f %.0f\n",a[i][],a[i][]);
break;
}
}
return ;
}
inline double K(int i,int j){
if(a[i][]==a[j][]) return (double)INT;
else return (a[i][]-a[j][])/(a[i][]-a[j][]);
}

cdoj802-Just a Line的更多相关文章

  1. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

  2. Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.

    启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...

  3. 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容

    我是在java中做的相关测试, 首先粘贴下报错: 读取xml配置文件:xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"

    同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...

  6. [LeetCode] Line Reflection 直线对称

    Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given ...

  7. [LeetCode] Tenth Line 第十行

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  8. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  9. "Installation failed !" in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated )

    "Installation failed !" in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated ...

  10. How to build .apk file from command line(转)

    How to build .apk file from command line Created on Wednesday, 29 June 2011 14:32 If you don’t want ...

随机推荐

  1. Java 浅析 Thread.join()

    概要 本文分为三部分对 Thread.join() 进行分析: 1. join() 的示例和作用 2. join() 源码分析 3. 对网上其他分析 join() 的文章提出疑问 1. join() ...

  2. windows任务计划程序 坑

  3. Java-Web中访问某个指定工程中的文件,报错后发现访问的文件是另一个工程里面的文件

    问题: 浏览器向我的bingou项目中的UserDaoImpl.java发送请求, myeclipse报错:空指针异常 点击报错行之后,错误给定位到了另一个项目中的的一个文件 解决: 原因是文件名错误 ...

  4. elasticsearch 复杂查询小记

    以下接口调用都基于5.5版本 JSON 文档格式 { "_index": "zipkin-2017-09-06", "_type": &qu ...

  5. SpringBoot学习记(一)第一个SpringBoot Web服务

    工具IDEA 一.构建项目 1.选择Spring Initializr 2.填写项目信息 3.勾选webService 4.勾选Thymeleaf 5.项目建立完成,启动类自动生成 二.写个Contr ...

  6. [UE4]换枪需要做的事,容器:数组、集合、Map

    换枪: 1.需要同时保存多把枪 2.换下去的枪需要隐藏,而不是销毁 3.换枪应该有动作 4.不同的枪应该有不同的行为 蓝图中常见的容器 1.数组 特点: 1.元素连续存放 2.通过索引访问 3.索引从 ...

  7. 第9课 const和volatile分析

    1. const只读变量——(注意不是真正常量,只是告诉编译器不能出现在赋值号左边!) (1)const修饰的变量是只读的,本质还是变量 (2)const修饰的局部变量在栈上分配空间 (3)const ...

  8. Java 中的 JVM、堆和栈 -- 初步了解

    JVM -- Java Virtual Machine(Java虚拟机) —— 因为要说堆和栈,所以我们必须要先简单的说一下JVM.(JVM详细请找度娘啦~) 首先,我们都知道 java 一直宣传的口 ...

  9. 配置Ubuntu虚拟环境

    1.ubuntu默认root用户没有激活,激活root用户,就要为root用户创建密码 $sudo passwd root   2.修改主机名 $vi /etc/hostname   3.安装ssh服 ...

  10. OpenACC 书上的范例代码(Jacobi 迭代),part 1

    ▶ 使用Jacobi 迭代求泊松方程的数值解 ● 原始串行版本,运行时间 2272 ms #include <stdio.h> #include <stdlib.h> #inc ...