这图最多3色就可以 搜2就行了

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int vis[][],c[][],f[],mm;
int dis[][] = {{,},{,},{-,},{,-},{-,},{,-}},n;
int flag,m;
int judge(int x,int y)
{
if(x<||y<||x>=n||y>=n)
return ;
return ;
}
int dfs(int x,int y,vector <string> board,int o)
{
int i;
for(i = ; i < ; i++)
{
int tx = x+dis[i][];
int ty = y+dis[i][];
if(judge(tx,ty)&&board[tx][ty]=='X')
{
if(c[tx][ty])
{
if(c[tx][ty]!=o)
return ;
}
else
{
flag = ;
c[tx][ty] = o;
if(!dfs(tx,ty,board,-o))
return ;
}
}
}
return ;
}
class HexagonalBoard
{
public:
int minColors(vector <string> board)
{
int i,j,k = board.size();
n = k;
int ff = ;
for(i = ; i < n ; i++)
{
for(j = ; j < n ; j++)
{
if(board[i][j]=='X'&&!c[i][j])
{
m++;
c[i][j] = ;
if(!dfs(i,j,board,-))
{
ff=;
break;
}
}
}
if(!ff) break;
}
if(!m) return ;
if(!flag)
return ;
if(ff)
return ;
else
return ;
}
};

TC SRM 593 DIV1 250(dfs)的更多相关文章

  1. TC SRM 593 DIV1 250

    我只能说的亏没做,要不就挂0了.. 本来想四色定理,肯定4就可以的...然后准备爆,发现3的时候不好爆,又想了老一会,嗯,数据范围不小,应该不是暴力,直接找规律,貌似最大就是3,有一个3连块,输出3, ...

  2. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  3. SRM 594 DIV1 250

    可能开始宿舍比较乱,思绪静不下来...想了大半个小时,终于确定了应该暴力+DP,然后写了枚举除数,和被除的版本..这样,还敲错了个字母,第一次提交还100多,修改提交还有75.多,最后想到,貌似不打对 ...

  4. SRM 595 DIV1 250

    挺简单的组合把. #include <cstdio> #include <cstring> #include <iostream> #include <vec ...

  5. TC SRM 593 DIV2 1000

    很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...

  6. 最小公倍数 SRM 661 Div1 250: MissingLCM

    Problem Statement The least common multiple (denoted "lcm") of a non-empty sequence of pos ...

  7. Topcoder SRM 698 Div1 250 RepeatString(dp)

    题意 [题目链接]这怎么发链接啊..... Sol 枚举一个断点,然后类似于LIS一样dp一波 这个边界条件有点迷啊..fst了两遍... #include<bits/stdc++.h> ...

  8. TC srm 673 300 div1

    TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...

  9. SRM 583 DIV1

    A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...

随机推荐

  1. Feature Stapling in SharePoint 2010

    http://msdn.microsoft.com/en-us/library/bb861862(v=office.12).aspx http://gallery.technet.microsoft. ...

  2. java并发编程(一)

    多个线程访问同一个变量时,可能会出现问题.这里我用两个线程同时访问一个int count变量,让他们同时+1.同时让线程睡眠1秒,每个线程执行10次,最后应该输出20才对,因为count++并不是原子 ...

  3. JPA学习---第八节:使用JPQL语句进行查询

    1.JPQL 语句查询,代码如下: @Test public void query(){ EntityManagerFactory factory = Persistence.createEntity ...

  4. BZOJ 2753 [SCOI2012] 滑雪和时间胶囊 最小生成树

    题目链接: 题目 2753: [SCOI2012]滑雪与时间胶囊 Time Limit: 50 Sec Memory Limit: 128 MB 问题描述 a180285非常喜欢滑雪.他来到一座雪山, ...

  5. Matlab实现求a到b被c整除的个数

    我先想到的是for循环........ 然后sum(find(mod(a:b,c)==0)),从10到100得到874,为什么不对呢? 比如a = [1 2 3 4  2 3 4 2],find(a= ...

  6. ios开发小技巧之提示音播放与震动

    在ios开发中,有时候我们需要频繁播放某种提示声音,比如微博刷新提示音.QQ消息提示音等,对于这些短小且需要频繁播放的音频,最好将其加入到系统声音(system sound)里. 注意: 需要播放的音 ...

  7. Struct2 自定义拦截器

    1 因为struct2 如文件上传,数据验证等功能都是由系统默认的 defalutStack中的拦截器实现的,所以我们定义拦截器需要引用系统默认的defalutStack 这样才不会影响struct2 ...

  8. ByteArrary(优化数据存储和数据流)

    原地址:http://www.unity蛮牛.com/blog-1801-799.html 首页 博客 相册 主题 留言板 个人资料   ByteArrary(优化数据存储和数据流) 分类:unity ...

  9. PHP ServerPush

    原文:http://yorsal.com/archives/302 随着人们对Web即时应用需求的不断上升,Server Push(推送)技术在聊天.消息提醒尤其是社交网络等方面开始兴起,成为实时应用 ...

  10. 无废话版本-Asp.net MVC4.0 Rasor的基本用法

    最近工作有点忙,好久没写东西了!废话不多说了,进入主题! 1.在页面中输出单一变量时候,只要在C#语句之前加上@符号即可,For example: <p>Now Time:@DateTim ...