SRM 587 Div II L3:ThreeColorabilityEasyy
来源:互联网 发布:爱回收 知乎 编辑:程序博客网 时间:2024/06/06 14:28
题目来源: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 Two SpaceWarDiv2
- SRM 207 Div II Level One: TransportCounting
- SRM 219 Div II Level Two: HealthFood
- SRM 233 Div II Level Two: PipeCuts
- SRM 299 Div II Level Two: Projections
- SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2
- SRM 585 Div II Level Two: TrafficCongestionDivTwo
- SRM 585 Div II Level Three: EnclosingTriangleColorful
- SRM 579 Div II Level Two: UndoHistory
- SRM 576 D2 L3:CharacterBoard2
- SRM 603 D2 L3:GraphWalkWithProbabilities
- SRM 606 D2 L3:EllysCandyGame
- SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法
- SRM 212 Div II Level Two: WinningRecord,Brute Force
- SRM 212 Div II Level Three: LargestCircle,Brute Force
- SRM 207 Div II Level Three: CaptureThemAll,BFS算法
- SRM 219 Div II Level One: WaiterTipping,小心约分
- AJAX简介
- Android系统联系人全特效实现(上),分组导航和挤压动画
- 纯手工打造漂亮的瀑布流,五大插件一个都不少Bootstrap+jQuery+Masonry+imagesLoaded+Lightbox!
- 【C专家编程】第8章-第11章
- visual studio 中怎样添加lib引用
- SRM 587 Div II L3:ThreeColorabilityEasyy
- Qt 之 show,hide,setVisible,setHidden,close 等小结
- 单点登录解决方案:CAS
- XHR
- Android系统联系人全特效实现(下),字母表快速滚动
- XML基础
- 什么是共模干扰差模干扰共模信号差模信号
- 12-php中的错误的处理
- 【读书笔记】失败的逻辑