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

Tim's Programming Space  
Tim's Programming Space
日歷
<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
統(tǒng)計(jì)
  • 隨筆 - 20
  • 文章 - 1
  • 評(píng)論 - 40
  • 引用 - 0

導(dǎo)航

常用鏈接

留言簿(3)

隨筆檔案

文章檔案

搜索

  •  

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

 

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

/*
 * $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 閱讀(1869) 評(píng)論(1)  編輯 收藏 引用
評(píng)論:

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   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>
            欧美中文字幕在线播放| 欧美激情中文不卡| 欧美成年人网站| 久久久国产一区二区| 玖玖玖国产精品| 欧美韩日精品| 99精品视频一区| 欧美大片免费久久精品三p| 欧美精品色网| 亚洲免费观看| 中日韩高清电影网| 欧美一区二区私人影院日本| 久久国产欧美精品| 欧美成人国产一区二区| 欧美丝袜一区二区三区| 免费成人av在线| 91久久精品国产| 亚洲黄色一区| 欧美在线电影| 欧美国产三区| 国内精品久久久| 亚洲精品资源| 久久久久久香蕉网| 亚洲理伦在线| 久久婷婷综合激情| 欧美性大战久久久久久久蜜臀| 国外精品视频| 亚洲欧美日本在线| 欧美激情国产高清| 亚洲欧美国产日韩天堂区| 麻豆精品传媒视频| 国产欧美日韩亚洲| 亚洲午夜激情| 亚洲欧洲一区二区三区| 久久国产精品久久w女人spa| 欧美先锋影音| 一区二区三区国产在线观看| 欧美大片免费观看| 欧美在线视频免费播放| 欧美日韩久久精品| 91久久久精品| 欧美va天堂在线| 欧美一级久久| 国产精品一区视频| 亚洲午夜久久久久久尤物| 欧美福利小视频| 久久久国产一区二区| 国产精品网站视频| 中文精品视频| 亚洲精品一区中文| 欧美精品国产| 亚洲精品久久久久久下一站| 蜜桃av一区二区三区| 欧美一区二区三区的| 国产乱码精品一区二区三区忘忧草| 亚洲最新中文字幕| 亚洲高清不卡| 免费看亚洲片| 国内自拍一区| 麻豆久久婷婷| 久久亚洲综合网| 在线日韩欧美视频| 欧美va天堂| 欧美大学生性色视频| 日韩午夜电影av| 久久久国产91| 黄色一区二区在线| 久久久噜噜噜久久| 久久在线精品| 亚洲日本成人女熟在线观看| 欧美高清自拍一区| 你懂的国产精品永久在线| 亚洲国产天堂久久综合网| 欧美国产日韩二区| 欧美久久视频| 亚洲欧美中文日韩v在线观看| 亚洲私人影院| 国产综合一区二区| 亚洲国产经典视频| 欧美视频官网| 久久久高清一区二区三区| 六月丁香综合| 亚洲在线视频网站| 久久av一区二区三区漫画| 亚洲黄网站在线观看| 日韩亚洲不卡在线| 国产精品男gay被猛男狂揉视频| 久久精品一区| 欧美精品免费在线| 久久激五月天综合精品| 免费看精品久久片| 午夜视频在线观看一区| 欧美亚洲免费在线| 日韩视频免费| 性欧美xxxx大乳国产app| 亚洲国产精品综合| 亚洲在线观看视频网站| 亚洲黄色免费电影| 亚洲字幕在线观看| 亚洲国产aⅴ天堂久久| 亚洲一区二区三区精品动漫| 亚洲第一毛片| 亚洲欧美中文日韩v在线观看| 最新国产拍偷乱拍精品| 亚洲天堂成人在线视频| 一区二区在线观看视频| 在线一区二区三区四区| 在线观看欧美精品| 亚洲女同性videos| 亚洲深夜福利视频| 免费不卡在线观看av| 欧美在线地址| 欧美日韩天天操| 亚洲第一二三四五区| 国产精品三上| 一区二区三区蜜桃网| 日韩写真在线| 另类酷文…触手系列精品集v1小说| 亚洲伊人久久综合| 欧美精品大片| 91久久精品国产| 亚洲国产美女久久久久| 香蕉久久国产| 欧美影院在线| 国产精品综合久久久| 99爱精品视频| 亚洲午夜高清视频| 欧美视频中文字幕在线| 一本色道久久综合一区| 一区二区三区视频在线| 亚洲精美视频| 久久久伊人欧美| 久久精品国产第一区二区三区| 欧美日韩综合不卡| 亚洲日本免费电影| 夜夜爽99久久国产综合精品女不卡| 久久男女视频| 欧美高清一区二区| 亚洲人成人77777线观看| 免费亚洲一区| 亚洲日韩欧美视频一区| 亚洲精品综合精品自拍| 久久综合久色欧美综合狠狠| 欧美freesex交免费视频| 激情文学综合丁香| 久久综合九九| 亚洲精品一区二区三区在线观看| 99视频精品| 国产精品久久一区主播| 欧美一区2区三区4区公司二百| 久久亚洲一区二区三区四区| 亚洲国产日韩欧美在线动漫| 欧美精品一区二区三| 亚洲亚洲精品三区日韩精品在线视频| 欧美一区二区精美| 伊人久久亚洲美女图片| 欧美黄免费看| 99xxxx成人网| 久久精品久久99精品久久| 狠狠色综合一区二区| 老司机一区二区| 亚洲免费观看在线视频| 欧美一区二区在线观看| 在线成人黄色| 欧美精品日韩| 午夜精品久久久久久| 欧美国产日韩xxxxx| 亚洲欧美成人网| 韩国欧美一区| 欧美日韩亚洲一区二区三区在线观看 | 久久久久久穴| 亚洲精品视频在线播放| 欧美一级片一区| 亚洲国产精品一区在线观看不卡| 欧美日韩精品中文字幕| 久久精品国亚洲| 中文日韩欧美| 欧美国产精品一区| 亚洲欧美欧美一区二区三区| 精品成人一区| 国产精品久久久一区二区三区 | 亚洲在线视频网站| 欧美韩日一区二区| 久久国产精品一区二区三区| 亚洲美女淫视频| 黄色欧美成人| 国产久一道中文一区| 欧美精品一区二区三区在线播放| 欧美在线精品免播放器视频| 夜夜狂射影院欧美极品| 欧美成人午夜免费视在线看片 | 欧美一区在线直播| 夜夜嗨av一区二区三区| 一色屋精品视频在线观看网站| 欧美日韩在线不卡| 国模精品一区二区三区色天香 | 国产一区二区日韩精品| 欧美日韩一区免费| 欧美大片一区二区| 久久综合伊人77777蜜臀|