《Cracking the Coding Interview》——第7章:数学和概率论——题目3
2014-03-20 02:05
题目:给定笛卡尔二维平面上两条直线,判断它们是否相交。
解法:相交、重合、平行。
代码:
// 7.3 Given two lines on the Cartesian, determine if they would intersect.
#include <cstdio>
using namespace std; int main()
{
// a * x + b * y + c = 0;
// d * x + e * y + f = 0;
int a, b, c, d, e, f;
bool suc; while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) == ) {
if ((a == && b == ) || (d == && e == )) {
// invalid line
suc = false;
} else if (a * e == b * d) {
if (a * f == c *d) {
// coincident
suc = true;
} else {
// parallel
suc = false;
}
} else {
// intersect
suc = true;
}
if (suc) {
printf("Yes\n");
} else {
printf("No\n");
}
} return ;
}
《Cracking the Coding Interview》——第7章:数学和概率论——题目3的更多相关文章
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- Cracking the Coding Interview(Stacks and Queues)
Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...
- 《Cracking the Coding Interview》——第7章:数学和概率论——题目7
2014-03-20 02:29 题目:将质因数只有3, 5, 7的正整数从小到大排列,找出其中第K个. 解法:用三个iterator指向3, 5, 7,每次将对应位置的数分别乘以3, 5, 7,取三 ...
- 《Cracking the Coding Interview》——第7章:数学和概率论——题目6
2014-03-20 02:24 题目:给定二位平面上一堆点,找到一条直线,使其穿过的点数量最多. 解法:我的解法只能适用整点,对于实数坐标就得换效率更低的办法了.请参见LeetCode - Max ...
- 《Cracking the Coding Interview》——第7章:数学和概率论——题目5
2014-03-20 02:20 题目:给定二维平面上两个正方形,用一条直线将俩方块划分成面积相等的两部分. 解法:穿过对称中心的线会将面积等分,所以连接两个中心即可.如果两个中心恰好重合,那么任意穿 ...
- 《Cracking the Coding Interview》——第7章:数学和概率论——题目4
2014-03-20 02:16 题目:只用加法和赋值,实现减法.乘法.除法. 解法:我只实现了整数范围内的.减法就是加上相反数.乘法就是连着加上很多个.除法就是减到不能减为止,数数总共减了多少个. ...
随机推荐
- 什么是 pwd
pwd print work directory, 指linux terminal的当前目录 $ pwd
- 使用shell脚本实现在liunx上进行svn的上传下载更新功能
最近有个功能,是需要从在liunx上拉取svn地址,并创建一个新文件进行提交,shell脚本如下 #!/bin/bash echo "Hello World !" myFile=& ...
- java 生成12位随机数,解决The literal 9999999999999 of type int is out of range 问题
原本想这样产生一个随机数,但是你会看到,只要数字超过了9位数,就会出问题,提示“The literal 1000000000000 of type int is out of range” 解决方式是 ...
- python 合并字符串
[root@chenbj python]# cat name.py #!/usr/bin/env python # _*_ coding:utf-8 _*_ first_name = "ch ...
- sz 命令
sz命令 下载文件命令 sz 文件名
- Adobe CS2提供免费序列号
据Adobe官方博客报道,自2012年12月13日起,因为技术故障,该公司已停止使用Creative Suite(CS2)产品及Acrobat 7的激活服务器. 这些产品大多是7年前发布,很多已经无法 ...
- Java-笔记1
/* 对第一个java程序进行总结 1. java程序编写-编译-运行的过程 编写:我们将编写的java代码保存在以".java"结尾的源文件中 编译:使用javac.exe命令编 ...
- 曲率(Curvature)
原文链接 几何体的曲率对于不同的对象有不同的定义.首先来看最简单的平面曲线. 首先把曲线分成无穷小的小段,每一段看作某个圆的一小段圆弧.这个圆叫做“密切圆”(Osculating Circle).由于 ...
- 遗忘的html标签
<span>x</span><sup>2</sup><span>+y=10</span> <br> <span ...
- 牛客小白月赛2 H 武 【Dijkstra】
链接:https://www.nowcoder.com/acm/contest/86/H来源:牛客网 题目描述 其次,Sεlιнα(Selina) 要进行体力比武竞赛. 在 Sεlιнα 所在的城市, ...