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> ...
随机推荐
- 设置NODE_ENV=production
NodeJS - Express 4.0下设置环境变量NODE_ENV=production,并不是修改文件的配置信息,而是通过命令行来实现. 首先在命令行下进入项目的目录,然后先后执行如下命令: s ...
- 兼容iOS 10 资料整理笔记-b
原文链接:http://www.jianshu.com/p/0cc7aad638d9 1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化 ...
- C# XML - XmlNode and XmlAttribute
public static string TestXML(string path) { XmlDocument doc = new XmlDocument(); doc.Load(path); Xml ...
- 2879: [Noi2012]美食节 - BZOJ
Description CZ市为了欢迎全国各地的同学,特地举办了一场盛大的美食节.作为一个喜欢尝鲜的美食客,小M自然不愿意错过这场盛宴.他很快就尝遍了美食节所有的美食.然而,尝鲜的欲望是难以满足的.尽 ...
- ubuntu下opencv 3.0和python2.7安装测试
1.安装opencv所需的库(编译器.必须库.可选库) sudo apt-get install build-essential sudo apt-get install cmake git libg ...
- 精华阅读第 10 期 |解开阿尔法狗(AlphaGo)人工智能的画皮
谷歌用一个变了身的古老「穷举算法」,披上「神经网络」的画皮,假装「跨时代」的黑科技,忽悠广大「膜拜者」,「狮仙」我实在看不下去了,来揭一揭这只幺蛾子小狗的画皮. 本期是移动开发精英俱乐部的第10期推荐 ...
- 精华阅读第 9 期 |滴滴出行 iOS 客户端架构演进之路
「架构都是演变出来的,没有最好的架构,只有最合适的架构!」最近,滴滴出行平台产品中心 iOS 技术负责人李贤辉接受了 infoQ 的采访,阐述了滴滴的 iOS 客户端架构模式与演变过程.李贤辉也是移动 ...
- A Step-by-Step Guide to Your First AngularJS App
What is AngularJS? AngularJS is a JavaScript MVC framework developed by Google that lets you build w ...
- Lua 的数据结构
1. Arrays: 注意 #(data), # 加上 table名字 == size of data = {}; , do --行 , do --列 data[(y-)*+x] = (y-)*+x; ...
- ZOJ3765 Lights Splay树
非常裸的一棵Splay树,需要询问的是区间gcd,但是区间上每个数分成了两种状态,做的时候分别存在val[2]的数组里就好.区间gcd的时候基本上不支持区间的操作了吧..不然你一个区间里加一个数gcd ...