301160: CF216D. Spider's Web

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Spider's Web

题意翻译

## 题目描述 这个蛛网有 $n$ 条主线,将整张蛛网分成 $n$ 个区域,我们按照顺时针的顺序从 $1$ 到 $n$ 编号,其中 $n$ 号区域与 $1$ 号区域相邻。 对于第 $i$ 个区域,两条主线之间有 $k_{i}$ 条蛛丝相连,蛛丝两端到中心的距离相等,第 $j$ 条蛛丝两端到中心的距离为 $p_{i,j}$。这些蛛丝将该区域分成 $k_{i}$ $-$ $1$ 个扇区,如果某个扇区两侧的主线上蛛丝端点的个数不相等,则这个扇区是不稳定的。 现在给出整张蜘蛛网的结构,计算有多少个不稳定的扇区。 ## 输入格式 第一行有一个整数 $n$ $($$3$ $≤$ $n$ $≤$ $1000$$)$,表示主线的条数。 接下来 $n$ 行,每行首先有一个整数$k$ $($$1$ $≤$ $k$ $≤$ $10^5$$)$,表示该扇区蛛丝的条数。后面紧跟 $k_i$ 个整数 $p_{i,j}$ $($$1$ $≤$ $p_{i,j}$ $≤$ $105$ $,$ $1$ $≤$ $j$ $≤$ $ki$$)$,表示每条蛛丝两端与中心的距离,不保证排好序。 保证相邻区域中,不存在到中心距离相同的两条蛛丝。总的蛛丝数不超过$105$。 ## 输出格式 输出一个整数,表示不稳定的扇区数量。

题目描述

Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF216D/e65dd65db24247adc6327b212b9c0054dfc81151.png)There are $ n $ main threads going from the center of the web. All main threads are located in one plane and divide it into $ n $ equal infinite sectors. The sectors are indexed from $ 1 $ to $ n $ in the clockwise direction. Sectors $ i $ and $ i+1 $ are adjacent for every $ i $ , $ 1<=i&lt;n $ . In addition, sectors $ 1 $ and $ n $ are also adjacent. Some sectors have bridge threads. Each bridge connects the two main threads that make up this sector. The points at which the bridge is attached to the main threads will be called attachment points. Both attachment points of a bridge are at the same distance from the center of the web. At each attachment point exactly one bridge is attached. The bridges are adjacent if they are in the same sector, and there are no other bridges between them. A cell of the web is a trapezoid, which is located in one of the sectors and is bounded by two main threads and two adjacent bridges. You can see that the sides of the cell may have the attachment points of bridges from adjacent sectors. If the number of attachment points on one side of the cell is not equal to the number of attachment points on the other side, it creates an imbalance of pulling forces on this cell and this may eventually destroy the entire web. We'll call such a cell unstable. The perfect web does not contain unstable cells. Unstable cells are marked red in the figure. Stable cells are marked green. Paw the Spider isn't a skillful webmaker yet, he is only learning to make perfect webs. Help Paw to determine the number of unstable cells in the web he has just spun.

输入输出格式

输入格式


The first line contains integer $ n $ ( $ 3<=n<=1000 $ ) — the number of main threads. The $ i $ -th of following $ n $ lines describe the bridges located in the $ i $ -th sector: first it contains integer $ k_{i} $ ( $ 1<=k_{i}<=10^{5} $ ) equal to the number of bridges in the given sector. Then follow $ k_{i} $ different integers $ p_{ij} $ ( $ 1<=p_{ij}<=10^{5}; 1<=j<=k_{i} $ ). Number $ p_{ij} $ equals the distance from the attachment points of the $ j $ -th bridge of the $ i $ -th sector to the center of the web. It is guaranteed that any two bridges between adjacent sectors are attached at a different distance from the center of the web. It is guaranteed that the total number of the bridges doesn't exceed $ 10^{5} $ .

输出格式


Print a single integer — the number of unstable cells in Paw the Spider's web.

输入输出样例

输入样例 #1

7
3 1 6 7
4 3 5 2 9
2 8 1
4 3 7 6 4
3 2 5 9
3 6 3 8
3 4 2 9

输出样例 #1

6

Input

题意翻译

## 题目描述 这个蛛网有 $n$ 条主线,将整张蛛网分成 $n$ 个区域,我们按照顺时针的顺序从 $1$ 到 $n$ 编号,其中 $n$ 号区域与 $1$ 号区域相邻。 对于第 $i$ 个区域,两条主线之间有 $k_{i}$ 条蛛丝相连,蛛丝两端到中心的距离相等,第 $j$ 条蛛丝两端到中心的距离为 $p_{i,j}$。这些蛛丝将该区域分成 $k_{i}$ $-$ $1$ 个扇区,如果某个扇区两侧的主线上蛛丝端点的个数不相等,则这个扇区是不稳定的。 现在给出整张蜘蛛网的结构,计算有多少个不稳定的扇区。 ## 输入格式 第一行有一个整数 $n$ $($$3$ $≤$ $n$ $≤$ $1000$$)$,表示主线的条数。 接下来 $n$ 行,每行首先有一个整数$k$ $($$1$ $≤$ $k$ $≤$ $10^5$$)$,表示该扇区蛛丝的条数。后面紧跟 $k_i$ 个整数 $p_{i,j}$ $($$1$ $≤$ $p_{i,j}$ $≤$ $105$ $,$ $1$ $≤$ $j$ $≤$ $ki$$)$,表示每条蛛丝两端与中心的距离,不保证排好序。 保证相邻区域中,不存在到中心距离相同的两条蛛丝。总的蛛丝数不超过$105$。 ## 输出格式 输出一个整数,表示不稳定的扇区数量。

加入题单

算法标签: