SRM477

时间:2022-11-03 19:34:48

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. Ubuntu 下安装Mysql 需要注意的地方&period;

      安装卸载 sudo apt-get autoremove --purge mysql-server-5.0sudo apt-get remove mysql-serversudo apt-get au ...

    2. Django base view

      class django.views.generic.base.View 它是基类的基类,其它View基类都是从这继承的. 官例: from django.http import HttpRespon ...

    3. JQuery 绑定事件时传递参数的实现方法

      如题,比如我想在$(":text").bind("keyup",funcionName);将当前的文本框作为参数传递给 functionName所代表的函数,应 ...

    4. css伪类选择器详细解析及案例使用-----伪类选择器(2)

      结构伪类选择器: <div> <ul> /*ul:only-of-type*/ <li>one</li> /*li:first-child li:nth ...

    5. Cocos2d-x Layout简单使用

      1. Text* alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 ); alert-&gt ...

    6. SQL Server 2014 HADR&lowbar;DATABASE&lowbar;WAIT&lowbar;FOR&lowbar;TRANSITION&lowbar;TO&lowbar;VERSIONING 等待

      最近有发现SAP 的MES系统上了AlwaysOn后辅助节点发现无法查询的情况,例如在辅助节点上执行: SELECT TOP 0 * FROM TABLE1; 语句执行正常SELECT TOP 1* ...

    7. 网络编程-Python高级语法-深浅拷贝

      知识点:深浅拷贝,浅拷贝拷贝的是最顶层的东西,深拷贝是拷贝最深层的东西,光说可能理解不了,看下图 1.拷贝可变类型 2.拷贝不可变类型 3.拷贝元祖,元组内数据是可变类型

    8. iOS进阶之正则表达式

      最近一直在弄正则表达式,于是在这里整理一下,便于日后查阅. 1.常用符号 ^:字符串的开始 $:字符串的结束 *:表示零个或若干个 ?:表示零个或一个 +:表示一个或若干个 | :表示 或 操作 . ...

    9. Openvswitch手册&lpar;1&rpar;&colon; 架构,SSL&comma; Manager&comma; Bridge

      Openvswitch是一个virutal swtich, 支持Open Flow协议,当然也有一些硬件Switch也支持Open Flow协议,他们都可以被统一的Controller管理,从而实现物 ...

    10. Windows10反安装报错error code 2502 2503

      先找系统TEMP目录,一般为C:\windows\temp,打开这个目录的权限,为这个目录中的User用户添加权限为完全控制,现在再反安装就不会报错了. 注:原因就是因为系统运行时需要用到临时文件的目 ...

    相关文章