luogu#P6925. [ICPC2016 WF] Spin Doctor

[ICPC2016 WF] Spin Doctor

题目描述

As an employee of the world’s most respected political polling corporation, you must take complex, real-world issues and simplify them down to a few numbers. It isn’t always easy. A big election is coming up and, at the request of Candidate X, you have just finished polling nn people. You have gathered three pieces of information from each person, with the values for the ithi^\text {th} person recorded as:

aia_ i – the number of digits of π\pi they have memorized

bib_ i – the number of hairs on their head

cic_ i – whether they will vote for Candidate X

Unfortunately, you are beginning to wonder if these are really the most relevant questions to ask. In fact, you cannot see any correlation between aa, bb, and cc in the data. Of course, you cannot just contradict your customer – that is a good way to lose your job!

Perhaps the answer is to find some weighting formula to make the results look meaningful. You will pick two real values SS and TT, and sort the poll results (ai,bi,ci)(a_ i, b_ i, c_ i) by the measure aiS+biTa_ i \cdot S + b_ i \cdot T. The sort will look best if the results having cic_ i true are clustered as close to each other as possible. More precisely, if jj and kk are the indices of the first and last results with cic_ i true, you want to minimize the cluster size which is kj+1k-j+1. Note that some choices of SS and TT will result in ties among the (ai,bi,ci)(a_ i,b_ i,c_ i) triples. When this happens, you should assume the worst possible ordering occurs (that which maximizes the cluster size for this (S,T)(S, T) pair).

输入格式

The input starts with a line containing nn (1n2500001 \leq n \leq 250\, 000), which is the number of people polled. This is followed by one line for each person polled. Each of those lines contains integers aia_ i (0ai20000000 \leq a_ i \leq 2\, 000\, 000), bib_ i (0bi20000000 \leq b_ i \leq 2\, 000\, 000), and cic_ i, where cic_ i is 11 if the person will vote for Candidate X and 00 otherwise. The input is guaranteed to contain at least one person who will vote for Candidate X.

输出格式

Display the smallest possible cluster size over all possible (S,T)(S, T) pairs.

题目大意

大选要到了,受候选人X的要求,你调查了 nn 个人,并记录了每个人的 33 个信息:

  • aia_i 他们能记忆 π\pi 的多少位
  • bib_i 他们的头发数量
  • cic_i 他们是否会给候选人X投票

你需要找到某个公式使这些结果看起来有意义。你要选择 22 个实数 SSTT,将所有调查结果按 ai×S+bi×Ta_i\times S+b_i\times T 排序。如果 cic_itrue 的人聚集在了一起,你会觉得这个排序看起来不错。更准确地说,如果 jjkk 分别是第一个和最后一个 cic_itrue 的人的下标,你想要最小化 kj+1k-j+1。注意有些 SSTT 会让排序时出现相等的情况,这时你应该假设最坏情况发生,即排序使得 kj+1k-j+1 最大。

6
0 10 0
10 0 1
12 8 1
5 5 0
11 2 1
11 3 0

4

10
6 1 1
0 2 0
2 1 1
6 1 1
8 2 0
4 4 0
4 0 0
2 3 1
6 1 0
6 3 1

8

5
5 7 0
3 4 0
5 7 0
5 7 1
9 4 0

1

提示

Time limit: 5000 ms, Memory limit: 1048576 kB.

International Collegiate Programming Contest (ACM-ICPC) World Finals 2016