cdoj802-Just a Line
http://acm.uestc.edu.cn/#/problem/show/802
Just a Line
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
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 |
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的更多相关文章
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- 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 ...
- 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容
我是在java中做的相关测试, 首先粘贴下报错: 读取xml配置文件:xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
- [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 ...
- [LeetCode] Tenth Line 第十行
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- [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. ...
- "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 ...
- 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 ...
随机推荐
- DOM操作之属性和样式操作
在DOM操作,除了前面的节点操作以外,常常被用到的操作还有属性操作和节点操作,下面,主要来总结一下jQuery中的属性操作方法和样式操作方法. 在开始操作前,我们需要先在html中添加如下代码,后面所 ...
- 【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies
G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the pro ...
- TraceLog.cs 累积 C#
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Dia ...
- mysql 不同事务隔离级别
repeatable read 在同一事务中,同一查询多次进行时候,由于其他插入操作(insert)的事务提交,导致每次返回不同的结果集. 标准的repeatable read是允许幻读的,因为这一级 ...
- mysql存储过程中遍历数组字符串的两种方式
第一种:多次使用substring_index()的方法 DELIMITER $$ DROP PROCEDURE IF EXISTS `array`$$ CREATE PROCEDURE `arra ...
- 【转载】Docker 经验之谈
本文来源:Ghostcloud原创 对于用户来说,可能一开始在不了解的情况下会对容器报以拒绝的态度,但是在尝到容器的甜头.体验到它的强大性能之后,相信大家最终是无法抵挡其魅力的.容器技术能够解 ...
- BCGcontrolBar(一) MFC界面库简介
原帖地址:http://blog.csdn.net/zw514159799/article/details/9148385 英文原文:http://www.bcgsoft.com/bcgcontrol ...
- 自己根据js的兼容封装了一个小小的js库
var gys = function () { } //oParent父节点 //获取所有的子元素 gys.prototype.getElementChildren = function (oPare ...
- 简单工厂法( Factory Method)
工厂方法 (Factory Method) Define an interface for creating an object ,but let subclasses decide which cl ...
- 5.用 CSS 创作一个立体滑动 toggle 交互控件
原文地址:https://segmentfault.com/a/1190000014638655 HTML代码: <html> <head> <link rel=&quo ...