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. [转] Maven.pom.xml 配置示例

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  2. Mysql-binlog的移动和归档

    #!/bin/bash # To backup and archive binlogs. declare -i NUM=0 declare -i SUM=0 SUM=`/bin/ls -l mysql ...

  3. Linux下的压缩(zip)解压(unzip)缩命令

      .zip命令 zip -r myfile.zip ./* 将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzip命令 unzip -o ...

  4. freePBX汉化方法记录——备忘

    FreePBX汉化[root@bgcc69:/var/www/html/admin/i18n/zh_CN/LC_MESSAGES]$pwd/var/www/html/admin/i18n/zh_CN/ ...

  5. php 编程笔记分享 - 非常实用

    php opendir()列出目录下所有文件的两个实例 php opendir()函数讲解及遍历目录实例 php move_uploaded_file()上传文件实例及遇到问题的解决方法 php使用m ...

  6. 深度学习RNN实现股票预测实战(附数据、代码)

    背景知识 最近再看一些量化交易相关的材料,偶然在网上看到了一个关于用RNN实现股票预测的文章,出于好奇心把文章中介绍的代码在本地跑了一遍,发现可以work.于是就花了两个晚上的时间学习了下代码,顺便把 ...

  7. json化的必要性

    参考文章:http://www.cnblogs.com/SanMaoSpace/p/3139186.html http://www.oschina.net/question/100267_61459

  8. 3.2_k-近邻算法案例分析

        k-近邻算法案例分析 本案例使用最著名的”鸢尾“数据集,该数据集曾经被Fisher用在经典论文中,目前作为教科书般的数据样本预存在Scikit-learn的工具包中. 读入Iris数据集细节资 ...

  9. uva-10152-乌龟排序

    求从待排序的到期望的顺序的最小操作顺序,只能进行一个操作,将当前的乌龟拿出来,上面的下移,拿出来的放到最上面 发现voj没有PE, 解题方法,把俩个串反过来使用,从期望的顺序到待排序的顺序. AC:1 ...

  10. rsyslog编译依赖问题解决

    bit-32-centos6.4测试loganalyzer+mysql+rsyslog   web界面中央日志分析系统.1,报json-c错误wget http://cloud.github.com/ ...