uva 378 Intersecting Lines
来源:互联网 发布:大数据时代是什么意思 编辑:程序博客网 时间:2024/06/07 09:02
题目:给了4个点,求两条线,判断两条线平行,同一条线,相交(给出交点)
反思:1 功能一块块的写,边写边测,更容易一次性AC
2 网上代码多是用 struct point 来定义坐标,下次可以试试
#include <cstdio>#include <string.h>#include <cstdlib>#include <cmath>#include <ctgmath>#include <iostream>#include <vector>#include <algorithm>#include <map>using namespace std;//由两个点的坐标,求出所在直线方程,返回y=kx+b中的k、bvoid func(double x1,double y1,double x2,double y2,double &k,double &b){ k = (y2-y1)/(x2-x1); b = y1 - (k*x1);}int main(){ //double x1,y1,x2,y2,k,b; int num; cin>>num; cout<<"INTERSECTING LINES OUTPUT"<<endl; while (num--) { double x1,y1,x2,y2,x3,y3,x4,y4; cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4; //首先处理不垂直x轴的 if((x1!=x2) && (x3!=x4)){ double k1,b1,k2,b2; func(x1, y1, x2, y2, k1, b1); func(x3, y3, x4, y4, k2, b2); //平行 if(k1==k2 && b1!=b2) cout<<"NONE"<<endl; //一条线 else if(k1==k2 && b1==b2) cout<<"LINE"<<endl; //相交 else { double x,y; x=(b2-b1)/(k1-k2); y=k1*x + b1; printf("POINT %.2lf %.2lf\n",x,y); } } //处理垂直x轴的 else{ if (x1==x2 && x4==x3 && x1==x3) cout<<"LINE"<<endl; else if(x1==x2 && x4==x3 && x1!=x3) cout<<"NONE"<<endl; else{ if(x1==x2){ double k,b; func(x3, y3, x4, y4, k, b); double x = x1; double y = k*x+b; printf("POINT %.2lf %.2lf\n",x,y); } else{ double k,b; func(x1, y1, x2, y2, k, b); double x = x3; double y = k*x+b; printf("POINT %.2lf %.2lf\n",x,y); } } } } cout<<"END OF OUTPUT"<<endl; return 0;}
0 0
- uva 378Intersecting Lines
- UVa 378 - Intersecting Lines
- UVa 378 - Intersecting Lines
- UVa 378 - Intersecting Lines
- uva 378 Intersecting Lines
- uva 378 Intersecting Lines
- Intersecting Lines
- Intersecting Lines
- Intersecting Lines
- Intersecting Lines
- UVA 378 Intersecting Lines POJ 1249【直线位置情况简单判定】
- zoj1820 Intersecting Lines
- POJ 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- 原型、原型链-持续更新
- 如何在CSDN博客中编辑公式?
- 二分+倍增思想 “玲珑杯”ACM比赛 Round #13/B
- HTTP1.0 HTTP 1.1 HTTP 2.0主要区别
- 动态页面抓取
- uva 378 Intersecting Lines
- Uva1593 Alignment of Code
- Mac 升级bash
- Linux memcache操作命令
- ZOJ—3870 (位运算)
- 解释VR的时间扭曲(time-warp)
- 基于Tensorflow的MNIST手写数字识别(一)
- 【Usaco DEC08 bronze】劣质的草
- Android系统联系人特效