CodeForces 567C Geometric Progression 类似dp的递推统计方案数
input
n,k 1<=n,k<=200000
a1 a2 ... an
1<=ai<=1e9
output
数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b*k*k的种数
做法:先将可以作为第三个数的数放到map中,然后再扫一遍依次统计map中的数作为第三个数的种数,第二个数的种数,第三个数的种数
#include<cstdio>
#include<map>
struct node
{
int b;//a[i]作为i1的种数
long long c;//a[i]作为i2的种数
};
using namespace std;
int a[], n, k;
long long k2, sum;
map<int,node>q;
map<int,node>::iterator j;
int main()
{
while (scanf("%d%d", &n, &k) == )
{
q.clear();
k2 = (long long)k*k;
node u;
sum = u.b = u.c = ;
for (int i = ; i < n; i++)
{
scanf("%d", &a[i]);
if (!(a[i] % k2)) q.insert(make_pair(a[i] / k2,u));//统计出所有的i3
}
if (q.empty()) { puts("");continue; }
for (int i = ; i < n; i++)
{
if (a[i] % k2 == )//a[i]作为i3
{
j = q.find(a[i]/k2);//找i2
if(j!=q.end()) sum += j->second.c;//累加到总方法数
}
if (a[i] % k == )//a[i]作为i2
{
j = q.find(a[i] / k);//找i1
if (j != q.end()) j->second.c += j->second.b;//累加到i2的方法数
}
j = q.find(a[i]);//a[i]作为i1找i1
if (j != q.end()) j->second.b++;//累加
}
printf("%lld\n", sum);
}
return ;
}
CodeForces 567C Geometric Progression 类似dp的递推统计方案数的更多相关文章
- CodeForces 567C Geometric Progression
Geometric Progression Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- CodeForces 567C. Geometric Progression(map 数学啊)
题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...
- Codeforces 567C - Geometric Progression - [map维护]
题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...
- Codeforces 567C Geometric Progression(思路)
题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...
- [AHOI2009]中国象棋 DP,递推,组合数
DP,递推,组合数 其实相当于就是一个递推推式子,然后要用到一点组合数的知识 一道很妙的题,因为不能互相攻击,所以任意行列不能有超过两个炮 首先令f[i][j][k]代表前i行,有j列为一个炮,有k列 ...
- UVa 926【简单dp,递推】
UVa 926 题意:给定N*N的街道图和起始点,有些街道不能走,问从起点到终点有多少种走法. 很基础的dp.递推,但是有两个地方需要注意,在标记当前点某个方向不能走时,也要同时标记对应方向上的对应点 ...
- Codeforces 567C:Geometric Progression(DP)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- Codeforces Round #271 (Div. 2) D. Flowers (递推)
题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类 ...
- HDU 5965 三维dp 或 递推
题意:= =中文题 思路一:比赛时队友想的...然后我赛后想了一下想了个2维dp,但是在转移的时候,貌似出了点小问题...吧?然后就按照队友的思路又写了一遍. 定义dp[i][j][k],表示第i列, ...
随机推荐
- html的简单表单制作...day5 php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 图片翻转(Raw Image)
int TransformImageBuffer(unsigned char* pImageBuffer, int width, int height,unsigned char* targetIma ...
- scala 访问权限详解
private/protected [包名/类名/this] 即可指定变量的作用域.(this代表只有当前实例(即对象)可以访问) 伴生类和伴生对象中的成员可以相互访问. class PackageO ...
- ansible 判断和循环
标准循环 模式一 - name: add several users user: name={{ item }} state=present groups=wheel with_items: - te ...
- Python 智能处理方向的工具
机器视觉类:OpenCV. 自然语言处理:NLTK, jieba(Python中文分词组件),HanLP, FudanNLP, NLPIR, http://tm.itc.ntnu.edu.tw/CNL ...
- adb shell dumpsys
adb shell dumpsys activity activities -- class/packagename adb shell dumpsys batterystate --reset ...
- python 基础学习-总结1
1.Python 简介 易学易懂,语法简单 不需编译,即可运行 比其他语言更简洁 不需要管理内存 1.1 什么是Python? python 是由Guido.van.Rossum于1989年始创,其根 ...
- 共享AFHTTPSessionManager 单例好处浅析
很多时候,AFNetworking都是目前iOS开发者网络库中的不二选择.Github上2W+的star数足见其流行程度.而从iOS7.0开始,苹果推出了新的网络库继承者NSURLSession后 ...
- 获取所有input值 处理成json格式再利用$.post提交
<script>$(document).ready(function(){ $("#sub").click(function(){ var ...
- hexo常用命令笔记
hexo npm install -g hexo npm update -g hexo hexo init 常用 hexo n == hexo new "a new post" 新 ...