P3845 [TJOI2007] Football Match

Background

# Description Super fan H watches football on TV every Saturday night and never misses a match. But last weekend, H suddenly had an important date, so he taught his three-year-old brother, little H, to write down the scores of all matches. When he came back, he found that little H not only recorded the final score of each match, but also some intermediate scores. Worse, little H did not distinguish between the two teams; the same match could be recorded as `1-2` or `2-1`. Therefore, if the final score of a match was 5-3, little H might actually have written down the following scores: `1-0 3-2 2-3 3-4 5-3` Now H has all the scores recorded by little H. He wants to know the minimum number of matches he must have missed this weekend due to the date. Note that the recorded scores are in no particular order.

Description

超级球迷 H 每周六晚上都会坐在电视前看球,从不错过一场比赛。 但是上周末,H 突然有一个重要的约会,于是他只能教他三岁的弟弟小 H 记录所有比赛的比分。但是当他约会回来时,他发现小 H 不仅认真的记录了每一场比赛的最终比分,还把一些比赛的中间比分也记录下来,而更糟糕的是,小 H 并没有区分比赛的两个队,同一场比赛的比分可能被记录成 `1-2`,也可能是 `2-1`。因此,若是有一场比赛的最终得分是 5-3,可能实际上被小 H 记录的分数有: `1-0 3-2 2-3 3-4 5-3` 现在 H 已经拿到了小 H 记录的所有比分,他想知道,在这个周末他由于约会至少错过了多少场比赛。注意小 H 记录的比分是没有先后顺序的。

Input Format

输入文件中可能包含多组测试数据,文件中第一行是一个整数 $n$,表明以下一共有 $n$ 组测试数据。 对于每一组数据,第一行有一个整数 $s$,表示小 H 记录的比分数目,以下每行用 `x-y` 的格式描述一条比分,$x$ 和 $y$ 都是非负整数。

Output Format

For each testdata, output a single integer $m$, the minimum number of matches that H must have missed.

Explanation/Hint

In the first testdata, two matches may correspond to `1-0 2-0 0-3` and `2-1`. In the second testdata, three matches may correspond to `0-0`, `5-0 3-1`, and `2-2`. Constraints: For 100% of the testdata, $n \leq 5$, $s \leq 1000$, and every score fits in `longint(Pascal)` / `long(C++)` ($2147483647$). Translated by ChatGPT 5