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的个数,求其子序列里能够构成的等比序列的个数。

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

这应该算是一个看数字的规律题吧,我找的也挺慢的,不过想想二进制下每一位代表的数字 比较 一下规格,应该不难猜出来这个 等比 和 等差的规律

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#define LL __int64
const double eps = 1e-;
const int maxn = +;
using namespace std; class PotentialGeometricSequence
{
public:
int numberOfSubsequences(vector <int> d)
{
int n = d.size();
int i, j, ret = n+n-, f, x, k, y;
for(i = ; i < n; i++)
{
for(j = ; j < n; j++)
{
if(j+i < n)
{
f = ;
x = d[j+]-d[j];
for(k = j+; k <= j+i; k++)
{
y = d[k]-d[k-];
if(y!=x)
f = ;
}
if(f == )
ret ++;
}
}
}
return ret;
}
};

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

  1. TC srm 673 300 div1

    TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...

  2. tc srm 636 div2 500

    100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...

  3. TC SRM 597 DEV2

    第一次玩TC的SRM,只完成了一题,有点失落,不过还是要把每个问题都研究清楚才是我的本性,呵呵 第一题思路: 任意一个数,不断除掉2以后的剩下的数若相同则YES否则NO 第二题: 最开始判断字母个数是 ...

  4. TC SRM 593 DIV1 250

    我只能说的亏没做,要不就挂0了.. 本来想四色定理,肯定4就可以的...然后准备爆,发现3的时候不好爆,又想了老一会,嗯,数据范围不小,应该不是暴力,直接找规律,貌似最大就是3,有一个3连块,输出3, ...

  5. TC SRM 584 DIV 2

    第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...

  6. TC SRM 664 div2 B BearPlaysDiv2 bfs

    BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by ...

  7. TC SRM 663 div2 B AABB 逆推

    AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...

  8. TC SRM 663 div2 A ChessFloor 暴力

    ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...

  9. TC SRM 665 DIV2 A LuckyXor 暴力

    LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...

随机推荐

  1. 三维云模拟Three.js

    http://www.mrdoob.com/#/131/clouds http://www.webgl.com/2012/03/webgl-demo-clouds/ <!DOCTYPE html ...

  2. Mac OS 上设置 JAVA_HOME

    Mac OS 上设置 JAVA_HOME 原文链接:http://han.guokai.blog.163.com/blog/static/136718271201301183938165/ 由于需要, ...

  3. IE6 IE7 IE8(Q) 不支持 JSON 对象

    标准参考 JSON 是一种数据交换格式,RFC 4627 对 JSON 进行了详细描述. 根据 ECMA-262(ECMAScript)第 5 版中描述,JSON 是一个包含了函数 parse 和 s ...

  4. Sqli-labs less 48

    Less-48 本关与less-46的区别在于报错注入不能使用,不进行错误回显,因此其他的方法我们依旧是可以使用的. 可以利用sort=rand(true/false)进行判断. http://127 ...

  5. allow_url_include和allow_url_fopen

    allow_url_fopen没什么好说的,主要是allow_url_include 从PHP5.2开始allow_url_include就默认为Off了,而allow_url_fopen一直是On的 ...

  6. Razor语法学习

    原文:http://www.cnblogs.com/youring2/archive/2011/07/24/2115254.html 1.Razor的文件类型 Razor支持两种文件类型,分别是.cs ...

  7. POJ 2484

    A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3861   Accepted: 2311 Desc ...

  8. Spinner学习

    我暂且把Spinner称作下拉选择框吧,先来看一下它的效果: 在layout文件中添加Spinner的代码如下: <Spinner android:id="@+id/planets_s ...

  9. HtmlAgilityPack 之 HtmlNode类

    HtmlAgilityPack中的HtmlNode类与XmlNode类差不多,提供的功能也大同小异.下面来看看该类提供功能. 一.静态属性 public static Dictionary<st ...

  10. Java Applet与Java Application的特点

    java application是应用程序,用于桌面开发,java applet是小应用程序,一般嵌入到网页里运行.applet一般用于B/S页面上作为插件式的开发,而application主要是桌面 ...