TC SRM 593 DIV1 250
我只能说的亏没做,要不就挂0了。。
本来想四色定理,肯定4就可以的。。。然后准备爆,发现3的时候不好爆,又想了老一会,嗯,数据范围不小,应该不是暴力,直接找规律,貌似最大就是3,有一个3连块,输出3,其他输出2什么的。交,发现有环的时候,特殊的也是3。。。没办法还得暴力啊。暴力2的情况,写的也是各种错误。。。终于过了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
char p[][];
int o[][];
int mp[][],pre[];
int a[] = {,,,-,,-};
int b[] = {,-,,,-,};
int num = ;
int dfs(int x,int step)
{
int i;
for(i = ;i < num;i ++)
{
if(i == x) continue;
if(mp[x][i]&&pre[x] == pre[i])
{
return ;
}
else if(mp[x][i])
{
pre[i] = step% + ;
if(dfs(i,step+) == )
return ;
}
}
return ;
}
class HexagonalBoard
{
public :
int minColors(vector <string> board)
{
int i,j,k,n,flag;
n = board[].size();
for(i = ;i < n;i ++)
{
for(j = ;j < n;j ++)
{
if(board[i][j] == 'X')
o[i][j] = num ++;
}
}
for(i = ;i < n;i ++)
{
for(j = ;j < n;j ++)
{
if(board[i][j] != 'X') continue;
if(flag == ) flag = ;
for(k = ;k < ;k ++)
{
if(i + a[k] >= &&i + a[k] < n&&j + b[k] >= &&j + b[k] < n)
{
if(board[i+a[k]][j+b[k]] == 'X')
{
flag = ;
mp[o[i][j]][o[i+a[k]][j+b[k]]] = ;
}
}
}
}
}
if(flag == )
{
for(i = ;i < num;i ++)
{
if(!pre[i])
{
pre[i] = ;
if(dfs(i,) == )
return ;
}
}
return ;
}
else if(flag == )
return ;
else
return ;
}
};
TC SRM 593 DIV1 250的更多相关文章
- TC SRM 593 DIV1 250(dfs)
这图最多3色就可以 搜2就行了 #include <iostream> #include<cstdio> #include<cstring> #include< ...
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- SRM 595 DIV1 250
挺简单的组合把. #include <cstdio> #include <cstring> #include <iostream> #include <vec ...
- SRM 594 DIV1 250
可能开始宿舍比较乱,思绪静不下来...想了大半个小时,终于确定了应该暴力+DP,然后写了枚举除数,和被除的版本..这样,还敲错了个字母,第一次提交还100多,修改提交还有75.多,最后想到,貌似不打对 ...
- 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> ...
随机推荐
- 【叉积】【sdut 2508 图形密码】
图形密码 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...
- 记录一次冷备恢复遇到的 ORA-00304问题
希望通过冷备一个数据库,然后在另外一台数据库进行恢复 1.打tar包 tar -czvf Prod.tar.gz *control01.ctlcontrol02.ctlredo01.logredo02 ...
- JavaScript - call(this)
为什么使用call(this), 而不是直接使用(function(){})(); "use strict" function Foo() { (function() { cons ...
- Windows下Apache服务器中自动配置二级子域名
今天我们介绍的这个办法,只需要简单修改 httpd-vhosts.conf 文件,配合 .htaccess 文件即可实现自动配置二级域名. 我们这里以 wpchina.com 为例,以下代码中的 wp ...
- 50个必备的实用jQuery代码段
本文会给你们展示50个jquery代码片段,这些代码能够给你的javascript项目提供帮助.其中的一些代码段是从jQuery1.4.2才开始支持的做法,另一些则是真正有用的函数或方法,他们能够帮助 ...
- hdu 4826(dp + 记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4826 思路:dp[x][y][d]表示从方向到达点(x,y)所能得到的最大值,然后就是记忆化了. #i ...
- loj 1257 (求树上每一个点到树上另一个点的最长距离)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1257 思路:首先需要用到一个知识点就是树上任一点到树上最长直径的某一个端点的距离最远, ...
- mac上创建MySQL的基本步骤
首先得安装环境与MySQL的软件 安装环境的软件在这里我用的是:jdk-8u111-macosx-x64.dmg MySQL:mysql-5.7.16-osx10.11-x86_64.dmg 安装好了 ...
- 用JAXP的SAX方式解析XML文件
简单用JAXP的SAX方式(事件驱动)解析XML文件: 文件(1.XML) <?xml version="1.0" encoding="UTF-8" st ...
- 安装Maven、Eclipse设置、添加地址JAR
1.下载Maven 地址:http://maven.apache.org/download.cgi 2.安装Maven 系统变量:MAVEN_HOME = D:\maven\apache-maven- ...