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> ...
随机推荐
- Interview-Harry Potter walk through matrix.
假设你是harry potter,在grid的左上角,你现在要走到右下角,grid中有正数也有负数,遇到正数表示你的strength增加那么多,遇到负数表示strength减少那么多,在任何时刻如果你 ...
- php Linux安装
参考地址:http://www.cnblogs.com/lianyue/p/3936728.html
- Hadoop以及其外围生态系统的安装参考
在研究Hadoop的过程中使用到的参考文档: 1.Hadoop2.2 参考文档 在CentOS上安装Hadoop 2.x 集群: http://cn.soulmachine.me/blog/201 ...
- 【BZOJ】【3398】【USACO 2009 Feb】Bullcow 牡牛和牝牛
组合计数/乘法逆元 排列组合求总方案数 这个可以用一个一维的动态规划解决: f[i][0]表示第i头牛是牝牛的方案数 f[i][1]表示第i头牛是牡牛的方案数 则转移为:f[i][0]=f[i-1][ ...
- memmove和memcpy 以及strcmp strcpy几个库函数的实现
memmove和memcpy 1.memmove 函数原型:void *memmove(void *dest, const void *source, size_t count) 返回值说明:返回指向 ...
- spoj 1108
要求输出一个牌的顺序 使每隔1.2.......n翻牌后出现1 2 3 4 5 6 7 8 9 .... n 将牌想象成n个空格 正向推 空n个位置放n 循环 需优化 #include <io ...
- hdu 2112 HDU Today (最短路,字符处理)
题目 题目很简单,只是多了对地名转化为数字的处理,好吧,这我也是参考网上的处理办法,不过大多数的人采用map来处理 注意初始化注意范围,不然会wa!!!(这是我当时wa的原因org) 大家容易忽视的地 ...
- POJ 1795
DNA Laboratory Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 1425 Accepted: 280 Des ...
- POJ2251Dungeon Master
http://poj.org/problem?id=2251 题意 : 就是迷宫升级版,从以前的一个矩阵也就是一层,变为现在的L层," . "是可以走,但是“#”不可以走,从S走到 ...
- 包装类型的比较,如:Integer,Long,Double
Integer, Long, Double等基本类型的包装类型,比较时两种方法:第一种:equals, 第二种: .intValue(), .longValue() , .doubleValue ...