青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

coreBugZJ

此 blog 已棄。

Selling Land,nwerc2010 G

Selling Land
As you may know, the country of Absurdistan is full of abnormalities. For example, the whole
country can be divided into unit squares that are either grass or swamp. Also, the country
is famous for its incapable bureaucrats. If you want to buy a piece of land (called a parcel),
you can only buy a rectangular area, because they cannot handle other shapes. The price of
the parcel is determined by them and is proportional to the perimeter of the parcel, since the
bureaucrats are unable to multiply integers and thus cannot calculate the area of the parcel.

    Per owns a parcel in Absurdistan surrounded by swamp and he wants to sell it, possibly in
parts, to some buyers. When he sells a rectangular part of his land, he is obliged to announce
this to the local bureaucrats. They will first tell him the price he is supposed to sell it for. Then
they will write down the name of the new owner and the coordinates of the south-east corner
of the parcel being sold. If somebody else already owns a parcel with a south-east corner at
the same spot, the bureaucrats will deny the change of ownership.

    Per realizes that he can easily trick the system. He can sell overlapping areas, because
bureaucrats only check whether the south-east corners are identical. However, nobody wants
to buy a parcel containing swamp.

    In this example, dark squares represent swamp. Per may, for example, sell three overlapping grey
areas, with dimensions 2 × 1, 2 × 4 and 4 × 1 respectively. The total perimeter is 6 + 12 + 10 = 28.
Note that he can get more money by selling even more land. This figure corresponds to the case in
the sample input.

    Now Per would like to know how many parcels of each perimeter he needs to sell in order
to maximize his profit. Can you help him? You may assume that he can always find a buyer
for each piece of land, as long as it doesn’t contain any swamps. Also, Per is sure that no
square within his parcel is owned by somebody else.

Input
On the first line a positive integer: the number of test cases, at most 100. After that per test
case:
• One line with two integers n and m (1 ≤ n, m ≤ 1 000): the dimensions of Per’s parcel.
• n lines, each with m characters. Each character is either ‘#’ or ‘.’. The j-th character
on the i-th line is a ‘#’ if position (i, j) is a swamp, and ‘.’ if it is grass. The north-west
corner of Per’s parcel has coordinates (1, 1), and the south-east corner has coordinates
(n, m).

Output
Per test case:
• Zero or more lines containing a complete list of how many parcels of each perimeter
Per needs to sell in order to maximize his profit. More specifically, if Per should sell pi
parcels of perimeter i in the optimal solution, output a single line “pi x i”. The lines
should be sorted in increasing order of i. No two lines should have the same value of i,
and you should not output lines with pi = 0.

Sample in- and output

Input
1
6 5
..#.#
.#...
#..##
...#.
#....
#..#.

Output
6 x 4
5 x 6
5 x 8
3 x 10
1 x 12


比賽時就有思路,可惜時間不夠了,最后階段在沖刺另一題——可惜也是賽后幾分鐘才解決。。。


 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 #define  L  1009
 5 #define  T  (L*4)
 6 
 7 int n, m, cant[ L ][ L ], width[ L ][ L ], height[ L ][ L ];
 8 
 9 void input() {
10         int i, j;
11         char  tmp[ L ];
12         scanf( "%d%d"&n, &m );
13         gets( tmp );
14         for ( i = 1; i <= n; ++i ) {
15                 gets( tmp );
16                 for ( j = 0; j < m; ++j ) {
17                         cant[ i ][ j+1 ] = ( tmp[ j ] == '#' );
18                 }
19         }
20 }
21 
22 void solve() {
23         int i, j, k, most, up[ L ], left[ L ], right[ L ];
24         memset( width, 0sizeof(width) );
25         memset( height, 0sizeof(height) );
26         for ( j = 1; j <= m; ++j ) {
27                 up[ j ] = 1;
28                 left[ j ] = 1;
29                 right[ j ] = m;
30         }
31         for ( i = 1; i <= n; ++i ) {
32                 most = 1;
33                 for ( j = 1; j <= m; ++j ) {
34                         if ( cant[ i ][ j ] ) {
35                                 up[ j ] = i + 1;
36                                 left[ j ] = 1;
37                                 most = j + 1;
38                         }
39                         else if ( most > left[ j ] ) {
40                                 left[ j ] = most;
41                         }
42                 }
43 
44                 most = m;
45                 for ( j = m; j >= 1--j ) {
46                         if ( cant[ i ][ j ] ) {
47                                 most = j - 1;
48                                 right[ j ] = m;
49                         }
50                         else if ( right[ j ] > most ) {
51                                 right[ j ] = most;
52                         }
53                 }
54 
55                 up[ 0 ] = up[ 1 ] - 1;
56                 for ( j = 1; j <= m; ++j ) {
57                         if ( ( cant[ i ][ j ] ) || ( up[ j ] == up[ j - 1 ] ) ) {
58                                 continue;
59                         }
60                         for ( k = left[ j ]; k <= right[ j ]; ++k ) {
61                                 if ( (k-left[j]+1+ (i-up[j]+1> width[i][k] + height[i][k] ) {
62                                         width[ i ][ k ] = k - left[ j ] + 1;
63                                         height[ i ][ k ] = i - up[ j ] + 1;
64                                 }
65                         }
66                 }
67         }
68 }
69 
70 void output() {
71         int cnt[ T ], i, j;
72         memset( cnt, 0sizeof(cnt) );
73         for ( i = 1; i <= n; ++i ) {
74                 for ( j = 1; j <= m; ++j ) {
75                         ++cnt[ ( width[i][j] + height[i][j] ) << 1 ];
76                 }
77         }
78         for ( i = 1; i < T; ++i ) {
79                 if ( cnt[ i ] > 0 ) {
80                         printf( "%d x %d\n", cnt[ i ], i );
81                 }
82         }
83 }
84 
85 int main() {
86         int td;
87         scanf( "%d"&td );
88         while ( td-- > 0 ) {
89                 input();
90                 solve();
91                 output();
92         }
93         return 0;
94 }
95 

posted on 2011-04-29 21:05 coreBugZJ 閱讀(391) 評論(0)  編輯 收藏 引用 所屬分類: ACM

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产一区二区三区精品欧美日韩一区二区三区 | 亚洲日本va午夜在线影院| 男女av一区三区二区色多| 久久精品女人| 亚洲欧洲综合| 99av国产精品欲麻豆| 国产精品久久久久久久久婷婷| 午夜欧美精品久久久久久久| 欧美一区午夜视频在线观看| 在线观看亚洲精品视频| 亚洲精品在线一区二区| 国产精品三级视频| 欧美阿v一级看视频| 欧美日韩免费观看一区| 久久精品99无色码中文字幕| 久热精品视频在线观看一区| 亚洲美女色禁图| 亚洲一区在线视频| 在线成人欧美| 亚洲图片欧美日产| 在线欧美日韩| 亚洲嫩草精品久久| 亚洲三级观看| 午夜精品美女久久久久av福利| 亚洲成人中文| 午夜视频在线观看一区二区三区| 亚洲高清中文字幕| 亚洲欧美综合网| 亚洲精品免费电影| 欧美专区亚洲专区| 中国成人在线视频| 久久人人97超碰人人澡爱香蕉| 国产精品99久久久久久久久| 久久久蜜桃精品| 欧美一二区视频| 欧美激情一区二区三区全黄| 久久日韩粉嫩一区二区三区| 欧美先锋影音| 91久久精品国产91久久性色| 国产日韩久久| 亚洲午夜小视频| 一本色道久久综合狠狠躁篇的优点| 久久成人免费| 久久精品视频网| 国产精品爽爽ⅴa在线观看| 亚洲人成网站在线观看播放| 136国产福利精品导航| 欧美中文字幕在线| 久久精品成人| 国产一区二区看久久| 亚洲永久免费av| 亚洲永久免费| 欧美视频中文在线看| 亚洲伦理中文字幕| 9人人澡人人爽人人精品| 免费亚洲一区二区| 欧美激情aaaa| 亚洲三级免费| 欧美日韩123| 亚洲精品日日夜夜| 一区二区三区高清| 欧美日韩一区二区免费视频| 亚洲人成人一区二区三区| 亚洲国产专区| 欧美精品九九99久久| 亚洲精品少妇30p| 亚洲亚洲精品三区日韩精品在线视频| 欧美激情视频网站| 亚洲毛片视频| 欧美亚洲视频一区二区| 国产精品欧美日韩一区| 欧美一区二区三区免费观看| 久久久久9999亚洲精品| 韩国在线一区| 欧美77777| 一区二区久久久久| 欧美一区在线视频| 好吊色欧美一区二区三区视频| 久久久夜夜夜| 亚洲激情电影在线| 亚洲欧美在线播放| 狠狠色综合色综合网络| 免费观看一区| 中文在线不卡视频| 久久久99精品免费观看不卡| 亚洲国产免费看| 欧美日韩伦理在线免费| 亚洲欧美激情诱惑| 美女啪啪无遮挡免费久久网站| 亚洲精品极品| 国产精品一区二区三区乱码| 久久免费少妇高潮久久精品99| 亚洲国产高清aⅴ视频| 亚洲欧美日本精品| 在线观看视频一区| 欧美天天影院| 久久视频在线免费观看| 一区二区免费在线播放| 久久一区欧美| 亚洲先锋成人| 亚洲黄网站黄| 国产亚洲欧美色| 欧美伦理一区二区| 久久精品国产99| 亚洲视频第一页| 亚洲国产经典视频| 久久精品国产免费| 亚洲色图制服丝袜| 亚洲国产精品传媒在线观看 | 亚洲视频香蕉人妖| 伊人成人网在线看| 国产精品高潮呻吟| 欧美a级一区| 久久er99精品| 亚洲女爱视频在线| 一本久道久久综合婷婷鲸鱼| 欧美激情视频一区二区三区在线播放 | 可以看av的网站久久看| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 中文精品视频| 亚洲精品国久久99热| 国产亚洲aⅴaaaaaa毛片| 欧美日一区二区三区在线观看国产免| 久久人人九九| 欧美在线网站| 午夜视频久久久| 亚洲一区影院| 正在播放亚洲一区| 一本色道久久精品| 亚洲精品中文字幕在线| 亚洲国产精品久久久久秋霞不卡| 老鸭窝毛片一区二区三区| 久久久久久久综合日本| 欧美在线视频免费观看| 亚洲欧美美女| 午夜在线一区| 欧美一区午夜精品| 欧美一区二区三区在线看 | 亚洲欧美激情精品一区二区| 中文一区二区在线观看| 一区二区三区免费网站| 中国成人在线视频| 亚洲综合色丁香婷婷六月图片| 99视频在线精品国自产拍免费观看| 亚洲人成网站999久久久综合| 亚洲电影自拍| 99天天综合性| 亚洲一区二区三区欧美| 午夜视黄欧洲亚洲| 久久久999精品视频| 裸体歌舞表演一区二区| 亚洲国产91| 亚洲美女中文字幕| 亚洲一区999| 久久精品国产亚洲精品| 免费成人高清在线视频| 欧美日韩国产欧| 国产目拍亚洲精品99久久精品| 国产日韩视频| 亚洲人线精品午夜| 亚洲一区二区黄| 久久综合九色99| 亚洲国内自拍| 亚洲一区一卡| 老司机免费视频久久| 欧美人成在线视频| 国产精品一区久久久久| 亚洲国产成人精品视频| 99视频超级精品| 午夜精品一区二区三区四区| 久久综合久久久久88| 亚洲精品影院| 久久国产精品亚洲va麻豆| 欧美二区视频| 国产午夜精品久久久久久久| 亚洲黑丝在线| 欧美一区二区视频在线观看| 欧美成人在线免费观看| 一本色道精品久久一区二区三区| 欧美亚洲一区在线| 欧美日韩国产一中文字不卡| 狠久久av成人天堂| 亚洲一区亚洲二区| 欧美激情网友自拍| 性18欧美另类| 欧美视频在线观看 亚洲欧| 精品动漫3d一区二区三区免费| 亚洲一区二区三区四区视频| 欧美大成色www永久网站婷| 亚洲在线视频| 欧美日韩国产欧| 亚洲黄色一区| 麻豆国产精品va在线观看不卡| 日韩网站在线| 欧美丰满少妇xxxbbb| 一区二区在线视频观看| 久久精品免费电影| 亚洲亚洲精品在线观看 | 久久久欧美一区二区| 国产精品欧美日韩|