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 ...
随机推荐
- html_常用技巧总结
============= 博客大全: 脚本之家:http://www.jb51.net/list/list_233_104.htm 红黑联盟: http://www.2cto.com/kf/yid ...
- 第4章 文件和目录(5)_贯穿案例2:mini shell(1)
6. 贯穿案例2:mini shell(1) [阶段性任务]实现cd.pwd和quit命令 //job.h #ifndef __JOB_H__ #define __JOB_H__ //接收命令行参数 ...
- storm的可靠性
消息确认机制: 在数据发送的过程中可能会数据丢失导致没能接收到,spout有个超时时间(默认是30S),如果30S过去了还是没有接收到数据,也认为是处理失败. 运行结果都是处理成功 参考代码Storm ...
- SPM——Using Maven+Junit to test Hello Wudi
Last week, ours teacher taught us 'Software Delivery and Build Management'. And in this class, our t ...
- python拓展3 常用算法
知识内容: 1.递归复习 2.算法基础概念 3.查找与排序 参考资料: http://python3-cookbook.readthedocs.io/zh_CN/latest/index.html h ...
- python入门-变量和简单数据类型
1 title() 是以首字母大写的方式显示每个单词 lower() 字母小写 upper() 字母大写 2 python使用+号来合并字符串 字符串中使用制表符用\t 字符串中使用换行符\n 用rs ...
- mock单测
mockMvc执行流程总结: 整个过程:1.mockMvc.perform执行一个请求:2.MockMvcRequestBuilders.get("/user/1")构造一个请求3 ...
- 13.mysql基本查询
1. 给表起个别名:但是,前面的也是需要进行修改的,否则会报错的: select * from s.name from students as s; 2. 为字段起别名 select s,name a ...
- hive xml udf
<store> <book id="book"><title id="titile">hive</title> ...
- 网络软工个人作业4——Alpha阶段个人总结
1.个人总结 (1) 类型 具体技能和面试问题 现在的回答 毕业时找工作 语言 拿手的语言 Java 软件实现 有没有在别人的代码基础上进行改进,你是怎么读懂别人的代码,你采取什么方法不影响原来的功能 ...