题意: 给一条线段,和一个矩形,问线段是否与矩形相交或在矩形内. 解法: 判断是否在矩形内,如果不在,判断与四条边是否相交即可.这题让我发现自己的线段相交函数有错误的地方,原来我写的线段相交函数就是单纯做了两次跨立实验,在下图这种情况是错误的: 这样的话线段与右边界的两次跨立实验(叉积<=0)都会通过,但是并不相交. 所以要加快速排斥. 还有就是这题题目说给出的不一定是左上角,右下角依次的顺序.所以干脆重新自己定义左上角,右下角. 代码: #include <iostream> #inc…
There are n lines l1,l2,…,ln on the 2D-plane. Staring at these lines, Calabash is wondering how many pairs of (i,j) that 1≤i<j≤n and li,lj share at least one common point. Note that two overlapping lines also share common points. Please write a progr…
题目链接:https://vjudge.net/problem/Gym-102220C 题意:求n 条直线两两相交有几对(也可以重合). 思路:用map和pair存所有直线的斜率和与X轴的交点,假设与前面i条直线都相交,那么要减去与这条直线平行而不重合的直线. 1 #include <bits/stdc++.h> 2 #include <time.h> 3 #include <set> 4 #include <map> 5 #include <stac…
题目传送门 题意:一个矩形和一条线段,问是否有相交 分析:考虑各种情况.坑点:给出的矩形的两个端点是无序的,还有线段完全在矩形内也算相交 /************************************************ * Author :Running_Time * Created Time :2015/10/27 星期二 13:17:49 * File Name :POJ_1410.cpp ******************************************…
模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostream> #include <cstring> using namespace std; #define eps 1e-8 #define PI acos(-1.0)//3.14159265358979323846 //判断一个数是否为0,是则返回true,否则返回false #define z…
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果攻占城市,就能装满背包.从城市到城市消耗的粮食等于两城市的距离,如果距离大于士兵当前的背包的容量,士兵就不能走这条路.士兵可以选择空降一次,空降不耗费.求p个士兵攻占所有城市所需要的最小背包容量k. 来源:2013 暑期多校联合训练 第一场 思路 非常好的一道比较综合的题目~首先我们能想到这是可相交…
Geometric Shapes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1243   Accepted: 524 Description While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be cut into special fluorescent materials. To…
Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9996   Accepted: 2632 Description You are to write a program that has to decide whether a given line segment intersects a given rectangle. An example: line: start point: (4,9) …
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3512   Accepted: 1601 Description In the game of Jack Straws, a number of plastic or wooden "straws" are dumped o…
Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13605   Accepted: 6049 Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three…