LTIME16小结(CodeChef)
最后一题是Splay...还没有学会。。蒟蒻!!!
A
/*************************************************************************
> File Name: A.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月28日 星期日 13时33分32秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ int n, A[]; int main(void) {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = ; i < n; i++) cin >> A[i];
sort(A, A + n);
long long res = ;
for (int i = n - ; i >= ; i -= ) res += A[i];
cout << res << endl;
}
return ;
}
B
处理出每个素数在所有数中出现的次数最多的个数。
/*************************************************************************
> File Name: B.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月28日 星期日 13时36分46秒
> 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!!!*/ typedef pair<int, int> pii;
const int MAX_N = ;
const int MAX_M = ;
bool vis[MAX_M];
int prime[MAX_N], A[MAX_N], cnt; void init() {
cnt = ;
memset(vis, false, sizeof(vis));
for (int i = ; i < MAX_M; i++) {
if (!vis[i]) {
prime[++cnt] = i;
for (int j = *i; j < MAX_M; j += i) vis[j] = true;
}
}
} #define rep(i, n) for (int i = (1); i <= (n); i++) vector<pii> factor(MAX_M);
vector<pii>::iterator it; void work(int x, int y) {
if (factor[x].second == ) {
factor[x].second = y; }
else {
factor[x].second = max(y, factor[x].second);
}
} int main(void) {
init();
ios::sync_with_stdio(false);
int t, n;
cin >> t;
while (t--) {
rep (i, MAX_M) factor[i-].second = ;
cin >> n;
rep (i, n) cin >> A[i];
rep (i, n) {
int x = A[i];
if (x == ) continue;
rep (j, cnt) {
if (prime[j]*prime[j] > A[i]) break;
if (x % prime[j] == ) {
int tmp = ;
while (x % prime[j] == ) tmp++, x /= prime[j];
work(prime[j], tmp);
}
}
if (x > ) work(x, );
}
int res = ;
for (it = factor.begin(); it != factor.end(); ++it) {
res += it->second;
}
cout << res << endl;
} return ;
}
C
线段树。
对于第一种修改,就是区间减1
对于第二种修改,就是单点更新
最后,查询每个点2,3,5因子的个数。
/*************************************************************************
> File Name: C.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月28日 星期日 14时06分24秒
> Propose:
************************************************************************/
#include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int MAX_N = ;
int factor[][MAX_N], A[MAX_N], id[MAX_N];
#define rep(i, n) for (int i = (1); i <= (n); i++)
#define lson(x) ((x<<1))
#define rson(x) ((x<<1) | 1) struct node {
int l, r, Min[];
}Tr[MAX_N<<]; void build(int rt, int l, int r) {
Tr[rt].l = l, Tr[rt].r = r;
rep(i, ) Tr[rt].Min[i-] = ;
if (l == r) {
rep (i, ) Tr[rt].Min[i-] = factor[i-][l];
id[l] = rt;
return ;
}
int mid = (l + r) / ;
build(lson(rt), l, mid);
build(rson(rt), mid + , r);
} void pushdown(int rt, int p) {
if (Tr[rt].Min[p] != ) {
Tr[lson(rt)].Min[p] += Tr[rt].Min[p];
Tr[rson(rt)].Min[p] += Tr[rt].Min[p];
Tr[rt].Min[p] = ;
}
} void update1(int rt, int l, int r, int p) {
if (Tr[rt].l >= l && Tr[rt].r <= r) {
Tr[rt].Min[p]--;
return ;
}
pushdown(rt, p);
int mid = Tr[lson(rt)].r;
if (l <= mid) update1(lson(rt), l, r, p);
if (r > mid) update1(rson(rt), l, r, p);
} void update2(int rt, int l, int p, int d) {
if (Tr[rt].l == Tr[rt].r && Tr[rt].l == l) {
Tr[rt].Min[p] = d;
return ;
}
pushdown(rt, p);
int mid = Tr[lson(rt)].r;
if (l <= mid) update2(lson(rt), l, p, d);
else update2(rson(rt), l, p, d);
} int query(int rt, int l, int p) {
if (Tr[rt].l == Tr[rt].r && Tr[rt].l == l) {
return max(Tr[rt].Min[p], );
}
pushdown(rt, p);
int mid = Tr[lson(rt)].r;
if (l <= mid) query(lson(rt), l, p);
else query(rson(rt), l, p);
} void read(int &res) {
res = ;
char c = ' ';
while (c < '' || c > '') c = getchar();
while (c >= '' && c <= '') res = res*+c-'', c = getchar();
} int POW(int a, int b) {
int res = ;
while (b) {
if (b & ) res *= a;
a *= a;
b >>= ;
}
return res;
} int main(void) {
int N, M, a[] = {, , , };
read(N);
rep (i, N) {
read(A[i]);
int x = A[i];
factor[][i] = factor[][i] = factor[][i] = ;
rep (j, ) {
int tmp = , p = a[j];
while (x % p == ) tmp++, x /= p;
factor[j-][i] = tmp;
}
A[i] = x;
}
build(, , N);
read(M);
int t, l, r, p, d, tmp;
while (M--) {
read(t);
if (t == ) {
read(l), read(r), read(p);
update1(, l, r, (p+)/-);
} else {
read(l), read(d);
rep (i, ) {
tmp = , p = a[i];
while (d % p == ) tmp++, d /= p;
update2(, l, i-, tmp);
}
A[l] = d;
}
}
rep (i, N) {
rep (j, ) {
tmp = query(, i, j-);
A[i] *= POW(a[j], tmp);
}
printf("%d%c", A[i], i == N ? '\n' : ' ');
} return ;
}
D
LTIME16小结(CodeChef)的更多相关文章
- 从零开始编写自己的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 ...
随机推荐
- centos6 php5.4 升級到php 5.6
因Centos6中的PHP版本有点底,需要升级PHP版本 [vagrant@localhost ~]$ php -v PHP 5.4.45 (cli) (built: Sep 30 2015 15:0 ...
- 233 Matrix
233 Matrix 有一\(n\times m\)的矩阵\(\{a\}\),定义\(a[0][0]=0,a[0][1]=233,a[0][2]=2333,a[0][3]=23333...\),然后给 ...
- 廖雪峰Java12maven基础-2maven进阶-1使用插件
1.maven的Lifecycle,Phase和Goal: 使用maven构建项目就是执行Lifecycle 执行Lifecycle就是按顺序执行一系列Phase 每执行一个Phase,都会执行该Ph ...
- 区间dp——cf1025D二叉搜索树的中序遍历好题!
这题帮我复习了一下BST的中序遍历.. 因为给定的数组是递增的,那么BST的中序遍历一定是1 2 3 4 5 6 7 8 9 ... n 即[l,r]为左子树,那么根节点就是r+1,反之根节点就是l- ...
- c++ static关键字的作用
1.被申明的函数或值无法被其他源文件使用 2.static的第二个作用是保持变量内容的持久.(static变量中的记忆功能和全局生存期) 存储在静态数据区的变量会在程序刚开始运行时就完成初始化,也是唯 ...
- IOS6 新特性之UIActivityViewController详解
新的IOS6增加了一些新特性.因为应用需要,所以在国庆的几天里.研究了一下IOS6的说明文档,然后大概地总结了一下UIActivityViewController的用法与大家分享. 首先 从实际效果入 ...
- 菜鸟nginx源码剖析数据结构篇(六) 哈希表 ngx_hash_t(上)[转]
菜鸟nginx源码剖析数据结构篇(六) 哈希表 ngx_hash_t(上) Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.c ...
- 解决windows8.1的依赖
- windows下bat批量处理启动exe
新建文本文档,start.dat start "" "D:\QQ\anzhaung\Bin\QQ.exe" 启动QQ cd ./当前文件夹下,../上一文件夹下 ...
- 使用git命令从github上clone项目
首先创建本地仓库(实际上就是创建一个文件夹,放项目代码),然后cd进文件夹, 初始化空的git仓库 注意:这里不初始化也是可以clone的 然后git clone url(url表示项目网址) 然后就 ...