#P4122. [USACO17DEC] Blocked Billboard B

[USACO17DEC] Blocked Billboard B

题目描述

During long milking sessions, Bessie the cow likes to stare out the window of her barn at two huge rectangular billboards across the street advertising "Farmer Alex's Amazingly Appetizing Alfalfa" and "Farmer Greg's Great Grain". Pictures of these two cow feed products on the billboards look much tastier to Bessie than the grass from her farm.

One day, as Bessie is staring out the window, she is alarmed to see a huge rectangular truck parking across the street. The side of the truck has an advertisement for "Farmer Smith's Superb Steaks", which Bessie doesn't quite understand, but she is mostly concerned about the truck potentially blocking the view of her two favorite billboards.

Given the locations of the two billboards and the location of the truck, please calculate the total combined area of both billboards that is still visible. It is possible that the truck obscures neither, both, or only one of the billboards.

输入格式

The first line of input contains four space-separated integers: x1,y1,x2y2x_1,y_1,x_2 y_2, where (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2) are the coordinates of the lower-left and upper-right corners of the first billboard in Bessie's 2D field of view. The next line contains four more integers, similarly specifying the lower-left and upper-right corners of the second billboard. The third and final line of input contains four integers specifying the lower-left and upper-right corners of the truck. All coordinates are in the range 1000-1000 to +1000+1000. The two billboards are guaranteed not to have any positive area of overlap between themselves.

输出格式

Please output the total combined area of both billboards that remains visible.

题目大意

题目描述

在漫长的挤奶过程中,奶牛 Bessie 喜欢透过谷仓的窗户盯着街对面的两块巨大的矩形广告牌,上面分别写着“Farmer Alex 的美味苜蓿”和“Farmer Greg 的优质谷物”。广告牌上这两种奶牛饲料的图片对 Bessie 来说比她农场里的草看起来美味得多。

有一天,当 Bessie 正盯着窗外时,她惊讶地看到一辆巨大的矩形卡车停在街对面。卡车的侧面有一则广告,写着“Farmer Smith 的顶级牛排”,Bessie 不太理解这则广告,但她更担心的是卡车可能会挡住她最喜欢的两块广告牌的视线。

给定两块广告牌和卡车的位置,请计算两块广告牌仍然可见的总面积。卡车可能遮挡了其中一块、两块,或者没有遮挡任何一块广告牌。

输入格式

输入的第一行包含四个用空格分隔的整数:x1,y1,x2y2x_1,y_1,x_2 y_2,其中 (x1,y1)(x_1,y_1)(x2,y2)(x_2,y_2) 是 Bessie 的二维视野中第一块广告牌的左下角和右上角坐标。第二行包含四个整数,以相同的方式指定第二块广告牌的左下角和右上角坐标。第三行也是最后一行输入包含四个整数,指定卡车的左下角和右上角坐标。所有坐标都在 1000-1000+1000+1000 的范围内。保证两块广告牌之间没有任何重叠的正面积区域。

输出格式

请输出两块广告牌仍然可见的总面积。

说明/提示

在这个例子中,第一块广告牌有 55 单位面积可见,第二块广告牌有 1212 单位面积可见。

题目来源:Brian Dean

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

提示

Here, 5 units of area from the first billboard and 12 units of area from the second billboard remain visible.

Problem credits: Brian Dean