tc srm 632 500 (规律)


We have a sequence of N positive integers: a[0] through a[N-1]. You do not know these integers. All you know is the number of trailing zeros in their binary representations. You are given a vector <int> d with N elements. For each i, d[i] is the number of trailing zeros in the binary representation of a[i].

For example, suppose that a[0]=40. In binary, 40 is 101000 which ends in three zeros. Therefore, d[0] will be 3.

You like geometric sequences. (See the Notes section for a definition of a geometric sequence.) You would like to count all non-empty contiguous subsequences of the sequence a[0], a[1], ..., a[N-1] that can be geometric sequences (given the information you have in d).

More precisely: For each pair (i,j) such that 0 <= i <= j <= N-1, we ask the following question: "Given the values d[i] through d[j], is it possible that the values a[i] through a[j] form a geometric sequence?"

For example, suppose that d = {0,1,2,3,2}. For i=0 and j=3 the answer is positive: it is possible that the values a[0] through a[3] are {1,2,4,8} which is a geometric sequence. For i=1 and j=4 the answer is negative: there is no geometric sequence with these numbers of trailing zeros in binary.

Compute and return the number of contiguous subsequences of a[0], a[1], ..., a[N-1] that can be geometric sequences.

Definition

    
Class: PotentialGeometricSequence
Method: numberOfSubsequences
Parameters: vector <int>
Returns: int
Method signature: int numberOfSubsequences(vector <int> d)
(be sure your method is public)

Limits

    
Time limit (s): 2.000
Memory limit (MB): 256

Notes

- A geometric sequence is any sequence g[0], g[1], ..., g[k-1] such that there is a real number q (the quotient) with the property that for each valid i, g[i+1] = g[i]*q. For example, {1,2,4,8} is a geometric sequence with q=2, {7,7,7} is a geometric sequence with q=1, and {18,6,2} is a geometric sequence with q=1/3.

Constraints

- N will be between 1 and 50, inclusive.
- d will contain exactly N elements.
- Each element of d will be between 0 and 100, inclusive.

d是二进制下这个数的末尾的0的个数,求其子序列里能够构成的等比序列的个数。

分析:求其等差子序列的个数

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <vector>
 8 #define LL __int64
 9 const double eps = 1e-8;
10 const int maxn = 100+10;
11 using namespace std;
12
13 class PotentialGeometricSequence
14 {
15  public:
16     int numberOfSubsequences(vector <int> d)
17     {
18         int n = d.size();
19         int i, j, ret = n+n-1, f, x, k, y;
20         for(i = 2; i < n; i++)
21         {
22             for(j = 0; j < n; j++)
23             {
24                 if(j+i < n)
25                 {
26                     f = 0;
27                     x = d[j+1]-d[j];
28                     for(k = j+2; k <= j+i; k++)
29                     {
30                         y = d[k]-d[k-1];
31                         if(y!=x)
32                         f = 1;
33                     }
34                     if(f == 0)
35                     ret ++;
36                 }
37             }
38         }
39         return ret;
40     }
41 };
时间: 2024-10-07 09:10:53

tc srm 632 500 (规律)的相关文章

TC SRM 649 500分题

Problem Statement      You are given an integer sequence A and an int N that is a power of 2. All elements of A are between 0 and N-1, inclusive. You can now choose an integer B which is between 0 and N-1, inclusive. This integer determines a new seq

[TC SRM 697 div1 lev1] DivisibleSetDiv1

Tutorial:https://apps.topcoder.com/wiki/display/tc/SRM+697#DivisibleSetDiv1 Note:证明过程值得一看. 主要内容:寻找[x1,x2,...,xn]使得满足bi * xi >= S - xi,其中S = x1 + x2 + ... + xn.

TC srm 673 300 div1

TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能够组成一个骑兵,这个骑兵的战斗力等于马的战斗力乘以人的战斗力,问你有多少种组合方式满足其他骑兵的战斗力都不超过第0号骑兵. Input Output Sample Input Sample Output HINT 题意 题解: 大概就暴力枚举哪匹马和第0号人匹配,后面的骑兵我们按照战斗力从大到小排序之后,

Topcoder SRM 630 (500 floyed 暴力 _builtin_popcount())

题意:给n个点,保证图联通,给点相连的距离,求一个最多的点,这些点之间的距离都是相同的. 分析: 下面的代码是我们房间第一的大神的,写的很简洁,我的思路和他的一样,但是我不知道错哪了. 思路是暴力枚举,最多有10个点,先用floyed计算出每两点之间的距离,然后用位运算暴力枚举, 枚举每个点是否加入进去,并用set把每个加入进去的点之间的距离加进去,如果距离唯一,说明点之间所有的距离相同, 然后用_builtin_popcount()计算二进制中多少个1 ,即表示加入了多少个点,求最大. Top

tc srm 636 div2 500

100的数据直接暴力就行,想多了... ac的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #include <vector> 8 #define LL __int64 9 const int maxn =

TC SRM 637 DIV1 500 PathGame

Problem Statement 给一个2*1000的board,每个格子黑或者白.白格子从左到右连成一条连接第一列和最后一列的path,path上相邻两格有公共边.两人轮流把白格子涂成黑格子,最后一个被迫涂黑格子使path断开的人输.问先手必胜还是必败. (Translated By myq_952) Tutorial 做sg的题有点生(有什么生不生的不就dp嘛) 考虑以一段2*k的全白矩形作为局面,涂黑一个格子会把原局面拆成两个后继局面,然后$n^2$求局面的sg即可 要注意的是,因为本题

TC SRM 665 DIV2 A LuckyXor 暴力

LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive integer consisting of only the digits 4 and 7.Given an int a, return an int b strictly greater than a, such that a XOR b is a lucky number. (See Notes fo

TC SRM 664 div2 B BearPlaysDiv2 bfs

BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by moving some stones between three piles of stones. Initially, the piles contain A, B, and C stones, respectively. Limak's goal is to produce three equa

TC SRM 663 div2 A ChessFloor 暴力

ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a square room. The floor of the room is an N times N grid of unit square tiles. Each tile has some color. You are given the current colors of all tiles in a