题目链接

很遗憾。看到第五题的通过人数就不敢做了。待日后补上。

A题

求最长的连续子序列,使得他们满足gcd为1。

如果有相邻的两个数的gcd为1,那么整个序列的gcd值也就是1,

否则就是该序列不存在。

 /*************************************************************************
> File Name: A.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月23日 星期二 13时57分22秒
> Propose:
************************************************************************/
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int MAX_N = ;
int N, A[MAX_N];
#define rep(i, n) for (int i = (1); i <= (n); i++) int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
} int main(void) {
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
cin >> N;
bool flag = false;
rep (i, N) {
cin >> A[i];
if (i > && gcd(A[i], A[i-]) == ) flag = true;
}
if (flag) cout << N << endl;
else cout << - << endl;
} return ;
}

B题

统计一个每个位置向右和向下是否都没有障碍。

 /*************************************************************************
> File Name: B.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月23日 星期二 14时30分39秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ char a[][];
int N, T;
bool col[][], row[][];
#define rep(i, n) for (int i = (1); i <= n; i++)
#define per(i, n) for (int i = (n); i >= 1; i--) int main(void) {
ios::sync_with_stdio(false);
cin >> T;
while (T--) {
cin >> N;
rep (i, N) rep (j, N) cin >> a[i][j], row[i][j] = col[i][j] = true; rep (i, N) per (j, N) if ((j < N && !row[i][j+]) || (a[i][j] != '.')) row[i][j] = false;
rep (j, N) per (i, N) if ((i < N && !col[i+][j]) || (a[i][j] != '.')) col[i][j] = false; int res = ;
rep (i, N) rep (j, N) if (row[i][j] && col[i][j]) res++;
cout << res << endl;
} return ;
}

C题

先预处理出每个数的所有的质因子。 并记录下每个质因子在序列中最后一次出现的位置即可。

 /*************************************************************************
> File Name: C.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月23日 星期二 17时24分56秒
> Propose:
************************************************************************/
#include <set>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int MAX_N = ;
int A[MAX_N], p[MAX_N], cnt, last[MAX_N*];
bool vis[MAX_N*];
#define rep(i, n) for (int i = (1); i <= n; i++) void prime() {
cnt = ;
memset(vis, false, sizeof(vis));
for (int i = ; i < ; i++) if (!vis[i]) {
p[cnt++] = i;
for (int j = *i; j < ; j += i) vis[j] = true;
}
} void read(int &res) {
res = ;
char c = ' ';
while (c < '' || c > '') c = getchar();
while (c >= '' && c <= '') res = res * + c - '', c = getchar();
} vector<int> factor[];
vector<int>::iterator it;
int main(void) {
prime();
rep (i, ) {
int x = i;
for (int j = ; p[j]*p[j] <= x; j++) {
if (x % p[j] == ) {
factor[i].push_back(p[j]);
while (x % p[j] == ) x /= p[j];
}
}
if (x > ) factor[i].push_back(x);
} int T, N;
read(T);
while (T--) {
read(N);
rep (i, N) read(A[i]); int l = , r = , res = ;
memset(last, , sizeof(last));
for (it = factor[A[l]].begin(); it != factor[A[l]].end(); ++it) last[*it] = l;
while (l <= r && r <= N) {
int m = ;
for (it = factor[A[r]].begin(); it != factor[A[r]].end(); ++it) {
if (last[*it] >= l) m = max(m, last[*it]);
last[*it] = r;
}
if ( == m) res = max(res, r - l + );
else l = m + ;
r++;
} if (res == ) puts("-1");
else printf("%d\n", res);
} return ;
}

D题

分奇数行和偶数行讨论,并得出递推式,即可用矩阵加速。

 /*************************************************************************
> File Name: D.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月24日 星期三 13时20分04秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ typedef long long LL;
const int MOD = 1e9 + ;
#define rep(i, n) for (int i = (1); i <= (n); i++) struct Matrix {
LL mat[][];
int n, m;
Matrix() {}
Matrix(int n, int m):n(n), m(m) {
memset(mat, , sizeof(mat));
}
Matrix operator * (const Matrix &b) const {
Matrix c(n, b.m);
rep (i, n) rep (k, n) rep (j, b.m) c.mat[i][j] = (c.mat[i][j] + mat[i][k] * b.mat[k][j]) % MOD;
return c;
}
}; Matrix pow_mod(Matrix a, int b) {
Matrix res(a.n, a.m);
rep (i, a.n) res.mat[i][i] = ;
while (b) {
if (b & ) res = res * a;
a = a * a;
b >>= ;
}
return res;
} int main(void) {
ios::sync_with_stdio(false);
int T, N, M;
cin >> T;
while (T--) {
cin >> N >> M;
Matrix a(M, M), b(M, M);
rep (i, M) {
if (i - >= ) a.mat[i][i-] = b.mat[i][i-] = ;
if (i + <= M) a.mat[i][i+] = b.mat[i][i+] = ;
a.mat[i][i] = ;
}
Matrix res = pow_mod(a*b, (N% == ? N/- : N/));
if (N % == ) res = b * res;
Matrix f1(M, );
rep (i, M) f1.mat[i][] = ;
res = res * f1; LL ans = ;
rep (i, M) ans = (ans + res.mat[i][]) % MOD;
cout << ans << endl;
} return ;
}

E题

COOK50小结的更多相关文章

  1. 从零开始编写自己的C#框架(26)——小结

    一直想写个总结,不过实在太忙了,所以一直拖啊拖啊,拖到现在,不过也好,有了这段时间的沉淀,发现自己又有了小小的进步.哈哈...... 原想框架开发的相关开发步骤.文档.代码.功能.部署等都简单的讲过了 ...

  2. Python自然语言处理工具小结

    Python自然语言处理工具小结 作者:白宁超 2016年11月21日21:45:26 目录 [Python NLP]干货!详述Python NLTK下如何使用stanford NLP工具包(1) [ ...

  3. java单向加密算法小结(2)--MD5哈希算法

    上一篇文章整理了Base64算法的相关知识,严格来说,Base64只能算是一种编码方式而非加密算法,这一篇要说的MD5,其实也不算是加密算法,而是一种哈希算法,即将目标文本转化为固定长度,不可逆的字符 ...

  4. iOS--->微信支付小结

    iOS--->微信支付小结 说起支付,除了支付宝支付之外,微信支付也是我们三方支付中最重要的方式之一,承接上面总结的支付宝,接下来把微信支付也总结了一下 ***那么首先还是由公司去创建并申请使用 ...

  5. iOS 之UITextFiled/UITextView小结

    一:编辑被键盘遮挡的问题 参考自:http://blog.csdn.net/windkisshao/article/details/21398521 1.自定方法 ,用于移动视图 -(void)mov ...

  6. K近邻法(KNN)原理小结

    K近邻法(k-nearst neighbors,KNN)是一种很基本的机器学习方法了,在我们平常的生活中也会不自主的应用.比如,我们判断一个人的人品,只需要观察他来往最密切的几个人的人品好坏就可以得出 ...

  7. scikit-learn随机森林调参小结

    在Bagging与随机森林算法原理小结中,我们对随机森林(Random Forest, 以下简称RF)的原理做了总结.本文就从实践的角度对RF做一个总结.重点讲述scikit-learn中RF的调参注 ...

  8. Bagging与随机森林算法原理小结

    在集成学习原理小结中,我们讲到了集成学习有两个流派,一个是boosting派系,它的特点是各个弱学习器之间有依赖关系.另一种是bagging流派,它的特点是各个弱学习器之间没有依赖关系,可以并行拟合. ...

  9. scikit-learn 梯度提升树(GBDT)调参小结

    在梯度提升树(GBDT)原理小结中,我们对GBDT的原理做了总结,本文我们就从scikit-learn里GBDT的类库使用方法作一个总结,主要会关注调参中的一些要点. 1. scikit-learn ...

随机推荐

  1. spring:AOP面向切面编程02

    参考: https://blog.csdn.net/jeffleo/article/details/54136904 一.AOP的核心概念AOP(Aspect Oriented Programming ...

  2. POJ1160 Post Office-四边形不等式优化DP

    方程 $\Large f(i,j)=min(f(i-1,k)+w(k+1,j))$ 其中$w(i,j)$表示在$[i,j]$的村庄都去一个邮局的最小距离和 证明w满足四边形不等式 设$w_k(i,j) ...

  3. CentOS6.3搭建ZooKeeper伪集群

    1. 将zookeeper安装包移动至/home, 解压后改名为zookeeper 相关命令 # 解压 .tar.gz # 重命名 zookeeper 2. 进入zookeeper/conf/目录下, ...

  4. python requests 高级用法

    高级用法 本篇文档涵盖了 Requests 的一些高级特性. 会话对象 会话对象让你能够跨请求保持某些参数.它也会在同一个 Session 实例发出的所有请求之间保持 cookie, 期间使用 url ...

  5. VS2010版的Speex音频处理模块(附源码+测试demo)

    开源的Speex代码内部包含了VS2003,05,08工程,但是直接编译总有一些要设置的地方,虽说也不是很复杂,但是对于不是很了解VS的同学来说还是要折腾一阵,所以我弄了一个可以直接使用的版本,当然是 ...

  6. golang和python的二进制转换

    1.二进制转换规则 比如13,对13整除2,余数1,整除变为6,依次类推 13/2=6余1 6/2=3余0 3/2=1余1 1/2=0余1 所以最后的结果为1101 2.python def conv ...

  7. 2019/10/17 CSP模拟 总结

    T1 补票 Ticket 没什么好说的,不讲了 T2 删数字 Number 很后悔的是其实考场上不仅想出了正解的方程,甚至连优化都想到了,却因为码力不足只打了\(O(n^2)\)暴力,甚至还因为细节挂 ...

  8. 容器安全与EDR的异同

    以Docker为代表的容器技术,直接运行于宿主机操作系统内核,因此对于容器安全,很多人会有着这样的疑问:EDR(Endpoint Detection and Response)等主机安全方案,能否直接 ...

  9. JS-jquery 获取当前点击的对象

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  10. SpringBoot学习笔记(六):SpringBoot实现Shiro登录控制和权限控制

    登录模块:在登录时必须调用 授权模块:不是一登录就调动,而是当角色权限控制时才会调用 登录控制 环境搭建在上一篇. 数据库表 表名:role 字段:id rolename 表名:user 字段:id ...