codeforces#314C&567C Geometric Progression
来源:互联网 发布:mud游戏编程 下载 编辑:程序博客网 时间:2024/05/03 12:48
题目大意:有一个长度为n的序列,让你从这之中找到长度为3(三个数)且能成公比为k的序列,问一共有多少组这样的序列。
解题思路:map即可搞定
注意点:公比为k的意思是除了这三个数之间有k倍的关系,但我没理解到他们本身也必须是k的倍数这一点~~
还有a【i】*k的时候会溢出,一定要打个long long符号才行;
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<set>#include<map>using namespace std;typedef long long LL;const int maxn=2*100000+100;int a[maxn];int n,k;map<LL,LL> s,s2;//s用于存储“当前的数”之前的某个数的个数,s2是它之后的某个数int main(){ while(scanf("%d%d",&n,&k)!=EOF) { s.clear(); s2.clear(); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); s2[a[i]]++; } LL ans=0; for(int i=1; i<n; i++) //枚举中值 { if(i==1) { s2[a[i]]--; s[a[i]]++; } else { s2[a[i]]--; if(a[i]%k==0) { ans+=(LL)s[a[i]/k]*(LL)s2[(LL)a[i]*k]; } s[a[i]]++; } } cout<<ans<<endl; }}
1 0
- codeforces#314C&567C Geometric Progression
- codeforces(567C)-- Geometric Progression
- codeforces 567C Geometric Progression
- Codeforces 567C Geometric Progression
- CodeForces 567C Geometric Progression
- CodeForces 567C Geometric Progression
- codeforces 567C Geometric Progression (map维护)
- Codeforces 567C Geometric Progression (离散 + DP)
- CodeForces 567C Geometric Progression【思维+map】
- CodeForces #Pi C.Geometric Progression
- CF-567C - Geometric Progression
- CF 567C. Geometric Progression
- codeforces 567E C. Geometric Progression(dp+STL)
- CodeForces 567C. Geometric Progression(map 数学啊)
- CodeForces 567C. - Geometric Progression(解题报告)
- codeforce 567c Geometric Progression(map)
- CF 567C(Geometric Progression-map)
- Codeforces Round #Pi (Div. 2) C. Geometric Progression dp
- [leetcode 240]Search a 2D Matrix II
- Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the desi
- 链表头结点作用
- 怎样设置才能允许外网访问MySQL
- 8大JS库/框架对比
- codeforces#314C&567C Geometric Progression
- Struts2里面 s:textfield标签 Date类型的格式化以及日期时间控件使用
- android 5.0新特性学习总结之阴影特效(二)
- matlab 判断网络是在多边形之内,之外还是边界上。papa的儿子
- HDOJ 2025 查找最大元素(水)
- IntelliJ IDEA 代码检查规范QAPlug
- LeetCodeOJ.Number of Digit One
- 关于jquery重复引包的问题
- iOS安全系列之一:HTTPS