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, ...
随机推荐
- Android架构分析之LOG模块
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android版本:2.3.7_r1 Linux内核版本:android-goldfish-2.6.29 Andro ...
- 在mac os下编译android -相关文章
1. Mac OS X下编译Android源码 http://blog.csdn.net/bulreed/article/details/22783467 2.MAC OS 编译 Android源代码 ...
- sizeClass和autolayout学习资源整理
sizeClass和autolayout,看来不得不開始放弃frame的写法,收集点资料集中学习下 Adaptivity User Interfaces苹果官方文档:https://developer ...
- char与unsigned char 差别
char 与 unsigned char的本质差别 http://bbs.csdn.net/topics/270080484 同一个内存内容:10010000 你用char* 解释是-1 ...
- linux kernel 结构体赋值方法{转载}
原文地址: http://www.chineselinuxuniversity.net/articles/48226.shtml 这几天看Linux的内核源码,突然看到init_pid_ns这个结构体 ...
- oracle物化视图使用+hibernate
使用过程 ----删除 TRUNCATE TABLE mlog$_xxx_lxz_tmp;DROP MATERIALIZED VIEW LOG ON xxx_lxz_tmp; drop materia ...
- php 两个文件之间的相对路径的计算方法
php 两个文件之间的相对路径的计算方法 比如: 文件A 的路径是 /home/web/lib/img/cache.php 文件B的路径是 /home/web/api/img/show.php 那么. ...
- 2014百度之星资格赛——Disk Schedule
2014百度拥有明星格比赛--Disk Schedule Problem Description 有非常多从磁盘读取数据的需求,包含顺序读取.随机读取. 为了提高效率.须要人为安排磁盘读取. 然而.在 ...
- Git Flow流程
# 1. clone远程仓库到本地 git clone git@git.oschina.net:huogh/muzhifm_xxx.git # 2. 使用远程分支origin/dev创建本地分支d ...
- 你的第一个AngularJS应用--教程二:基架、建立和測试的工具
介绍 有非常多可用的工具能够帮助你开发AngularJS 应用,那些非常复杂的框架不在我的讨论范围之中,这也是我開始这系列教程的原因. 在第一部分,我们掌握了AngularJS框架的基本结构,开发了第 ...