题目链接:Barcelonian Distance 题意:给定方格坐标,方格坐标上有两个点A,B和一条直线.规定:直线上沿直线走,否则沿方格走.求A到B的最短距离. 题解:通过直线到达的:A.B两点都有两种方式到直线上,最多4种情况,每种情况求出A.B点到直线的距离和直线上新的两点间距离,取4种情况中最优的. 不通过直线到达:$abs(x1-x2)+abs(y1-y2)$,最后与通过直线到达的最优情况比较,得到最优解. #include <cmath> #include <cstdio&…
题目描述: In this problem we consider a very simplified model of Barcelona city. Barcelona can be represented as a plane with streets of kind x=cx=c and y=cy=c for every integer cc (that is, the rectangular grid). However, there is a detail which makes B…
题意:给出一条直线 ax +by+c=0  给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及   给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要经过的最短距离 思路: 整点和整点之间的最短路径 要么 经过 直线 要么不经过直线 如果不经过直线,那么最短距离就是两者的曼哈顿距离  |x1-x2|+|y1-y2| 如果经过线段  那么一个点有两种到线段的方式  一种是和线段上的点x 相同 一个是和线段上的点y相同  2*2一共四种情况  全部算…
题目链接:http://codeforces.com/problemset/problem/161/D 题意: 给你一棵树,问你有多少对点的距离为k. 思路: dp[i][j]表示离i节点距离为j的点个数,2次dfs,一次从底向上,另一次从顶向下. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include &…
题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah$是不可用的.(压根感觉不可优化) 考虑向量的做法:$S = \frac{1}{2}(A \times B + B \times C + C\times A)$.(相当于把一个三角形拆成了三个以原点作为其中一个顶点的"有向"三角形) 于是考虑利用向量叉积对向量加法的分配律进行优化. 枚举第…
B. Hamming Distance Sum time limit per test: 2 seconds memory limit per test:256 megabytes input: standard input output: standard output Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some str…
题目链接:http://codeforces.com/problemset/problem/161/D 题意:给出一个树,问树上点到点的距离为k的一共有几个. 一道简单的树形dp,算是一个基础题. 设dp[i][len]表示i为根距离为len的一共有几个点. 一般的树形dp都是先dfs然后再更新dp的值,注意按这样写就行了.而且一般的树形dp都是设dp[i][k]i为根,k为条件. void dfs(int u , int pre) { int len = vc[u].size(); dp[u]…
D. Distance in Tree time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is the length (…
ShitáliaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88994#problem/A Description After suddenly becoming a billionaire, Shi adopted YOLO as his motto and decided to buy a small european island, wh…
Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/A Description Bill is working in a secret laboratory. He is developing missiles for national security projects. Bi…