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

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>
            欧美一区二区三区在线播放| 亚洲午夜高清视频| 蜜桃av一区二区在线观看| 欧美搞黄网站| 亚洲免费观看高清在线观看| 欧美日韩一区二区三区在线| 一区二区三区日韩精品视频| 欧美在线视频日韩| 亚洲国产精品久久久久婷婷884| 欧美国产日韩一区二区| 一区二区三区三区在线| 久久久之久亚州精品露出| 亚洲国产成人91精品| 欧美视频在线观看免费网址| 亚洲欧美资源在线| 欧美福利影院| 亚洲欧美中日韩| 在线精品国精品国产尤物884a| 欧美精品xxxxbbbb| 午夜精品久久| 亚洲欧洲美洲综合色网| 性高湖久久久久久久久| 亚洲第一精品在线| 国产精品久久久久久久久久久久| 欧美综合二区| 一区二区高清| 欧美不卡高清| 欧美伊久线香蕉线新在线| 亚洲精品国久久99热| 国产女人aaa级久久久级| 免费不卡中文字幕视频| 亚洲欧美日韩一区在线观看| 欧美黄色片免费观看| 欧美在线91| 宅男噜噜噜66一区二区| 亚洲电影免费观看高清| 国产精品一区二区三区乱码| 欧美精品色综合| 久久精品视频在线观看| 一区二区三区视频在线观看 | 欧美成人激情视频| 欧美一级播放| 中日韩午夜理伦电影免费| 亚洲缚视频在线观看| 国产日韩欧美一二三区| 欧美天天在线| 欧美区日韩区| 欧美91大片| 久久青草福利网站| 久久国产精品久久久| 亚洲一区bb| 一区二区三区成人| 亚洲精品中文字幕女同| 亚洲第一精品夜夜躁人人躁| 老司机67194精品线观看| 欧美一区二粉嫩精品国产一线天| 亚洲图片欧洲图片av| 日韩亚洲欧美综合| 亚洲精品一区二区三区福利| 一区二区三区中文在线观看| 国内精品美女av在线播放| 国产人妖伪娘一区91| 国产乱码精品1区2区3区| 国产精品成人免费| 欧美视频在线一区| 欧美午夜大胆人体| 欧美视频在线播放| 欧美调教视频| 国产精品porn| 国产欧美短视频| 国产欧美日韩亚州综合| 国产日韩亚洲欧美精品| 国内外成人免费激情在线视频| 国产视频一区欧美| 狠狠综合久久| 在线观看成人网| 亚洲国产精品视频一区| 亚洲日本电影| 一区二区三区欧美视频| 亚洲欧美国内爽妇网| 性欧美1819性猛交| 久久另类ts人妖一区二区| 另类激情亚洲| 亚洲国产婷婷香蕉久久久久久99 | 亚洲欧洲美洲综合色网| 亚洲精品乱码久久久久久久久 | 亚洲一区在线播放| 性xx色xx综合久久久xx| 久久久久久网址| 欧美成人精品在线播放| 欧美日韩亚洲另类| 国产精品一区二区黑丝| 樱桃视频在线观看一区| 亚洲精品欧美精品| 午夜国产精品视频| 久久综合999| 亚洲人成毛片在线播放女女| 亚洲天堂成人| 久久久久久久综合日本| 欧美国产日本在线| 国产精品视频一二| 在线观看视频日韩| 亚洲视频中文| 久久婷婷亚洲| 99这里只有精品| 久久高清免费观看| 欧美日韩成人在线播放| 国产老女人精品毛片久久| 在线日韩日本国产亚洲| 亚洲视频一起| 美腿丝袜亚洲色图| 亚洲视频综合在线| 久久综合中文色婷婷| 国产精品久久久久久亚洲调教| 国产又爽又黄的激情精品视频| 日韩性生活视频| 久久精品国产亚洲aⅴ| 亚洲国产精品久久91精品| 亚洲欧美日韩国产综合在线| 欧美刺激性大交免费视频| 国产女同一区二区| 亚洲作爱视频| 媚黑女一区二区| 亚洲欧美综合| 欧美涩涩网站| 亚洲精品美女久久7777777| 久久狠狠婷婷| 夜夜躁日日躁狠狠久久88av| 久热爱精品视频线路一| 国产欧美一区二区精品婷婷| 夜夜精品视频一区二区| 欧美成人性网| 久久国产直播| 国产日韩在线一区| 在线亚洲观看| 亚洲激情在线播放| 久久男女视频| 国内成+人亚洲+欧美+综合在线| 亚洲尤物视频网| 亚洲日本久久| 免费黄网站欧美| 精品成人国产在线观看男人呻吟| 午夜久久一区| 在线视频精品一区| 欧美日韩色一区| 日韩网站在线| 亚洲福利视频一区二区| 久久九九热re6这里有精品| 国产日本欧美一区二区三区在线 | 一区二区三区欧美日韩| 欧美国产精品日韩| 久久久人成影片一区二区三区观看 | 一本色道久久综合亚洲精品不| 欧美成人激情在线| 久久精品毛片| 黄色亚洲网站| 另类av一区二区| 久久成人精品无人区| 国产又爽又黄的激情精品视频| 欧美在线视频在线播放完整版免费观看| 一本色道久久综合亚洲精品婷婷| 欧美激情一区二区三区不卡| 亚洲精品综合在线| 亚洲激情在线观看| 欧美日本韩国在线| 亚洲无限乱码一二三四麻| 日韩手机在线导航| 欧美三级在线| 午夜精品久久久| 性色av香蕉一区二区| 国产主播一区二区三区四区| 久久久久免费视频| 久久久噜噜噜久久| 亚洲激情中文1区| 亚洲精品国产视频| 欧美午夜三级| 欧美专区亚洲专区| 久久久久国产免费免费| 亚洲国产你懂的| 亚洲精品男同| 国产精品一二三四| 久久综合伊人77777麻豆| 美女图片一区二区| 一区二区三区高清不卡| 亚洲一区二区精品| 黑人巨大精品欧美一区二区| 欧美电影专区| 欧美手机在线| 久久精品免费| 美女主播一区| 亚洲一区二区在线视频| 欧美一区二区网站| 最新日韩精品| 亚洲一区二区三区免费在线观看| 韩国成人福利片在线播放| 亚洲黑丝在线| 国产精品一区二区在线观看| 欧美不卡视频| 国产精品另类一区| 欧美激情片在线观看|