"bzoj4080" [Wf2014]sensor Network randomization

Source: Internet
Author: User

Title Description

The Magic Cannon came to the Royal Park, in addition to eating special dishes, but also ready to taste the famous Peking duck. The Royal Park has a total of n (1<=1<=100) Roast Duck restaurant, can be regarded as a two-dimensional plane within the point. But since the Magic Cannon did not bring money before eating roast duck, after eating the roast duck can only leave to brush the dishes. After brushing the plate, the Magic cannon will reward him with D (1<=d<=10000) money in addition to the cost of paying for the meal. The Magic Cannon is a special likes to eat roast duck children, so after going to a roast duck shop, the Magic Cannon also ready to go to other roast duck shop. But because the Royal park tolls more expensive, each unit length needs to spend 1 yuan, therefore the magic cannon may not go to all other roast duck shop. Before arriving at the next roast duck shop, the Magic Cannon will spend all the money in hand so that the next time you eat a King's meal. In addition, the Magic cannon for the Roast Duck restaurant has a special feeling, so he asked at a certain roast duck restaurant after eating roast duck, you can reach all have eaten past the roast duck restaurant. So the problem is, the Magic Cannon wants to know how many roast duck restaurants they can go to and which are the roast duck shops. Can you help him?

The main topic: a given plane of n points, select a point set S, so that all points in S 22 Euclidean distance not more than D, ask | The maximum value of the s| and the points in S. If there are multiple answers, output any one. The first row of two integers n and D, respectively, indicates the number of duck shops and the owner's toll on the Magic cannon.

Input

The next n lines, two integers per line, x, y, represent the coordinates of the N roast duck store.

Output

The first line is a number m, which indicates how many roast duck restaurants The Magic cannon can go to.

The second line is the number of M, each of which indicates the mark of the roast duck that the magic cannon can go to.

Sample input

4 1
0 0
0 1
1 0
1 1

Sample output

2
1 2

Exercises

Randomization

Test instructions is the largest regiment, but the largest regiment is the NPC problem.

For this problem, you can use the randomization algorithm:

First think of a wrong greedy algorithm: For each point, can join the answer set to join, or not add people.

If we make a lot of random sort of this sequence, and then run the greedy algorithm, we can approximate the optimal solution when we have more times.

Random ordering of sequences can use the Random_shuffle function in algorithm, using the same method as the sort function.

Due to the characteristics of the point in the two-dimensional plane, so the random number of times need not be particularly much, probably n^2 times.

#include <cstdio> #include <cstring> #include <algorithm> #define N 110using namespace Std;int N, X[n], y  [N], a[n], map[n][n], sta[n], tot, ans[n], sum;void cal () {int I, J;tot = 0;for (i = 1; I <= N; i + +) {for (j = 1 ; J <= tot; J + +) if (!map[a[i]][sta[j]]) break;if (J > Tot) sta[++tot] = A[i];} if (Tot > sum) {sum = tot;for (i = 1; I <= tot; i + +) ans[i] = Sta[i];}} int main () {int d, I, j;scanf ("%d%d", &n, &d); for (i = 1; I <= n; i + +) scanf ("%d%d", &x[i], &y[ I]), a[i] = i;for (i = 1; I <= n; i + +) for (j = 1; J <= N; j + +) if ((X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j] ) * (Y[i]-y[j]) <= d * d) map[i][j] = 1;for (i = 1; I <= n * n; i + +) Random_shuffle (A + 1, a + n + 1), Cal ();p R intf ("%d\n", sum), for (i = 1; I <= sum; i + +) printf ("%d", Ans[i]);p rintf ("\ n"); return 0;}

"bzoj4080" [Wf2014]sensor Network randomization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.