COOK50小结
很遗憾。看到第五题的通过人数就不敢做了。待日后补上。
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小结的更多相关文章
- 从零开始编写自己的C#框架(26)——小结
一直想写个总结,不过实在太忙了,所以一直拖啊拖啊,拖到现在,不过也好,有了这段时间的沉淀,发现自己又有了小小的进步.哈哈...... 原想框架开发的相关开发步骤.文档.代码.功能.部署等都简单的讲过了 ...
- Python自然语言处理工具小结
Python自然语言处理工具小结 作者:白宁超 2016年11月21日21:45:26 目录 [Python NLP]干货!详述Python NLTK下如何使用stanford NLP工具包(1) [ ...
- java单向加密算法小结(2)--MD5哈希算法
上一篇文章整理了Base64算法的相关知识,严格来说,Base64只能算是一种编码方式而非加密算法,这一篇要说的MD5,其实也不算是加密算法,而是一种哈希算法,即将目标文本转化为固定长度,不可逆的字符 ...
- iOS--->微信支付小结
iOS--->微信支付小结 说起支付,除了支付宝支付之外,微信支付也是我们三方支付中最重要的方式之一,承接上面总结的支付宝,接下来把微信支付也总结了一下 ***那么首先还是由公司去创建并申请使用 ...
- iOS 之UITextFiled/UITextView小结
一:编辑被键盘遮挡的问题 参考自:http://blog.csdn.net/windkisshao/article/details/21398521 1.自定方法 ,用于移动视图 -(void)mov ...
- K近邻法(KNN)原理小结
K近邻法(k-nearst neighbors,KNN)是一种很基本的机器学习方法了,在我们平常的生活中也会不自主的应用.比如,我们判断一个人的人品,只需要观察他来往最密切的几个人的人品好坏就可以得出 ...
- scikit-learn随机森林调参小结
在Bagging与随机森林算法原理小结中,我们对随机森林(Random Forest, 以下简称RF)的原理做了总结.本文就从实践的角度对RF做一个总结.重点讲述scikit-learn中RF的调参注 ...
- Bagging与随机森林算法原理小结
在集成学习原理小结中,我们讲到了集成学习有两个流派,一个是boosting派系,它的特点是各个弱学习器之间有依赖关系.另一种是bagging流派,它的特点是各个弱学习器之间没有依赖关系,可以并行拟合. ...
- scikit-learn 梯度提升树(GBDT)调参小结
在梯度提升树(GBDT)原理小结中,我们对GBDT的原理做了总结,本文我们就从scikit-learn里GBDT的类库使用方法作一个总结,主要会关注调参中的一些要点. 1. scikit-learn ...
随机推荐
- ListControl 设置表格行高与字体
设置行高: CImageList m_l; m_l.Create(1,18,TRUE|ILC_COLOR32,1,0); listCtrl.SetImageList(&m_l,LVS ...
- activeMQ消息队列安装配置
1. 下载 到官网下载最新版本,有windows版本和linux版本的. http://activemq.apache.org/download.html 2. windows下部署 Activ ...
- nodejs vue-cli 微信公众号开发(一) 申请域名搭建服务器
一.搭建本地服务器 1.首先保存本地的80端口被node监听,利用内网穿透工具把80端口映射出去.(ngrok工具可以穿透内网使本地ip作为外网使用) 2.打开https://natapp.cn/tu ...
- [JZOJ4639] 【NOIP2016提高组A组7.16】Angel Beats!
题目 描述 题目大意 给你一棵树,每次询问两个点,求出这两个点的子树的重心到其中每个点的距离和. 重心的定义是到其中每个点距离和最小的点(不一定在两棵子树内) 思考历程 想想以前我是怎么求重心的呢-- ...
- python相关软件安装流程图解————————python安装——————python-3.7.1-amd64
首先查看自己的系统版本 是32位的还是64位的 https://www.python.org/downloads/windows/ —————————python下载安装 开始———————————— ...
- System.Web.Mvc.FileStreamResult.cs
ylbtech-System.Web.Mvc.FileStreamResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, P ...
- PAT甲级——【牛客练习题1002】
题目描述 Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chi ...
- 坐标转换,EPSG:4326转换成高德坐标教程
这里先给大家介绍几个坐标系: 1.WGS84:国际坐标系,为一种大地坐标系,也是目前广泛使用的GPS全球卫星定位系统使用的坐标系.2.GCJ02:火星坐标系,是由中国国家测绘局制订的地理信息系统的坐标 ...
- 常用的函数:atoi,itoa,atof,_ttoi等
出自http://blog.csdn.net/zzyoucan/article/details/10260093 atoi---ASCII to integer,将字符串转换成整形,从数字或正负号开始 ...
- CCA Spark and Hadoop 开发者认证技能点【2016只为hadoop达到巅峰】
Required Skills 技能要求: Data Ingest 数据消化: The skills to transfer data between external systems and you ...