您的位置:首页 > 其它

map Codeforces Round #Pi (Div. 2) C. Geometric Progression

2015-08-06 21:11 423 查看
题目传送门

 /*
题意:问选出3个数成等比数列有多少种选法
map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数。别人的代码很短,思维巧妙
*/
/************************************************
* Author        :Running_Time
* Created Time  :2015-8-6 1:07:18
* File Name     :C.cpp
************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
map<ll, ll> c1, c2;

int main(void)    {     //Codeforces Round #Pi (Div. 2) C. Geometric Progression
ll ans = 0, x;  ll n, k;
scanf ("%I64d%I64d", &n, &k);
for (int i=1; i<=n; ++i)    {
scanf ("%I64d", &x);
if (x % (k * k) == 0)   ans += c1[x/k];     //x可选作第三个数
if (x % k == 0) c1[x] += c2[x/k];           //x第三个数或第二个数
c2[x]++;
}

printf ("%I64d\n", ans);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: