TC SRM 593 DIV1 250(dfs)
这图最多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)的更多相关文章
- TC SRM 593 DIV1 250
我只能说的亏没做,要不就挂0了.. 本来想四色定理,肯定4就可以的...然后准备爆,发现3的时候不好爆,又想了老一会,嗯,数据范围不小,应该不是暴力,直接找规律,貌似最大就是3,有一个3连块,输出3, ...
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- SRM 594 DIV1 250
可能开始宿舍比较乱,思绪静不下来...想了大半个小时,终于确定了应该暴力+DP,然后写了枚举除数,和被除的版本..这样,还敲错了个字母,第一次提交还100多,修改提交还有75.多,最后想到,貌似不打对 ...
- SRM 595 DIV1 250
挺简单的组合把. #include <cstdio> #include <cstring> #include <iostream> #include <vec ...
- TC SRM 593 DIV2 1000
很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...
- 最小公倍数 SRM 661 Div1 250: MissingLCM
Problem Statement The least common multiple (denoted "lcm") of a non-empty sequence of pos ...
- Topcoder SRM 698 Div1 250 RepeatString(dp)
题意 [题目链接]这怎么发链接啊..... Sol 枚举一个断点,然后类似于LIS一样dp一波 这个边界条件有点迷啊..fst了两遍... #include<bits/stdc++.h> ...
- TC srm 673 300 div1
TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...
- SRM 583 DIV1
A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...
随机推荐
- iPhone OS 开发 - 了解并解决代码签名问题
译者:Jestery 发表时间:2010-04-24浏览量:21082评论数:0挑错数:0 了解并解决代码签名问题 (为保持跟开发环境以及APPLE开发者社区网站结构对应,一些名词未作翻译) 绝大多数 ...
- Team Homework #1 学长“学霸英语学习软件”试用
简介: 一款英语单词记忆和管理辅助软件. 基本功能: 内置GRE词汇及其常考形态.Webster英语解释 单词发音功能 单词测验模式 简易词典功能 基本界面 词库单词读取 单词测试 优点: 1.界面简 ...
- p1205单词翻转-递归解决
题目描述 Description 给出一个英语句子,希望你把句子里的单词顺序都翻转过来 输入描述 Input Description 输入包括一个英语句子. 输出描述 Output Descripti ...
- 阿旭的php开发环境
过了几年,php技术也日新月异,变化也挺多.哪么对于开发者,感觉有一些简单的方法,写下来,以备以后使用.我觉得吧,Linux写php不如windows写php,调试,查资料和各种功能比较全面,而lin ...
- 无root权限安装python
http://lujialong.com/?p=150 pipe 安装第三方包 http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip http://www.cn ...
- 客户端服务端通信protocol
这个协议不知我在上面耗费了多长时间,也有人问过我咋回事,这个protocol不长,但对于我来说理解起来很费劲,今天回来看看忽然看懂了(80%),只能说不知看了多少遍 其实这些东西应该在来的一个月这样子 ...
- GameMap其他初始化
//其他初始化 init_prop();//初始化道具 init_ornamemtal();//初始化装饰物 init_monster_type_info();//初始化怪物基本信息 这个比较重要在加 ...
- jquery-validation 学习总结
一.用前必备 项目主页:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassis ...
- poj 2362
回溯加剪枝 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> # ...
- uva 11029
看了别人的解法 发现了 modf 这个函数 取小数部分 /*********************************************************************** ...