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的更多相关文章
随机推荐
- CF Round #516 (Div. 2, by Moscow Team Olympiad)
前言:依旧菜,\(A\)了\(4\)题,不过这次上蓝了挺开心的. A. Make a triangle! Description 给出\(3\)根木棍,希望用它们拼成三角形,可以将其中的某些木棍增长, ...
- python 正则表达式 group() groups()
参考地址: http://www.cnblogs.com/kaituorensheng/archive/2012/08/20/2648209.html
- Linux 终端设备
<Linux终端设备详解> https://www.cnblogs.com/shineshqw/articles/2423989.html
- 查看PHP代码执行的时间
$t1 = microtime(true); //...要执行的代码$t2 = microtime(true); echo '耗时'.round($t2-$t1,3).'秒';
- windows mysql主 Linux mysql 从 主从同步,读写分离
Mysql –master linux-slave 一.My.ini: Server-id=1 relay-log=relay-bin relay-log-index=relay-bin-index ...
- [Spark]Spark章1 Spark架构浅析
Spark架构 Spark架构采用了分布式计算中的Master-Slave模型.集群中运行Master进程的节点称为Master,同样,集群中含有Worker进程的节点为Slave.Master负责控 ...
- oracle使用3DES加密
CREATE OR REPLACE PACKAGE dbc_cryptor IS SYSKEY VARCHAR2(16) := '0000000012345678'; SYSIV VARCHAR2(1 ...
- openssl pem密钥文件rsa加密解密例子
准备工作 命令行加密解密,用与比对代码中的算法和命令行的算法是否一致 C:\openssl_test>openssl rsautl -encrypt -in data.txt -inkey pu ...
- nginx xxx.conf
server { listen 80 ; server_name xxx.test.cn localhost 127.0.0.1 115.29.96.222; access_log /var/log/ ...
- eclipse构建maven的web项目(转载)
eclipse构建maven的web项目 分类: java opensource2013-12-25 16:22 43人阅读 评论(0) 收藏 举报 maven框架webappwebeclipse 使 ...