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

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 閱讀(401) 評論(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>
            午夜日韩福利| 久久久久欧美精品| 欧美午夜女人视频在线| 一本久久知道综合久久| 一区二区三区四区蜜桃| 国产精品少妇自拍| 久久精品国产99国产精品| 性欧美大战久久久久久久免费观看| 国产欧美精品一区二区色综合 | 亚洲黄色高清| 亚洲激情国产| 欧美日韩在线免费视频| 午夜精品久久| 久久夜色精品一区| 99re视频这里只有精品| 亚洲图片在区色| 激情自拍一区| 亚洲精品免费看| 国产精品免费久久久久久| 久久人人精品| 欧美激情一区二区三区四区| 性做久久久久久久免费看| 久久亚洲图片| 亚洲欧美综合一区| 久久一区国产| 亚洲欧美在线x视频| 久久午夜电影| 欧美一区二区三区四区在线观看地址| 久久全国免费视频| 亚洲一区在线观看视频| 久久夜色撩人精品| 欧美一级视频精品观看| 欧美www视频| 久久激情视频免费观看| 欧美激情区在线播放| 欧美在线黄色| 欧美性久久久| 欧美国产视频一区二区| 国产精品综合色区在线观看| 亚洲激情在线| 亚洲国产婷婷香蕉久久久久久99| 亚洲免费在线播放| 一本色道久久综合亚洲精品小说 | 国产亚洲精品aa| 亚洲欧洲精品一区二区精品久久久| 国产性做久久久久久| 亚洲看片一区| 亚洲乱码精品一二三四区日韩在线 | 亚洲男人第一网站| 欧美 日韩 国产一区二区在线视频| 久久精品一区二区国产| 国产精品激情电影| 99精品免费网| 一区二区免费在线播放| 玖玖玖免费嫩草在线影院一区| 久久福利毛片| 国产欧美一区二区三区另类精品 | 欧美人交a欧美精品| 毛片基地黄久久久久久天堂| 国产深夜精品福利| 亚洲永久免费观看| 午夜精品亚洲一区二区三区嫩草| 欧美日韩一二三四五区| 亚洲精品三级| 亚洲深夜激情| 欧美日韩综合| 亚洲一区免费| 欧美亚洲一区二区在线观看| 国产欧美欧美| 欧美在线免费视屏| 久久午夜电影网| 激情欧美丁香| 美日韩精品视频免费看| 欧美黄污视频| 99精品视频免费在线观看| 欧美日韩的一区二区| 艳妇臀荡乳欲伦亚洲一区| 亚洲精品久久嫩草网站秘色 | 老司机免费视频一区二区三区| 麻豆精品精华液| 亚洲欧洲一区二区天堂久久| 欧美日韩aaaaa| 日韩一区二区免费高清| 亚洲欧美日韩精品在线| 国产有码在线一区二区视频| 久久久亚洲国产天美传媒修理工| 欧美国产乱视频| 一区二区欧美在线| 国产精品素人视频| 久久久久久一区| 亚洲精品国产拍免费91在线| 亚洲欧美成人综合| 国产一区二区三区无遮挡| 麻豆成人av| 99视频日韩| 久久久久久久久蜜桃| 亚洲第一中文字幕| 欧美日韩一区二区高清| 欧美制服第一页| 日韩网站在线| 久久中文字幕一区| 一区二区日韩| 一区二区亚洲精品国产| 欧美日韩不卡一区| 欧美一区二区性| 亚洲毛片在线看| 久久久免费观看视频| 一区二区精品| 尤物精品在线| 国产精品自拍网站| 欧美xart系列在线观看| 欧美一区二区播放| 日韩视频在线免费观看| 老司机一区二区三区| 亚洲女女女同性video| 伊人久久av导航| 国产精品自拍三区| 欧美日韩国产高清| 噜噜噜在线观看免费视频日韩| 亚洲天堂av在线免费观看| 亚洲成人自拍视频| 久久久国产成人精品| 亚洲专区欧美专区| 日韩亚洲一区在线播放| 黄色亚洲网站| 国产欧美日韩综合| 欧美特黄一区| 欧美日韩一区二区在线| 欧美777四色影视在线| 久久国产欧美日韩精品| 亚洲欧美日韩区| 中文日韩在线| 日韩一级大片在线| 亚洲激情午夜| 亚洲三级毛片| 亚洲国产精品999| 久久综合九色| 久久综合伊人77777蜜臀| 久久九九全国免费精品观看| 午夜在线播放视频欧美| 午夜精品久久久久| 亚洲欧美综合精品久久成人| 亚洲女同在线| 午夜精品美女自拍福到在线 | 一区二区三区免费观看| 亚洲激情偷拍| 亚洲乱码一区二区| 日韩视频永久免费| 99精品久久| 亚洲女人小视频在线观看| 亚洲一区精彩视频| 亚洲欧美第一页| 久久精品视频va| 老司机成人在线视频| 欧美国产日韩一二三区| 欧美激情亚洲视频| 亚洲国产一区视频| 日韩午夜电影在线观看| 一区二区三区日韩精品视频| 午夜宅男久久久| 久久精品五月婷婷| 欧美成人69av| 欧美色另类天堂2015| 国产麻豆日韩欧美久久| 一区二区在线观看视频| 亚洲片国产一区一级在线观看| 亚洲最新色图| 欧美一区二区精品久久911| 久久久91精品国产一区二区三区| 免费不卡亚洲欧美| 亚洲韩国精品一区| 亚洲一区在线播放| 欧美一级免费视频| 免费国产一区二区| 国产精品分类| 亚洲第一精品影视| 亚洲图片在线| 欧美sm极限捆绑bd| 亚洲视频一区二区| 久久久久久久欧美精品| 欧美午夜精品久久久久久孕妇| 国产亚洲综合精品| 99精品视频一区| 久久免费视频网站| 亚洲人体影院| 久久久www免费人成黑人精品 | 国产精品二区三区四区| 国内久久视频| 中文欧美日韩| 欧美wwwwww| 亚洲免费人成在线视频观看| 老鸭窝91久久精品色噜噜导演| 国产精品欧美日韩| 亚洲精品黄网在线观看| 久久精品中文字幕一区| 亚洲最快最全在线视频| 久久综合图片| 好看的日韩av电影| 午夜国产精品视频免费体验区| 亚洲成色777777女色窝|