Settling Salesman Problem 旅行者问题

Problem Description
After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers.
All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively.
What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible?

Input
On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

One line with an integer n (1 <= n <= 2 000): the number of customers John has.

n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer.

Output
For each test case:

Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum.

Sample Input
2
4
1 -3
0 1
-2 1
1 -1
2
-999888777 1000000000
1000000000 -987654321

Sample Output
10 4
3987543098 3975087573110998514

Settling Salesman Problem 的问题

Problem Description After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers. All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively. What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible? Input On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case: One line with an integer n (1 <= n <= 2 000): the number of customers John has. n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer. Output For each test case: Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum. Sample Input 2 4 1 -3 0 1 -2 1 1 -1 2 -999888777 1000000000 1000000000 -987654321 Sample Output 10 4 3987543098 3975087573110998514

Settling Salesman Problem 的代码编写实现

Problem Description After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers. All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively. What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible? Input On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case: One line with an integer n (1 <= n <= 2 000): the number of customers John has. n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer. Output For each test case: Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum. Sample Input 2 4 1 -3 0 1 -2 1 1 -1 2 -999888777 1000000000 1000000000 -987654321 Sample Output 10 4 3987543098 3975087573110998514

Settling Salesman Problem 怎么做呢

Problem Description After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers. All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively. What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible? Input On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case: One line with an integer n (1 <= n <= 2 000): the number of customers John has. n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer. Output For each test case: Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum. Sample Input 2 4 1 -3 0 1 -2 1 1 -1 2 -999888777 1000000000 1000000000 -987654321 Sample Output 10 4 3987543098 3975087573110998514

Settling Salesman Problem 是怎么写呢

Problem Description After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers. All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively. What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible? Input On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case: One line with an integer n (1 <= n <= 2 000): the number of customers John has. n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer. Output For each test case: Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum. Sample Input 2 4 1 -3 0 1 -2 1 1 -1 2 -999888777 1000000000 1000000000 -987654321 Sample Output 10 4 3987543098 3975087573110998514

Settling Salesman Problem 怎么做的呢

Problem Description After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers. All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively. What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible? Input On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case: One line with an integer n (1 <= n <= 2 000): the number of customers John has. n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer. Output For each test case: Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum. Sample Input 2 4 1 -3 0 1 -2 1 1 -1 2 -999888777 1000000000 1000000000 -987654321 Sample Output 10 4 3987543098 3975087573110998514

Settling Salesman Problem是怎么解答的

Problem Description After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers. All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively. What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible? Input On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case: One line with an integer n (1 <= n <= 2 000): the number of customers John has. n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer. Output For each test case: Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum. Sample Input 2 4 1 -3 0 1 -2 1 1 -1 2 -999888777 1000000000 1000000000 -987654321 Sample Output 10 4 3987543098 3975087573110998514

Settling Salesman Problem

Problem Description After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers. All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively. What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible? Input On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case: One line with an integer n (1 <= n <= 2 000): the number of customers John has. n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer. Output For each test case: Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum. Sample Input 2 4 1 -3 0 1 -2 1 1 -1 2 -999888777 1000000000 1000000000 -987654321 Sample Output 10 4 3987543098 3975087573110998514

Population

It is always exciting to see people settling in a new continent. As the head of the population management office, you are supposed to know, at any time, how people are distributed in this continent. The continent is divided into square regions, each has a center with integer coordinates (x, y). Hence all the people coming into that region are considered to be settled at the center position. Given the positions of the corners of a rectangle region, you are supposed to count the number of people living in that region. Input Your program must read inputs from the standard input. Since there are up to 32768 different regions and possibly even more queries, please use "scanf" and "printf" instead of "cin" and "cout" to avoid timeout. The character "I" in a line signals the coming in of new groups of people. In the following lines, each line contains three integers: X, Y, and N, where X and Y (1 <= X, Y <= 20000) are the coordinates of the region's center, and N (1 <= N <= 10000) is the number of people coming in. The character "Q" in a line signals the query of population. The following lines each contains four numbers: Xmin, Xmax, Ymin, Ymax, where (Xmin, Ymin) and (Xmax, Ymax) are the integer coordinates of the lower left corner and the upper right corner of the rectangle, respectively. The character "E" signals the end of a test case. Process to the end of file. Output For each "Q" case, print to the standard output in a line the population in the given rectangle region. That is, you are supposed to count the number of people living at all the positions (x, y) such that Xmin <= x <= Xmax, and Ymin <= y <= Ymax. Sample Input I 8 20 1 4 5 1 10 11 1 12 10 1 18 14 1 Q 8 10 5 15 8 20 10 14 I 7 6 1 10 3 2 7 2 1 2 3 2 10 3 1 Q 2 20 2 20 E Sample Output 1 3 12

Money Matters 判定的问题

Problem Description Our sad tale begins with a tight clique of friends. Together they went on a trip to the picturesque country of Molvania. During their stay, various events which are too horrible to mention occurred. The net result was that the last evening of the trip ended with a momentous exchange of "I never want to see you again!"s. A quick calculation tells you it may have been said almost 50 million times! Back home in Scandinavia, our group of ex-friends realize that they haven't split the costs incurred during the trip evenly. Some people may be out several thousand crowns. Settling the debts turns out to be a bit more problematic than it ought to be, as many in the group no longer wish to speak to one another, and even less to give each other money. Naturally, you want to help out, so you ask each person to tell you how much money she owes or is owed, and whom she is still friends with. Given this information, you're sure you can gure out if it's possible for everyone to get even, and with money only being given between persons who are still friends. Input The first line contains two integers, n (2 <= n <= 10000), and m (0 <= m <= 50000), the number of friends and the number of remaining friendships. Then n lines follow, each containing an integer o (-10000 <= o <= 10000) indicating how much each person owes (or is owed if o < 0). The sum of these values is zero. After this comes m lines giving the remaining friendships, each line containing two integers x, y (0 <= x < y <= n - 1) indicating that persons x and y are still friends. Output Your output should consist of a single line saying "POSSIBLE" or "IMPOSSIBLE". Sample Input 5 3 100 -75 -25 -42 42 0 1 1 2 3 4 4 2 15 20 -10 -25 0 2 1 3 Sample Output POSSIBLE IMPOSSIBLE

Money Matters 会的再来回答！

Problem Description Our sad tale begins with a tight clique of friends. Together they went on a trip to the picturesque country of Molvania. During their stay, various events which are too horrible to mention occurred. The net result was that the last evening of the trip ended with a momentous exchange of "I never want to see you again!"s. A quick calculation tells you it may have been said almost 50 million times! Back home in Scandinavia, our group of ex-friends realize that they haven't split the costs incurred during the trip evenly. Some people may be out several thousand crowns. Settling the debts turns out to be a bit more problematic than it ought to be, as many in the group no longer wish to speak to one another, and even less to give each other money. Naturally, you want to help out, so you ask each person to tell you how much money she owes or is owed, and whom she is still friends with. Given this information, you're sure you can gure out if it's possible for everyone to get even, and with money only being given between persons who are still friends. Input The first line contains two integers, n (2 <= n <= 10000), and m (0 <= m <= 50000), the number of friends and the number of remaining friendships. Then n lines follow, each containing an integer o (-10000 <= o <= 10000) indicating how much each person owes (or is owed if o < 0). The sum of these values is zero. After this comes m lines giving the remaining friendships, each line containing two integers x, y (0 <= x < y <= n - 1) indicating that persons x and y are still friends. Output Your output should consist of a single line saying "POSSIBLE" or "IMPOSSIBLE". Sample Input 5 3 100 -75 -25 -42 42 0 1 1 2 3 4 4 2 15 20 -10 -25 0 2 1 3 Sample Output POSSIBLE IMPOSSIBLE

PHP Paypal Auth / Capture NVP集成故障

viewpager里面广告轮播代码报错

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内，我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年，古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合，再掺入煅烧石灰石制成的石灰，由此得来了人...

C++11：一些微小的变化（新的数据类型、template表达式内的空格、nullptr、std::nullptr_t）

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...

【阿里P6面经】二本，curd两年，疯狂复习，拿下阿里offer

《经典算法案例》01-08：如何使用质数设计扫雷（Minesweeper）游戏

《Oracle Java SE编程自学与面试指南》最佳学习路线图（2020最新版）

2020春招面试了10多家大厂，我把问烂了的数据库事务知识点总结了一下

2020年截止目前，我面试了阿里巴巴、腾讯、美团、拼多多、京东、快手等互联网大厂。我发现数据库事务在面试中出现的次数非常多。