SRM477
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的更多相关文章
随机推荐
- JoyOI1940 创世纪
一道基环树+树形\(DP\) 原题链接 显然输入的是内向基环树森林,且我们可以单独考虑每一棵基环树. 既然是基环树,自然先\(dfs\)找环,然后随便找环上的一点\(r\),将其与\(A[r]\)的边 ...
- HDOJ2586 How far away ?
一道LCA模板 原题链接 \(LCA\)模板题,不解释. 倍增版 #include<cstdio> #include<cmath> #include<cstring> ...
- http协议(一)一些基础知识
当我们在浏览器的地址栏中输入网址,然后点击回车,接着,浏览器就会呈现出我们需要的web界面,那么,这个界面是怎么产生的? web的界面是根据我们输入的URL(网址.地址),浏览器从服务器端获取对应的文 ...
- BZOJ 4521 [CQOI2016]手机号码 - 数位DP
Description 在$[L, R]$找出有几个数满足两个条件 : 1 : 不同时含有$4$ 和 $8$ 2 : 至少有$3$个相邻的数相同 Solution 非常容易的数位DP, $pos$ 为 ...
- NServiceBus消息重播
https://docs.particular.net/tutorials/message-replay/ 链接:https://pan.baidu.com/s/1KdWvpfZYZ2wUivkt3B ...
- robot framework 中should be true 与should contain 的区别
should be true 是否等于:判断是否should contain 是否包含 a是否包含b
- 20155312 2016-2017-2《Java程序设计》课程总结
20155312 2016-2017-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:你期望的师生关系是什么? 预备作业2:做中学learning by doing个人感想 ...
- MySQL正则表达式 REGEXP详解
在开始这个话题之前我们首先来做一个小实验,比较一下REGEXP和Like他们两个哪个效率高,如果效率太低,我们就没有必要做过多的研究了,实验的代码如下:<?phpRequire("co ...
- MySQL批量修改表前缀
error_reporting(0); $old_pre = 'tdr_'; // 原表前缀 $new_pre = 'db_'; // 新表前缀 // 配置连接 $db = new mysqli('1 ...
- Ubuntu下 QT添加外部链接库(.so文件)示例
参考:https://blog.csdn.net/KKALL1314/article/details/81915354 https://forum.qt.io/topic/80301/file-not ...