HDOJ 3020 找规律

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
  
  
2 4
 

Sample Output
  
  
2 1 4 1
 

Source
 

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值