CF1079D Barcelonian Distance】的更多相关文章

思路: 模拟. 实现: #include <bits/stdc++.h> using namespace std; ; double dis(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { int a, b, c; double x1, x2, y1, y2; while (cin >> a…
题目链接: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/contest/1032/ 是真的真的真的忍不住想吐槽这题意是真的真的真的读不懂…… A - Kitchen Utensils - [简单数学题] 题意: 国王开宴会,总共有编号为 $1 \sim 100$ 种餐具用来组成一套餐具.组成一套餐具的要求是,每种餐具最多出现一只. 现在给 $k$ 个宾客每个人若干套餐具,给的每套餐具都是一模一样的:同时,每个人收到的餐具套数也都是相同的. 现在知道宴会开完后,还剩下 $n$ 个餐具,以及这 $n$ 个…
A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, k, cnt[N]; int main() { while (scanf("%d%d", &n, &k) != EOF) { memset(cnt, , sizeof cnt); , x; i <= n; ++i) { scanf("%d", &a…
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total Hamming distance between all pairs of the given numbers. Example: Input: 4, 14, 2 Output: 6 Explanat…
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 231. Example: Input: x = 1, y = 4 Output: 2 Explanation: 1…
Given a non-empty string str and an integer k, rearrange the string such that the same characters are at least distance k from each other. All input strings are given in lowercase letters. If it is not possible to rearrange the string, return an empt…
You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. You are given a 2D grid of values 0, 1 or 2, where: Each 0 marks an empty land which you can pass b…