SRM 587 Div II L3:ThreeColorabilityEasyy
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12699
这道题目是第一次在比赛的时候做出来的,开始还想用brute force,后来发现那太复杂了,于是在纸上画了画,发现一个规律,那就是只有在一个2x2的cell中,如果出现3个N或3个Z方式的cell,那么这种情况下肯定是无法配色成功,因为最后一定会有两个相邻点为相同的颜色。如果没有这样的情况存在,那么是一定可以配色成功的,根据这点代码就好写了。
代码如下:
#include <string>
#include <vector> using namespace std; /************** Program Begin *********************/
class ThreeColorabilityEasy {
public:
string isColorable(vector <string> cells) {
for (int i = 0; i < cells.size() - 1; i++) {
for (int j = 0; j < cells[0].size() - 1; j++) {
int n = 0; n += cells[i][j] == 'N' ? 1 : 0;
n += cells[i][j+1] == 'N' ? 1 : 0;
n += cells[i+1][j] == 'N' ? 1 : 0;
n += cells[i+1][j+1] == 'N' ? 1 : 0;
if (n == 1 || n == 3) {
return "No";
}
}
} return "Yes";
} }; /************** Program End ************************/
SRM 587 Div II L3:ThreeColorabilityEasyy的更多相关文章
- SRM 582 Div II Level One: SemiPerfectSquare
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...
- SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意 ...
- SRM 583 Div II Level One:SwappingDigits
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609 #include <iostream> # ...
- SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...
- SRM 207 Div II Level Two: RegularSeason,字符串操作(sstream),多关键字排序(操作符重载)
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟 ...
- SRM 223 Div II Level Two: BlackAndRed,O(N)复杂度
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3457&rd=5869 解答分析:http://comm ...
- SRM 582 Div II Level Two SpaceWarDiv2
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> # ...
- SRM 583 Div Level Two:IDNumberVerification
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12610 这道题比较有意思,估计是中国人出的吧,以前都不知道身份 ...
- SRM 219 Div II Level One: WaiterTipping,小心约分
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609&rd=15503 这题目看上去so easy, ...
随机推荐
- 使用cm-12.0源代码编译twrp
Select the newest branch available. This step is not necessary with Omni because Omni already includ ...
- CSAPP 六个重要的实验 lab5
CSAPP && lab5 实验指导书: http://download.csdn.net/detail/u011368821/7951657 实验材料: http://downlo ...
- CentOS7卸载KDE桌面(转)
最初安装centos时选择了安装KDE桌面,打开很卡,没有用到,想卸载,可是试了网上的方法什么yum groupremove kde-desktop 都不奏效,于是只能自己找出KDE的包,然后yum卸 ...
- 数据结构之计算器的实现(JAVA)(四)
原理: 1.将中序表达式变化兴许表达式 2.当前字符为数字,将该数字放入栈中 3.当前字符为操作符,从栈中取出两个树,依据操作符来运算,将运算结果放入到栈中 4.反复,直到将字符操作完.此时栈中仅仅剩 ...
- JS于string 和 json互转对象
一.json开启string JSON.stringify(jsonObj) 两.string开启json eval(string) 版权声明:本文博主原创文章.博客,未经同意不得转载.
- Mac OS X Yosemite安装Hadoop 2.6记录
整个安装过程分为四部分: 一. 安装Homebrew 二. ssh localhost 三. 安装Hadoop已经进行配置文件设置 (伪分布式) 四. 执行栗子 一. 安装Homebrew 採用H ...
- c#获取页面重定向url
/// <summary> /// 获取页面重定向url /// </summary> /// <param name="url"></p ...
- Python调用微博API
上头叫通过微博ID获取用户公布过的历史微博内容,于是研究了下新浪微博提供的API 1 首先在微博开放中心下"创建应用"创建一个应用,应用信息那些随便填,填写完成后,不须要提交审核, ...
- Windows Phone 同步方式获取网络类型
原文:Windows Phone 同步方式获取网络类型 在Windows Phone 开发中有时候需要获取设备当前连接网络的类型,是Wifi,还是2G,3G,或者4G,SDK中提供获取网络类型的API ...
- UVA No Tipping
Problem A - No Tipping As Archimedes famously observed, if you put an object on a lever arm,it will ...