题目链接:http://codeforces.com/problemset/problem/379/E
题意:有n个多边形,宽度为k,它们互相覆盖,求每个多边形露出部分的面积。(具体内容请看题目,重点内容已加粗)
E. New Year Tree Decorations
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Due to atheistic Soviet past, Christmas wasn’t officially celebrated in Russia for most of the twentieth century. As a result, the Russian traditions for Christmas and New Year mixed into one event celebrated on the New Year but including the tree, a Santa-like ‘Grandfather Frost’, presents and huge family reunions and dinner parties all over the country. Bying a Tree at the New Year and installing it in the house is a tradition. Usually the whole family decorates the tree on the New Year Eve. We hope that Codeforces is a big and loving family, so in this problem we are going to decorate a tree as well.
So, our decoration consists of n pieces, each piece is a piece of colored paper, its border is a closed polyline of a special shape. The pieces go one by one as is shown on the picture.
The i-th piece is a polyline that goes through points: (0, 0), (0, y0), (1, y1), (2, y2), …, (k, yk), (k, 0). The width of each piece equals k.
The figure to the left shows the decoration, the figure to the right shows the individual pieces it consists of.
The piece number 1 (shown red on the figure) is the outer piece (we see it completely), piece number 2 (shown yellow) follows it (we don’t see it completely as it is partially closed by the first piece) and so on. The programmers are quite curious guys, so the moment we hung a decoration on the New Year tree we started to wonder: what area of each piece can people see?
Input
The first line contains two integers, n and k (1 ≤ n, k ≤ 300). Each of the following n lines contains k + 1 integers — the description of the polyline. If the i-th line contains ontegers yi, 0, yi, 1, …, yi, k, that means that the polyline of the i-th piece goes through points ( 0 , 0 ) , ( 0 , y i , 0 ) , ( 1 , y i , 1 ) , (0, 0), (0, y_{i, 0}), (1, y_{i, 1}), (0, 0),(0, yi, 0