您的位置:首页 > 其它

Codeforces Round #256 (Div. 2)

2014-07-18 09:55 295 查看
A - Rewards

水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可

#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;

LL limit = 1e5;
vector<LL> divs,res;

bool solve(LL x, LL k){
if(k == 0 ||  x == 1){
res.push_back(x);
return res.size() >= limit;
}
for(int  i = 0 ;i < divs.size(); ++ i){
if(divs[i] > x) break;
if(x%divs[i] == 0){
if(solve(divs[i],k-1)) return true;
}
}
return false;
}

int main(){
LL x,k;
cin >> x >> k;
for(LL i = 1; i*i <= x; ++ i){
if(x%i == 0){
divs.push_back(i);
if(i*i != x) divs.push_back(x/i);
}
}
sort(divs.begin(),divs.end());
solve(x,k);
for(int i = 0 ; i < res.size(); ++ i){
if(i) cout<<" ";
cout<<res[i];
}
cout<<endl;
return 0;
}


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