您的位置:首页 > 其它

codeforces 789 B. Masha and geometric

2017-03-31 16:27 253 查看

链接

B. Masha and geometric depression

题意

给你一个等比数列的首项

和公比q,然后给出一个上限l,m个数字,在这个等比数列里,小于l且没有在m个数字里面出现过的

可以写在黑板上,问最后能写在黑板上的数字有多少个

做法

坑点主要都在b1和q上,我们只需要特判掉

和q=0或者

=0的情况,然后用set存m个数字(可以去重),再暴力到

>=l就可以了。

代码

/*set容器中count(x)返回x的数量1或0,se.find(b1) == se.end()判断b1是不是不在se里面,不在的话返回1,在的话返回0*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100010;
int main() {
LL a[maxn];
LL b1, q, l, m;
while(cin >> b1 >> q >> l >> m) {
LL ans = 0;
LL cnt = 0;
set<int> se;
for(LL i = 0; i < m; i++) {
cin >> a[i];
se.insert(a[i]);
}
if(abs(b1) > l)
cout << 0 << endl;
else if(!b1 || !q) {
if(!se.count(0))
cout << "inf" << endl;
else
cout << (se.find(b1) == se.end()) << endl;
} else if(abs(q) == 1) {
if((!se.count(b1)) || (!se.count(b1 * q)))
cout << "inf" << endl;
else
cout << 0 << endl;
} else {
LL sum = b1;
int cnt = 0;
while(llabs(sum) <= l) {
if (se.find(sum) == se.end()) {
cnt ++;
}
sum *= q;
}
cout << cnt << endl;
}
}
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: