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. 团队作业之Rookie also want to fly

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 在时代的浪潮下,单人编程,结对编程已经无法满 ...

  2. UI和View 三种控制方式

    AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...

  3. 搭建自己的代理服务 proxy nginx squid ss5 s(shadow)s(socks)

    标签: nginx / squid / 负载均衡 / ss 4090 1. nginx (forward) nginx自己熟悉,经常用来做负载均衡的反向代理, 这里搭建一个正向代理(forward) ...

  4. 将某视图View转换为UIImage

    + (UIImage *)getSharedScreenView{ UIWindow *screenWindow = [[UIApplication sharedApplication]keyWind ...

  5. MD5加密及Hash长度拓展攻击【通俗易懂】

    先放一个简单点的利用了Hash长度拓展攻击的题目 if($COOKIE["getmein"] === md5($secret . urldecode($username . $pa ...

  6. python -u

    标准错误(std.err):直接打印到屏幕 标准输出(std.out):需要缓存后再输出到屏幕 sys.stdout.write("stdout1") sys.stderr.wri ...

  7. DataTable xml 互相转换

    //测试方法 public static DataTable Test() { string savePath = System.AppDomain.CurrentDomain.BaseDirecto ...

  8. Android Makefile中是 如何识别 TARGET_PRODUCT 的

    http://blog.csdn.net/stevenliyong/article/details/5285334 今天有时间小看一下Android 的Makefile, 终于稍有明白Android ...

  9. rpm安装jdk7

    原文:http://www.centoscn.com/image-text/config/2015/0208/4658.html 系统环境:centos-6.5 安装方式:rpm安装 软件:jdk-7 ...

  10. socketserver实例化过程

    一.创建server对象时__init__的执行 找继承中的__init__ 这是ThreadingMixIn类中的方法 这是TCPServer类中的方法(父类BaserServer中还会用到fini ...