题目传送门

题意:判断是否是等比数列

分析:高精度 + 条件:a[i] * a[i+2] == a[i+1] * a[i+1]。特殊情况:0 0 0 0 0是Yes的,1 2 0 9 2是No的

代码:

/************************************************
* Author :Running_Time
* Created Time :2015-9-5 20:06:46
* 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 N = 1e2 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int numlen = 2005; // 需要的位数
const int numbit = 4; // 数组一位表示的整数
const int addbit = 10000;//进位数
const int maxn = numlen/numbit + 10; // 数组要开的位数 int max(int a, int b) { return a>b?a:b; }
struct bign {
int len, s[numlen];
bign() {
memset(s, 0, sizeof(s));
len = 1;
}
bign(int num) { *this = num; }
bign(const char *num) { *this = num; }
bign operator = (const int num) {
char s[numlen];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char *num) {
int clen = strlen(num);
while(clen > 1 && num[0] == '0') num++, clen--;
len = 0;
for(int i = clen-1;i >= 0;i -= numbit) {
int top = min(numbit, i+1), mul = 1;
s[len] = 0;
for(int j = 0;j < top; j++) {
s[len] += (num[i-j]-'0')*mul;
mul *= 10;
}
len++;
}
deal();
return *this;
} void deal() {
while(len > 1 && !s[len-1]) len--;
} bign operator + (const bign &a) const {
bign ret;
ret.len = 0;
int top = max(len, a.len) , add = 0;
for(int i = 0;add || i < top; i++) {
int now = add;
if(i < len) now += s[i];
if(i < a.len) now += a.s[i];
ret.s[ret.len++] = now%addbit;
add = now/addbit;
}
return ret;
}
bign operator - (const bign &a) const {
bign ret;
ret.len = 0;
int cal = 0;
for(int i = 0;i < len; i++) {
int now = s[i] - cal;
if(i < a.len) now -= a.s[i];
if(now >= 0) cal = 0;
else {
cal = 1; now += addbit;
}
ret.s[ret.len++] = now;
}
ret.deal();
return ret;
}
bign operator * (const bign &a) const {
bign ret;
ret.len = len + a.len;
for(int i = 0;i < len; i++) {
int pre = 0;
for(int j = 0;j < a.len; j++) {
int now = s[i]*a.s[j] + pre;
pre = 0;
ret.s[i+j] += now;
if(ret.s[i+j] >= addbit) {
pre = ret.s[i+j]/addbit;
ret.s[i+j] -= pre*addbit;
}
}
if(pre) ret.s[i+a.len] = pre;
}
ret.deal();
return ret;
} //乘以小数,直接乘快点 ***********注意计算过程可能会爆int
bign operator * (const int num) {
bign ret;
ret.len = 0;
int bb = 0;
for(int i = 0;i < len; i++) {
int now = bb + s[i]*num;
ret.s[ret.len++] = now%addbit;
bb = now/addbit;
}
while(bb) {
ret.s[ret.len++] = bb % addbit;
bb /= addbit;
}
ret.deal();
return ret;
}
// 除以一个小整数 ***********注意计算过程可能会爆int
bign operator / (const int a) const {
bign ret;
ret.len = len;
int pre = 0;
for(int i = len-1;i >= 0; i--) {
ret.s[i] = (s[i] + pre*addbit)/a;
pre = s[i] + pre*addbit - a*ret.s[i];
}
ret.deal();
return ret;
} bign operator % (const int a) const {
bign b = *this / a;
return *this - b*a;
} bign operator += (const bign &a) { *this = *this + a; return *this; }
bign operator -= (const bign &a) { *this = *this - a; return *this; }
bign operator *= (const bign &a) { *this = *this * a; return *this; }
bign operator /= (const int a) { *this = *this / a; return *this; }
bign operator %= (const int a) { *this = *this % a; return *this; } bool operator < (const bign &a) const {
if(len != a.len) return len < a.len;
for(int i = len-1;i >= 0; i--) if(s[i] != a.s[i])
return s[i] < a.s[i];
return false;
}
bool operator > (const bign &a) const { return a < *this; }
bool operator <= (const bign &a) const { return !(*this > a); }
bool operator >= (const bign &a) const { return !(*this < a); }
bool operator == (const bign &a) const { return !(*this > a || *this < a); }
bool operator != (const bign &a) const { return *this > a || *this < a; } void print() {
printf("%d", s[len-1]);
for(int i = len-2;i >= 0; i--) {
printf("%04d", s[i]);
}
puts("");
} string str() const {
string ret = "";
for(int i = 0;i < len; i++) ret = char(s[i] + '0') + ret;
return ret;
}
};
istream& operator >> (istream &in, bign &x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream &out, const bign &x) {
printf("%d", x.s[x.len-1]);
for(int i = x.len-2;i >= 0; i--) printf("%04d", x.s[i]);
return out;
}
bign a[N]; int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) cin >> a[i];
bool flag = true; int zero = 0;
for (int i=1; i<=n; ++i) {
if (a[i] == 0) {
zero++;
}
}
if (n == 1 || zero == n) {
puts ("Yes"); continue;
}
if (zero > 0) {
puts ("No"); continue;
}
else {
for (int i=1; i<=n-2; ++i) {
if (a[i] * a[i+2] != a[i+1] * a[i+1]) {
flag = false; break;
}
}
} puts (flag ? "Yes" : "No");
} return 0;
}

  

BestCoder Round #54 (div.2) 1003 Geometric Progression的更多相关文章

  1. DP BestCoder Round #50 (div.2) 1003 The mook jong

    题目传送门 /* DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp ...

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

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

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

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

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

    C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. BestCoder Round #81 (div.2) 1003 String

    题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=691&pid=1003题意:找出一个字符串满足至少 ...

  6. BestCoder Round #50 (div.1) 1003 The mook jong (HDU OJ 5366) 规律递推

    题目:Click here 题意:bestcoder 上面有中文题目 分析:令f[i]为最后一个木人桩摆放在i位置的方案,令s[i]为f[i]的前缀和.很容易就能想到f[i]=s[i-3]+1,s[i ...

  7. ACM学习历程—HDU5587 Array(数学 && 二分 && 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后 ...

  8. 素数+map BestCoder Round #54 (div.2) 1002 The Factor

    题目传送门 题意:给出一个数列,问数列的乘积的一个满足条件的最小因子是什么,没有输出-1.条件是不是素数 分析:官方题解:对于每一个数字,它有用的部分其实只有它的所有质因子(包括相等的).求出所有数的 ...

  9. 哈密顿图 BestCoder Round #53 (div.2) 1003 Rikka with Graph II

    题目传送门 题意:判断是否为哈密顿图 分析:首先一种情况是不合法的:也就是度数为1的点超过2个:合法的有:,那么从度数为1的点开始深搜,如果存在一种走法能够走完n个点那么存在哈密顿路 收获:学习资料 ...

随机推荐

  1. 甘特图——Excel搞定

    1. 甘特图 概念 甘特图就是条形图的一种. 甘特图是基于作业排序的目的,将活动与时间联系起来的最早尝试之中的一个. 这是什么意思呢?也就是说甘特图用来表示什么时间做什么事情,相当于一个计划安排.并且 ...

  2. HDU 6138 Fleet of the Eternal Throne 后缀数组 + 二分

    Fleet of the Eternal Throne Problem Description > The Eternal Fleet was built many centuries ago ...

  3. SVN回滚机制

    引子 工作中遇到一个新同事提交代码时不知怎么的出现了大面积的代码覆盖,由于对SVN也不是特别了解,就看着别人处理问题,自己也验证性的实践了一下,总结一下. 总结 svn每一次提交成功,都会有一个`编号 ...

  4. 怎么整合小图标,组合到一张png里面

    1.将切出来的图片,一个个打开,用动工具组合到新的图片中: 2.将新建的图片,背景选为透明,保存为png格式: 3.通过css的background-position属性设置元素的背景图片.

  5. WinDbg调试高内存的.Net进程Dump

    WinDbg的学习路径,艰难曲折,多次研究进展不多,今日有所进展,记录下来. 微软官方帮助文档非常全面:https://msdn.microsoft.com/zh-cn/library/windows ...

  6. silverlight 使用IValueConverter 转换

    在绑定数据中 有时候我们需要转换相关数据类型 silverlight提供了一个System.Windows.Data.IValueConverter接口它提供两个方法 Convert和ConvertB ...

  7. hdu2552

    点击打开链接 思路: 1.tan(a+b) = ( tan(a) + tan(b) ) / (1 – tan(a) * tan(b) ) 2.tan( atan(x) ) = x arctan(1/s ...

  8. Echarts饼状图

    <head> <meta charset="utf-8"> <title>ECharts</title> <script sr ...

  9. CoderForces343D:Water Tree(dfs序+线段树&&特殊处理)

    Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a res ...

  10. 【扬中集训DAY2T2】 机智的AmyZhi

    [题目链接] 点击打开链接 [算法] 据说标算是暴力? 从N-200开始搜 不过我用了搜索+一些奇怪的剪枝,也A了.... [代码] 标程 #include<bits/stdc++.h> ...