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 |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
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 (规律)的更多相关文章
- TC srm 673 300 div1
TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...
- tc srm 636 div2 500
100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 597 DEV2
第一次玩TC的SRM,只完成了一题,有点失落,不过还是要把每个问题都研究清楚才是我的本性,呵呵 第一题思路: 任意一个数,不断除掉2以后的剩下的数若相同则YES否则NO 第二题: 最开始判断字母个数是 ...
- TC SRM 593 DIV1 250
我只能说的亏没做,要不就挂0了.. 本来想四色定理,肯定4就可以的...然后准备爆,发现3的时候不好爆,又想了老一会,嗯,数据范围不小,应该不是暴力,直接找规律,貌似最大就是3,有一个3连块,输出3, ...
- TC SRM 584 DIV 2
第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...
- TC SRM 664 div2 B BearPlaysDiv2 bfs
BearPlaysDiv2 Problem Statement Limak is a little bear who loves to play. Today he is playing by ...
- TC SRM 663 div2 B AABB 逆推
AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...
- TC SRM 663 div2 A ChessFloor 暴力
ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...
- TC SRM 665 DIV2 A LuckyXor 暴力
LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...
随机推荐
- codeforces #235div2 D
完全没看出是状态压缩DP, 果然没练习,之前一直再看,看来要把状压做几道了, 上代码吧:代码也是问道的 无语... #include<cstdio> #include<cstring ...
- 遭遇Asp.Net长文件名下载的问题和解决办法
在Asp.Net中写了一个附件上传和下载的程序,附件上传到数据库中,然后将附件的GUID保存起来,我们可以根据GUID来找到数据库中的附件,一般附件下载的代码是: <!--<br /> ...
- HTTP状态码一览表(HTTP Status Code)
copy from:http://www.189works.com/article-43064-1.html 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 ( ...
- mapred和mapreduce
总体上看,Hadoop MapReduce分为两部分:一部分是org.apache.hadoop.mapred.*,这里面主要包含旧的API接口以及MapReduce各个服务(JobTracker以及 ...
- 你必须知道的ADO.NET
原文:http://www.cnblogs.com/liuhaorain/archive/2012/02/06/2340409.html 1. 什么是ADO.NET? 简单的讲,ADO.NET是一组允 ...
- leetcode majority number
给定一组数,有一个数在这组数里的出现次数超过n/2次. 求出这是哪个数 https://leetcode.com/problems/majority-element/ 一开始考虑的方是将所有数转化为二 ...
- JavaScript call和apply的用法
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 学习android的博客
http://www.cnblogs.com/hll2008/http://svn.apache.org/repos/asf/http://blog.csdn.net/chenzheng_javaht ...
- ExtJS之Ext.getDom
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- WCF分布式开发步步为赢(2)自定义托管宿主WCF解决方案开发配置过程详解
上一节<WCF分布式框架基础概念>我们介绍了WCF服务的概念和通信框架模型,并给出了基于自定义托管服务的WCF程序的实现代码.考虑到WCF分布式开发项目中关于托管宿主服务配置和客户端添加引 ...