题目链接

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

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. JavaScript特效源码(6、页面特效一)

    1.页面全屏 页面全屏显示[ALT+F4关闭][共1步][新弹出窗口并以全屏幕方式显示] ====1.将以下代码加入HTML的<body></body>之间: <form ...

  2. 【分块】P4135 作诗

    分块太暴力惹... 没做出来.看了题解qaq 分析: 两头$\sqrt{n}$暴力维护 预处理ans[i][j],sum[i][j] sum[i][j]是一个前缀和,前i块值为j的数量 ans[i][ ...

  3. [转]NuGet学习笔记(1) 初识NuGet及快速安装使用

    关于NuGet园子里已经有不少介绍及使用经验,本文仅作为自己研究学习NuGet一个记录. 初次认识NuGet是在去年把项目升级为MVC3的时候,当时看到工具菜单多一项Library Package M ...

  4. 关于Synthesis

    1,当追求面积最小时 会以牺牲Fmax为代价,可以使用一下setting: fit_pack_for_density=on fit_report_lab_usage_stats=on 可在 .qsf ...

  5. JUC 一 CopyOnWriteArrayList 和 CopyOnWriteArraySet

    java.util.concurrent; 简介 CopyOnWriteArrayList是一个线程安全的ArrayList,通过内部的volatile数组和显式锁ReentrantLock来实现线程 ...

  6. ThinkPHP 读取数据

    在ThinkPHP中读取数据的方式很多,通常分为读取数据.读取数据集和读取字段值. 步进电机和伺服电机 数据查询方法支持的连贯操作方法有: 连贯操作 作用 支持的参数类型 where 用于查询或者更新 ...

  7. form表单简易注册登陆

    注册页面: html <form action="updata.php" method="post" id="text_form"&g ...

  8. memcache课程---1、memcache介绍及安装(memcache作用)

    memcache课程---1.memcache介绍及安装(memcache作用) 一.总结 一句话总结: 减少对数据库的访问,因为数据库的访问比较花费时间 1.memcache为什么比操作数据库快的多 ...

  9. vue swiper点击后返回不能自动播放

    解决方法: 在返回时重新开启轮播 组件中: <swiper :options="swiperOption" ref="mySwiper" :class=& ...

  10. #iOS问题记录# 频繁触发viewDidLayoutSubviews的问题

    问题描述: 最近使用给Flutter团队写view组件的时候,出现了触发Widget的频繁build的问题. 问题排查: Flutter的同事提到在flutter层,是因为 updateViewpor ...