250pt:

题意:给定一块蜂巢状的N*M矩阵,每块六边形和周围6个六边形相邻,现在告诉你哪些是陆地,哪些是水,问水陆交界处的长度。

思路:直接模拟

code:

 #line 7 "Islands.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class Islands
{
public:
int beachLength(vector <string> S)
{
int ans = ;
int n = S.size(), m = S[].size(), p;
for (int i = ; i < n; ++i)
for (int j = ; j < m; ++j){
if (j > && S[i][j] == '#' && S[i][j-] == '.') ++ans;
if (j > && S[i][j] == '.' && S[i][j-] == '#') ++ans;
if (i == ) continue;
if (i & ) p = j;
else p = j - ;
if (p >= && S[i][j] == '.' && S[i-][p] == '#') ++ans;
if (p >= && S[i][j] == '#' && S[i-][p] == '.') ++ans;
if (p + < m && S[i][j] == '.' && S[i-][p+] == '#') ++ans;
if (p + < m && S[i][j] == '#' && S[i-][p+] == '.') ++ans;
}
return ans;
}
};

500pt:

题意:给定最多200个正整数,问最多能组成多少个勾股数对。勾股数对定义:对于互质数对(a, b),存在c,使得a*a+b*b=c*c,

思路:隐蔽的二分图。

很明显先求出勾股数对,那么接下来便是一个最大匹配了。

不过,是二分图吗?

对于奇数a与奇数b,由于互质,那么a^2+b^2必定是2的倍数,必然不存在c

对于偶数a与偶数b,不互质显然不存在。 

  所以是个二分图,直接匹配即可

code:

 #line 7 "PythTriplets.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define M0(a) memset(a, 0, sizeof(a))
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
int match[], g[][];
int n, m;
bool vis[];
class PythTriplets
{
public:
vector<int> v1, v2;
void makePoint(string &S){
int tmp = ;
for (int i = ; i < S.size(); ++i)
if (S[i] == ' '){
if (tmp == ) continue;
if (tmp & ) v1.push_back(tmp);
else v2.push_back(tmp);
tmp = ;
} else tmp = tmp * + S[i] - ;
if (tmp > ){
if (tmp & ) v1.push_back(tmp);
else v2.push_back(tmp);
}
}
LL gcd(LL a, LL b){
return b ? gcd(b, a % b) : a;
}
bool ok(long long a, long long b){
if (gcd(a, b) > ) return false;
long long c = floor(sqrt(a * a + b * b + .));
if (c * c < a * a + b * b) ++c;
if (a * a + b * b == c * c) return true;
return false;
}
bool search_path(int u){
for (int v = ; v < m; ++v) if (g[u][v] && !vis[v]){
vis[v] = true;
if (match[v] == - || search_path(match[v])){
match[v] = u;
return true;
}
}
return false;
}
int findMax(vector <string> stick)
{
v1.clear();
v2.clear();
string S = accumulate(stick.begin(), stick.end(), string(""));
makePoint(S);
n = v1.size();
m = v2.size();
M0(g);
for (int i = ; i < n; ++i)
for (int j = ; j < m; ++j)
if (ok(v1[i], v2[j])) g[i][j] = true;//, cout << v1[i] << " " << v2[j] << endl;
int ans = ;
memset(match, -, sizeof(match));
for (int i = ; i < n; ++i){
M0(vis);
if (search_path(i)) ++ ans;
}
return ans;
}
};

SRM477的更多相关文章

随机推荐

  1. BZOJ1801或洛谷2051 [AHOI2009]中国象棋

    BZOJ原题链接 洛谷原题链接 这题挺难想状态的,刚看题感觉是状压,但数据\(100\)显然不可能. 注意到每行每列只能放\(0\sim 2\)个棋子,所以我们可以将这个写入状态. 设\(f[i][j ...

  2. BZOJ1855或洛谷2569 [SCOI2010]股票交易

    一道单调队列优化\(DP\) BZOJ原题链接 洛谷原题链接 朴素的\(DP\)方程并不难想. 定义\(f[i][j]\)表示到第\(i\)天,手上持有\(j\)股时的最大收益. 转移方程可以分成四个 ...

  3. POJ3254或洛谷1879 Corn Fields

    一道状压\(DP\) POJ原题链接 洛谷原题链接 很显然的状压,\(1\)表示种植,\(0\)表示荒废. 将输入直接进行状压,而要满足分配的草场是适合种草的土地,即是分配时的状态中的\(1\),在输 ...

  4. Python 环境安装教程(Windows 10)

    Python编程语言非常强大,非常容易上手,版本更新也不慢,在win10 x64中兼容性也很好,直接安装不需另外配置,虽然Python2和3有点异同.学习的话选择最新的 python 3.7.1版. ...

  5. id不连续

    解决办法 Alter TABLE jf_day_pv_classify Drop id; Alter TABLE jf_day_pv_classify ADD id INT NOT NULL PRIM ...

  6. Spring 注解原理(三)@Qualifier @Value

    Spring 注解原理(三)@Qualifier @Value Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.Aut ...

  7. Capacity To Ship Packages Within D Days LT1011

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  8. 如何获取堆的dump 的信息,如何分析

    获取方式: 1. jdk 自带启动参数 -XX:+HeapDumpBeforeFullGC -XX:HeapDumpPath=/x/x 产生dump日志,然后用visualVm分析 2. jmap 命 ...

  9. unity luaFramework

    1 AppConst: DebugMode: 调试模式,true:lua脚本直接读取自 AssetDir,false:开始会将AssetDir内的lua脚本复制到 Util.DataPath内(根据平 ...

  10. 基于centos6.5 hadoop 集群搭建

    1.修改Linux主机名2.修改IP3.修改主机名和IP的映射关系 ######注意######如果你们公司是租用的服务器或是使用的云主机(如华为用主机.阿里云主机等) /etc/hosts里面要配置 ...