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

Tim's Programming Space  
Tim's Programming Space
日歷
<2010年7月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
統計
  • 隨筆 - 20
  • 文章 - 1
  • 評論 - 40
  • 引用 - 0

導航

常用鏈接

留言簿(3)

隨筆檔案

文章檔案

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

 

The Alliances

In a fantasy world, there is a large island of a rectangular shape. The sides of the island happen to be exactly R miles and C miles long, and the whole island is divided into a grid of R\times C areas. Some of the areas are uninhabited, and the rest are occupied by villages of fantasy beings: elves, humans, dwarves, and hobbits. Each area contains at most one village. Two villages are considered neighbours if their areas share a side.

Recently, the villages became terrified of the Great Evil. In order to feel safer, each village has decided to form military alliances with some of its neighbours. An alliance always involves two neighbouring villages, and it is a mutual and symmetric agreement.

Depending on the species living in the village, the inhabitants will not feel safe unless a specific configuration of alliances is formed:

  • The elves feel confident, and therefore need exactly one alliance.
  • Human villages require alliances with exactly two neighbours.
    Moreover, leaving two opposite sides of the village exposed is bad for tactical reasons. Therefore the two allied neighbours cannot be located on opposite sides of the village.
  • Dwarves require alliances with exactly three neighbours.
  • Hobbits are extremely scared, and therefore need to have alliances with all four of their neighbours.

In other words, except for humans each village requires a particular number of alliances, but does not care which neighbours will be its allies. For humans there is an additional restriction: the allied neighbours must not be on opposite sides of the village.

The conditions must be fulfilled irrespective of the position of the village on the map. For example, a dwarf village desires three alliances. If it is located on the coast, this means that it must have alliances with all three neighbours. If there is a dwarf village in a corner of the island, its inhabitants will never feel safe.

Task specification

For a given island description, your task is to decide whether it is possible to form alliances so that all inhabitants of the island will feel safe. In case of a positive answer, your task is also to suggest one viable configuration of alliances. In case of multiple solutions, choose an arbitrary one.

Input specification

The first line of the input contains two integers R and C specifying the size of the island. The following R lines encode a description of the island. Each line consists of C space-separated numbers between 0 and 4:

  • 0 means uninhabited area,
  • 1 means an elf village,
  • 2 means a human village,
  • 3 means a dwarf village.
  • 4 means a hobbit village,

(Note that the number in the input always corresponds to the number of desired alliances for that village.)

Constraints

In all test cases assume that 1 \leq R,C \leq 70.

In test cases worth a total of 55 points we have \min(R,C) \leq 10. Out of these, in test cases worth 15 points R\cdot C \leq 20.

Another batch of test cases worth 10 points contains maps with only uninhabited areas and human villages. (This batch is not included in the test cases worth 55 points.)

Output specification

If there is no solution, output a single line with the string "Impossible!" (quotes for clarity). Otherwise, output one valid map of alliances in the following format.

Each area should appear in the output as a matrix of 3 \times 3 characters. If the area is uninhabited, the corresponding section of the output will be filled with . (dot) symbols. If the area has a village there should be a a symbol O (uppercase letter O) in the middle representing the village itself, and there should be symbols X (uppercase letter X) representing a configuration of its allies. The rest of the 3\times 3 matrix should be filled with . (dot) symbols.

For each village type, all possible layouts of alliances are shown in the image below.

Examples

input:

3 4
2 3 2 0
3 4 3 0
2 3 3 1

output:

............
.OXXOXXO....
.X..X..X....
.X..X..X....
.OXXOXXO....
.X..X..X....
.X..X..X....
.OXXOXXOXXO.
............

input:

1 2
2 1

output:

Impossible!


這是 CEOI2010 當場唯一會做的。。。
題目大意是:告訴一個70*70的格子里面每個點的度,每個格子只能往四周的四個格子連邊,邊是雙向的,對于度為2的點所連的兩條邊不能在一條直線上,求出一組方案。
============================
如果沒有對度為2的點連邊的限制的話,就把格子黑白染色,建二分圖,相鄰的點連容量為1的邊,黑點連源,白點連匯,容量都為要求的度。流之即可。
加上對度為2的點連邊的限制,這樣的方法出現的問題在于沒法處理這個問題了。
但我們發現,對于度為2的點的限制可以化為:橫向或者縱向都有且只有一條邊,于是把度為2的點拆成橫的和豎的兩個點就行了。

/*
 * $File: alliances.cpp
 * $Date: Thu Jul 15 11:18:14 2010 +0800
 * $Prob: CEOI 2010 The Alliances
 * $Author: Tim
 * $Addr: 
http://riesky.sk/ceoi2010/problem.php?contest=CEOI%202010%20Day%201&problem=alliances
 
*/

#include 
<cstdio>
#include 
<cstring>
#include 
<cstdlib>

#define MAXL 71
#define MAXN (MAXL * MAXL * 2 + 10)
#define MAXM (MAXN * 4 + MAXN + MAXN) * 2


#define INFINITE 0x3f3f3f3f
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define OP(x) ((((x) - 1) ^ 1) + 1)

#define OP_DIR(x) ((x + 2) & 3)

using namespace std;

const int fx[] = {010-1};
const int fy[] = {10-10};
const int UP    = 3,
          DOWN    
= 1,
          LEFT    
= 2,
          RIGHT 
= 0;


int map[MAXL + 1][MAXL + 1];
int n, m;
void Init()
{
    scanf(
"%d%d"&n, &m);
    
for (int i = 0; i < n; i ++)
        
for (int j = 0; j < m; j ++)
            scanf(
"%d"&map[i][j]);
}

int N = 2, S = 0, T = 1;
int id[MAXL + 1][MAXL + 1][2];
int ID(int x, int y, int flag)
{
    
if (id[x][y][flag])
        
return id[x][y][flag];
    
return id[x][y][flag] = N ++;
}

int edge_id[MAXL + 1][MAXL + 1][4];
int Count = 0;
int begin[MAXN + 1], end[MAXM + 1], next[MAXM + 1], c[MAXM + 1];
void AddEdge(int a, int b, int f)
{
    Count 
++;
    next[Count] 
= begin[a];
    begin[a] 
= Count;
    end[Count] 
= b;
    c[Count] 
= f;

    Count 
++;
    next[Count] 
= begin[b];
    begin[b] 
= Count;
    end[Count] 
= a;
    c[Count] 
= 0;
}

int tot_flow[2];
void BuildGraph()
{
        
for (int i = 0; i < n; i ++)
        
for (int j = 0; j < m; j ++)
            
if (map[i][j])
            {
                
if ((i + j) & 1)
                {
                    
for (int k = 0; k < 4; k ++)
                    {
                        
int x = i + fx[k], y = j + fy[k];
                        
if (x >= 0 && x < n && y >= 0 && y < m && map[x][y])
                        {
                            AddEdge(ID(i, j, (map[i][j] 
== 2 ? (k & 1) : 0)), 
                                    ID(x, y, (map[x][y] 
== 2 ? (k & 1) : 0)),
                                    
1);
                            edge_id[i][j][k] 
= edge_id[x][y][OP_DIR(k)] = Count;
                        }
                    }
                    
if (map[i][j] == 2)
                    {
                        AddEdge(S, ID(i, j, 
0), 1);
                        AddEdge(S, ID(i, j, 
1), 1);
                    }
                    
else
                        AddEdge(S, ID(i, j, 
0), map[i][j]);
                }
                
else
                {
                    
if (map[i][j] == 2)
                    {
                        AddEdge(ID(i, j, 
0), T, 1);
                        AddEdge(ID(i, j, 
1), T, 1);
                    }
                    
else
                        AddEdge(ID(i, j, 
0), T, map[i][j]);
                }
                tot_flow[(i 
+ j) & 1+= map[i][j];
            }
}
int cur[MAXN + 1], d[MAXN + 1], pre[MAXN + 1], a[MAXN + 1], cnt[MAXN + 1];
int sap()
{
    
int flow = 0, now, tmp, u;
    a[u 
= S] = INFINITE;
    cnt[
0= N;
    memcpy(cur, begin, 
sizeof(begin[0]) * N);
    
while (d[S] < N)
    {
        
for (now = cur[u]; now; now = next[now])
            
if (c[now] && d[u] == d[end[now]] + 1)
                
break;
        
if (now)
        {
            tmp 
= end[now];
            pre[tmp] 
= cur[u] = now;
            a[tmp] 
= MIN(a[u], c[now]);
            
if ((u = tmp) == T)
            {
                flow 
+= (tmp = a[T]);
                
do
                {
                    c[pre[u]] 
-= tmp;
                    c[OP(pre[u])] 
+= tmp;
                    u 
= end[OP(pre[u])];
                }
                
while (u != S);
                a[S] 
= INFINITE;
            }
        }
        
else
        {
            
if ((--cnt[d[u]]) == 0)
                
break;
            cur[u] 
= begin[u], d[u] = N;
            
for (now = begin[u]; now; now = next[now])
                
if (c[now] && d[u] > d[end[now]] + 1)
                    d[u] 
= d[end[now]] + 1, cur[u] = now;
            cnt[d[u]] 
++;
            
if (u != S)
                u 
= end[OP(pre[u])];
        }
    }
    
return flow;
}

bool ans;
void Solve()
{
    BuildGraph();
    ans 
= true;
    
if (tot_flow[0!= tot_flow[1])
        ans 
= false;
    
else if (sap() != tot_flow[0])
        ans 
= false;
}

void Print()
{
    
if (!ans)
        puts(
"Impossible!");
    
else
    {
        
for (int i = 0; i < n; i ++)
        {
            
for (int j = 0; j < m; j ++)
            {
                printf(
"%c"'.');
                printf(
"%c", c[edge_id[i][j][UP]] ? 'X' : '.');
                printf(
"%c"'.');
            }
            printf(
"\n");
            
for (int j = 0; j < m; j ++)
            {
                printf(
"%c", c[edge_id[i][j][LEFT]] ? 'X' : '.');
                printf(
"%c", map[i][j] ? 'O' : '.');
                printf(
"%c", c[edge_id[i][j][RIGHT]] ? 'X' : '.');
            }
            printf(
"\n");
            
for (int j = 0; j < m; j ++)
            {
                printf(
"%c"'.');
                printf(
"%c", c[edge_id[i][j][DOWN]] ? 'X' : '.');
                printf(
"%c"'.');
            }
            printf(
"\n");
        }
    }
}

int main()
{
    freopen(
"alliances.in""r", stdin);
    freopen(
"alliances.out""w", stdout);
    Init();
    Solve();
    Print();
    
return 0;
}

posted on 2010-07-15 11:19 TimTopCoder 閱讀(1885) 評論(1)  編輯 收藏 引用
評論:

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


 
Copyright © TimTopCoder Powered by: 博客園 模板提供:滬江博客
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美大片免费久久精品三p| 欧美高潮视频| 国产精品女人网站| 亚洲午夜久久久| 亚洲欧洲在线免费| 欧美超级免费视 在线| 伊人夜夜躁av伊人久久| 免费在线播放第一区高清av| 久久精品国产99国产精品| 韩国成人理伦片免费播放| 久久夜色精品国产欧美乱| 欧美一区二区免费观在线| 国产欧美日韩精品专区| 久久九九免费视频| 久久午夜羞羞影院免费观看| 亚洲国产天堂久久国产91| 亚洲国产岛国毛片在线| 欧美日韩情趣电影| 午夜免费日韩视频| 亚洲欧美日本伦理| 国内伊人久久久久久网站视频| 美女日韩在线中文字幕| 欧美成人影音| 午夜久久99| 久久久无码精品亚洲日韩按摩| 亚洲精品在线一区二区| 一区二区高清视频在线观看| 国产亚洲欧美一区二区| 欧美高清在线| 国产精品成人av性教育| 裸体女人亚洲精品一区| 欧美日韩国产天堂| 欧美亚洲一区二区在线观看| 久久在线视频| 亚洲欧美久久| 欧美~级网站不卡| 亚洲一区在线视频| 久久在线播放| 香蕉久久国产| 你懂的国产精品永久在线| 亚洲欧美另类国产| 麻豆精品一区二区av白丝在线| 亚洲欧美成人网| 美日韩精品免费观看视频| 性欧美1819性猛交| 欧美国产日韩二区| 久久影视精品| 国产精品普通话对白| 亚洲国产影院| 亚洲国产成人av好男人在线观看| 亚洲新中文字幕| 亚洲六月丁香色婷婷综合久久| 欧美在线视频二区| 亚洲一区在线直播| 欧美大片一区二区| 久久色中文字幕| 国产日韩欧美高清免费| 日韩亚洲欧美成人| 亚洲片在线资源| 久久人人爽人人爽爽久久| 欧美亚洲在线播放| 国产精品jizz在线观看美国| 91久久精品国产91性色tv| 激情成人综合网| 欧美中文在线观看国产| 亚洲欧美国产精品专区久久| 欧美日韩国产综合在线| 亚洲国产精品一区在线观看不卡| 亚洲国产欧美国产综合一区| 久久久久久日产精品| 久久亚洲欧美| 一区二区三区在线视频观看| 久久久蜜桃精品| 久久婷婷蜜乳一本欲蜜臀| 国产一区在线播放| 欧美一区二区视频观看视频| 欧美一区二区三区久久精品| 国产伦精品一区二区三区视频孕妇 | 亚洲欧美国产另类| 午夜精品婷婷| 国产精品一区二区在线| 欧美亚洲网站| 美女日韩在线中文字幕| 在线精品一区| 欧美激情免费在线| 亚洲精品乱码久久久久久蜜桃麻豆 | 久久国产欧美日韩精品| 久久久噜噜噜久久中文字幕色伊伊| 国产一区二区三区久久久| 久久精品国产精品亚洲| 蜜桃av噜噜一区| 亚洲精品一区二| 欧美三级韩国三级日本三斤| 夜夜嗨av一区二区三区四季av | 亚洲国产成人av在线| 蜜桃av一区二区| 亚洲人成在线观看一区二区 | 国产亚洲一级高清| 久久全球大尺度高清视频| 欧美大片在线观看| 一本大道久久a久久精二百| 国产精品高潮呻吟视频| 久久精品成人欧美大片古装| 久热精品视频在线观看| 99re热精品| 国产麻豆一精品一av一免费| 久久久久久久97| 日韩午夜在线| 久久久综合免费视频| 亚洲精品一区在线观看香蕉| 国产九区一区在线| 欧美大胆a视频| 欧美一区二区高清| 91久久久在线| 久久精品国产69国产精品亚洲 | 国产香蕉久久精品综合网| 免费观看欧美在线视频的网站| 一区二区欧美日韩视频| 老司机精品视频网站| 亚洲先锋成人| 在线观看视频一区二区| 国产精品高潮呻吟久久av无限| 老司机精品导航| 亚洲视频久久| 亚洲国产婷婷综合在线精品 | 亚洲在线一区二区| 亚洲第一区在线观看| 欧美色图天堂网| 久热综合在线亚洲精品| 亚洲欧美www| 99在线视频精品| 亚洲国产视频a| 欧美aⅴ一区二区三区视频| 欧美一区二区免费| 亚洲影音先锋| 一本一本久久a久久精品牛牛影视| 国内精品免费午夜毛片| 国产欧美日韩视频在线观看| 欧美日韩在线一二三| 欧美成人免费在线观看| 久久午夜羞羞影院免费观看| 午夜在线电影亚洲一区| 宅男精品视频| 99国产一区二区三精品乱码| 亚洲精品1234| 亚洲国产成人精品女人久久久 | 一区二区欧美激情| 91久久久久久| 亚洲国内精品在线| 亚洲国产成人精品久久久国产成人一区| 国产日韩综合| 国产性做久久久久久| 国产模特精品视频久久久久 | 久久久五月婷婷| 久久久噜噜噜久噜久久| 久久久久国产精品午夜一区| 欧美伊人久久| 久久精品一二三| 久久久综合精品| 蜜臀av一级做a爰片久久| 美日韩精品视频| 欧美成人亚洲成人| 欧美激情一区二区三区在线| 欧美日韩日本网| 国产精品美女久久久免费| 国产女主播视频一区二区| 国产日产高清欧美一区二区三区| 国产日产欧美精品| 精品99一区二区三区| 亚洲欧洲美洲综合色网| 亚洲视频免费| 久久国产一二区| 美女黄毛**国产精品啪啪| 亚洲国产日韩欧美在线图片| 亚洲裸体视频| 午夜亚洲福利在线老司机| 久久精品毛片| 老鸭窝毛片一区二区三区| 欧美日韩精品久久久| 国产精品尤物福利片在线观看| 国产综合视频| 日韩视频免费在线观看| 午夜欧美不卡精品aaaaa| 老司机凹凸av亚洲导航| 亚洲人www| 欧美亚洲视频在线观看| 免费高清在线一区| 国产精品丝袜白浆摸在线| 精品成人一区二区三区四区| 一二三区精品福利视频| 久久精视频免费在线久久完整在线看| 久久日韩精品| 一本久道久久综合中文字幕| 久久经典综合| 欧美日韩美女在线| 韩国免费一区| 亚洲欧美日韩一区二区在线| 亚洲成人在线视频播放| 亚洲综合精品一区二区| 欧美极品影院|