HDOJ 3020 找规律

来源:互联网 发布:淘宝打包员招聘要求 编辑:程序博客网 时间:2024/06/06 03:23

FunnyXEN

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 156    Accepted Submission(s): 19


Problem Description
For any positive integer n, we define function F(n) and XEN(n).

For a collection S(n)={1,2,...,2n}, we select some numbers from it. For a selection, if each selected number could not be divided exactly by any other number in this selection, we will call the selection good selection. Further, we call a good selection best selection if the selection has more elements than any other good selection from S(n). We define F(n) the number of elements in the best selection from S(n). For example, n=2, F(n)=2. From the collection {1,2,3,4}, we can make good selection just like {2,3} or {3,4}, but we can't make any larger selection. So F(2) = 2.

Then we pay attention to XEN(n). For every S(n), there are always some numbers could not be selected to make up any best selection. For instance, when n=2, 1 is always could not be chosen. What's more, for every S(n), there is a number k which satisfies that all the number, from 0 to k, are always could not be chosen. Now we let XEN(n)=k:

n=2, F(n)=2, XEN(2)=1;
n=4, F(n)=4, XEN(4)=1.

You should write a program to calculate the value of F(n) and XEN(n) with a given number n.
 

Input
Your program is to read from standard input.

There are multiple cases. For each case, one integer n (1 ≤ n ≤ 10^7) in a line.
 

Output
Output two integers with one space between them in one line per case.
 

Sample Input
24
 

Sample Output
2 14 1
 

Source
2009 Multi-University Training Contest 6 - Host by WHU
 

Recommend
gaojie   |   We have carefully selected several similar problems for you:  3021 3022 3023 3024 3030 

分析:这题。。其实我看不出来背后有什么数学原理的,打表找规律。。
代码如下:
#include <cstdio>using namespace std;const int maxn = 25;int a[maxn],num[maxn];int n;void init(){    a[0] = 0;    for (int i=1; i<20; i++) a[i] = 2*a[i-1]+1;    num[1] = 3;    for (int i=2; i<20; i++) num[i] = num[i-1]*3;}int main(){    init();    while (scanf("%d",&n)!=EOF){         if (n==1) {printf("1 0\n"); continue;}         int tot = 0, x = 1;         while (x<n) {             tot++;             x+=num[tot];         }         printf("%d %d\n",n,a[tot]);    }    return 0;}


原创粉丝点击