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

题目传送门

 1 /*
 2     题意:问选出3个数成等比数列有多少种选法
 3     map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数。别人的代码很短,思维巧妙
 4 */
 5 /************************************************
 6  * Author        :Running_Time
 7  * Created Time  :2015-8-6 1:07:18
 8  * File Name     :C.cpp
 9  ************************************************/
10
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 2e5 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36 map<ll, ll> c1, c2;
37
38 int main(void)    {     //Codeforces Round #Pi (Div. 2) C. Geometric Progression
39     ll ans = 0, x;  ll n, k;
40     scanf ("%I64d%I64d", &n, &k);
41     for (int i=1; i<=n; ++i)    {
42         scanf ("%I64d", &x);
43         if (x % (k * k) == 0)   ans += c1[x/k];     //x可选作第三个数
44         if (x % k == 0) c1[x] += c2[x/k];           //x第三个数或第二个数
45         c2[x]++;
46     }
47
48     printf ("%I64d\n", ans);
49
50     return 0;
51 }
时间: 2024-12-17 01:22:18

map Codeforces Round #Pi (Div. 2) C. Geometric Progression的相关文章

Codeforces Round #Pi (Div. 2) (STL专场)

Codeforces Round #Pi (Div. 2) A - Lineland Mail 水题,拼手速. /* * @author Novicer * language : C++/C */ #include<iostream> #include<sstream> #include<fstream> #include<vector> #include<list> #include<deque> #include<queue

构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

题目传送门 1 /* 2 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 3 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-6 0:23:37 8 * File Name :B.cpp 9

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

Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers. He wants to know how many subsequences of

Codeforces Round #Pi (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/567 听说Round #Pi的意思是Round #314... A. Lineland Mail time limit per test:3 seconds memory limit per test:256 megabytes All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with it

Codeforces Round #Pi (Div. 2)(A,B,C,D)

A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include

Codeforces Round #Pi (Div. 2) E. President and Roads (最短路+强连通求割边)

题目地址:codeforces #pi (DIV2) E 题目很水..就是先求两边最短路,然后把可能为最短路的边挑出来,然后判断是否yes只需要转化成无向图跑一遍tarjan,找出割边,割边就是yes,然后剩下的边就让它的值为最短路-1就行了,如果-1后变成了非正数,就是no. 但是!!!居然卡spfa!!那是不是说cf以后就不能用可以卡的算法了..完全可以出组数据来卡这些算法...比如spfa,isap... 于是为了这题,又看了一遍迪杰斯特拉算法.. 代码如下: #include <cstd

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

题意: 现在有n个数,然后给出一个数k(代表的是等比数列中的那个公比),然后第二行给出n个数,代表的是这个序列. 最后的问题是叫你找出在这个序列中满足公比为k的三个数有几种,并输出方案总数. 思路: 这道题很巧妙啊,用到了map. 首先我们先记录下每种数出现过了几次,这里因为数太大了,直接用数组存会爆掉,所以改用map. 我们需要两个map,分别记为mp1,mp2. 然后在for的过程中,我们是以当前的那个数为第二项,然后去寻找它的mp1[a[i]*k](也就是第三项),寻找它的mp2[a[i]

Codeforces Round #Pi (Div. 2) —— D One-Dimensional Battle Ships

题目的意思是: 现在有一个长度为n,宽为1的方格,在上面可以放大小为1*a船,然后输入为n,k,a:分别为平地的大小,船的数量,船的长度. 一个叫alice的人已经在地图上摆好了船的位置. 然后bob总共可以有m次攻击的机会,然后他每次攻击的点为xi,但是alice并不会告诉它有没有打中(也就是说每次都认为他是miss的),问你,bob可以在第几次攻击的时候推测出alice在撒谎,如果推测不出来则输出-1. 这里每两条相邻的船不能相互接壤. 思路: 用set来维护每一段的区间. 首先,我们最多可

Codeforces Round #Pi (Div. 2)——set——Berland National Library

Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated reading roo