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 ...
随机推荐
- 提取数据之goose使用
1.简介 Python-goose项目是用Python重写的Goose,Goose原来是用Java写的文章提取工具.Python-goose的目标是给定任意资讯文章或者任意文章类的网页,不仅提取出文章 ...
- java web 中 页面/业务重定向
情形一:地址栏简洁明了(列表页面需要局部查询,分页) 页面初始化:library方法,没有任何过滤条件,显示第一页: 页面刷新:library方法,page依旧保留,在地址栏中显示,但局部查询条件会 ...
- appium+python自动化38-adb shell按键操作(input keyevent)
前言 接着上篇介绍input里面的按键操作keyevent事件,发送手机上常用的一些按键操作 keyevent 1.keyevent事件有一张对应的表,可以直接发送对应的数字,也可以方式字符串,如下两 ...
- binlog之五:mysqlbinlog解析binlog乱码问题解密
发现MySQL库的binlog日志出来都是乱码,如下所示: BINLOG ’ IXZqVhNIAAAALQAAAGcBAAAAAHoAAAAAAAEABHRlc3QAAno0AAEDAABUOcnY ...
- Discuz论坛管理的问题汇总
Discuz论坛在Linux上搭建成功了, 不得不说, 其功能是非常强大的, 可以满足已知的绝大多数的需求. 搭建完成后也有一些问题, 在这里汇总一下, 以便将来查阅. 1. 显示未处理用户信息, 但 ...
- 版本管理工具---svn搭建与使用
SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subversion ...
- pycharm下getpass.getpass()卡住
pycharm下getpass.getpass()卡住不运行是什么问题 python pycharm 首先声明 下面这几行代码在命令行和eclipse下都能正常运行 import getpass pr ...
- solr 7+tomcat 8 + mysql实现solr 7基本使用(安装、集成中文分词器、定时同步数据库数据以及项目集成)
基本说明 Solr是一个开源项目,基于Lucene的搜索服务器,一般用于高级的搜索功能: solr还支持各种插件(如中文分词器等),便于做多样化功能的集成: 提供页面操作,查看日志和配置信息,功能全面 ...
- Web of Science数据库中文献相关信息下载与保存
1. Web of Science 数据库(https://apps.webofknowledge.com/): a. 所在网络必须由访问 该网站的权限. b.建议使用web of Science的核 ...
- Linux入门之vi
How to Use the vi Editor* *Copyright 1991 by Simon Fraser University. Reprinted with permission. The ...