Topcoder/SRM565
2012-12-31 11:11
441 查看
SRM565 DIV II:
Problem Statement
A divisible sequence with starting value N and length H is a sequence of positive integers with the following properties:
The sequence has H elements, labeled A[0] through A[H-1].
A[0] equals N.
For each i between 0 and H-2, inclusive, A[i+1] divides A[i].
You are given the ints N and H. Let C be the count of all divisible sequences with starting value N and length H. Return the value (C modulo 1,000,000,009).
Definition
Class:
DivisibleSequence
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int N, int H)
(be sure your method is public)
Constraints
-
N will be between 1 and 1,000,000,000, inclusive.
-
H will be between 1 and 1,000,000,000, inclusive.
Examples
0)
5
3
Returns: 3
The three possible sequences are: 5, 5, 5 5, 5, 1 5, 1, 1
1)
6
3
Returns: 9
The nine possible sequences are: 6, 6, 6 6, 6, 3 6, 6, 2 6, 6, 1 6, 3, 3 6, 3, 1 6, 2, 2 6, 2, 1 6, 1, 1
2)
10
2
Returns: 4
A[1] can be equal to each of the divisors of the number 10. That is, A[1] can be 1, 2, 5, or 10.
3)
1
10000
Returns: 1
The only possible sequence consists of all ones.
4)
30
4
Returns: 64
5)
25883
100000
Returns: 991000009
----------------------------------------------------------------------------------------------------------------------------
我的代码:
#include <deque>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <stack>
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI 3.1415926535898
#define LL long long
using namespace std;
class DivisibleSequence
{
int c;
int cnt;
void count_process(const vector<int>& factor,int cur,int H)
{
if( H == 1)
{
for(int i =cur;i>=0;i--)
{
if( factor[cur]%factor[i] == 0)
c++;
}
}
else
{
for(int i = cur;i>=0;i--)
{
if ( factor[cur]%factor[i] == 0)
count_process(factor,i,H-1);
}
}
}
public:
int count(int N, int H)
{
cnt = 1;
c = 0;
if (( N == 1) || ( H == 1))
{
return 1;
}
vector <int> factor(N/2+1,0);
factor[0] = 1;
for(int i = 2;i<=N/2;i++)
{
if( N%i == 0)
{
factor[cnt] = i;
cnt++;
}
}
H--;
factor[cnt] = N;
cnt++;
if ( H == 1)
c = cnt;
else
count_process(factor,cnt-1,H);
return (c%1000000009);
}
};
开始得了999,后来发现第六组数据时效性太差。。。果断把自己给Challenge了。(结果真可以Challenge,汗。。)
Problem Statement
A divisible sequence with starting value N and length H is a sequence of positive integers with the following properties:
The sequence has H elements, labeled A[0] through A[H-1].
A[0] equals N.
For each i between 0 and H-2, inclusive, A[i+1] divides A[i].
You are given the ints N and H. Let C be the count of all divisible sequences with starting value N and length H. Return the value (C modulo 1,000,000,009).
Definition
Class:
DivisibleSequence
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int N, int H)
(be sure your method is public)
Constraints
-
N will be between 1 and 1,000,000,000, inclusive.
-
H will be between 1 and 1,000,000,000, inclusive.
Examples
0)
5
3
Returns: 3
The three possible sequences are: 5, 5, 5 5, 5, 1 5, 1, 1
1)
6
3
Returns: 9
The nine possible sequences are: 6, 6, 6 6, 6, 3 6, 6, 2 6, 6, 1 6, 3, 3 6, 3, 1 6, 2, 2 6, 2, 1 6, 1, 1
2)
10
2
Returns: 4
A[1] can be equal to each of the divisors of the number 10. That is, A[1] can be 1, 2, 5, or 10.
3)
1
10000
Returns: 1
The only possible sequence consists of all ones.
4)
30
4
Returns: 64
5)
25883
100000
Returns: 991000009
----------------------------------------------------------------------------------------------------------------------------
我的代码:
#include <deque>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <stack>
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI 3.1415926535898
#define LL long long
using namespace std;
class DivisibleSequence
{
int c;
int cnt;
void count_process(const vector<int>& factor,int cur,int H)
{
if( H == 1)
{
for(int i =cur;i>=0;i--)
{
if( factor[cur]%factor[i] == 0)
c++;
}
}
else
{
for(int i = cur;i>=0;i--)
{
if ( factor[cur]%factor[i] == 0)
count_process(factor,i,H-1);
}
}
}
public:
int count(int N, int H)
{
cnt = 1;
c = 0;
if (( N == 1) || ( H == 1))
{
return 1;
}
vector <int> factor(N/2+1,0);
factor[0] = 1;
for(int i = 2;i<=N/2;i++)
{
if( N%i == 0)
{
factor[cnt] = i;
cnt++;
}
}
H--;
factor[cnt] = N;
cnt++;
if ( H == 1)
c = cnt;
else
count_process(factor,cnt-1,H);
return (c%1000000009);
}
};
开始得了999,后来发现第六组数据时效性太差。。。果断把自己给Challenge了。(结果真可以Challenge,汗。。)
相关文章推荐
- 概率最大骰子总和 Topcoder SRM 536 DIV1 第2题
- 3月6日TopCoder上250分和500分的代码(我自己写的)
- js 实现 水仙花数
- 月工资1000的悲哀(巨搞笑),要找挣钱多的工作呀
- android振动器
- 曾经觉得当IT代码工人觉得很没前途,但是到了求别人的时候真的感觉到当个代码工人还是蛮有前途的
- 2周修改了1000多个Bug后软件项目扭转了局面,未交付银行的现金管理系统健壮起来了
- 我在新浪微博的第1000篇,截图纪念。
- 虚拟化为容灾添彩 推荐
- TopCoder一简单题的解题过程
- 后CRM时代来临——社会关系管理
- topcoder SRM 625 DIV2 A
- topcoder SRM 625 DIV2 B
- 如何设置 TopCoder 好助手 kawigiEdit 插件
- topcoder Single Round 624(500)
- 1000----2000年之间的闰年
- 个人重装系统前备份___1000款最杰出的软件清单:
- TopCoder - "TCHS SRM 1" 答案 及 代码
- Subversion版本库的配置和使用-软件架构1
- CentOS修改默认语言