首页 > 试题广场 >

话说某天一艘海盗船被天下砸下来的一头牛给击中了,5个倒霉的家

[填空题]
话说某天一艘海盗船被天下砸下来的一头牛给击中了,5个倒霉的家伙只好逃难到一个孤岛,发现岛上孤零零的,幸好有棵椰子树,还有一只猴子! 大家把椰子全部采摘下来放在一起,但是天已经很晚了,所以就睡觉先. 晚上某个家伙悄悄的起床,悄悄的将椰子分成5份,结果发现多一个椰子,顺手就给了幸运的猴子,然后又悄悄的藏了一份,然后把剩下的椰子混在一起放回原处,最后还是悄悄滴回去睡觉了. 过了会儿,另一个家伙也悄悄的起床,悄悄的将剩下的椰子分成5份,结果发现多一个椰子,顺手就又给了幸运的猴子,然后又悄悄滴藏了一份,把剩下的椰子混在一起放回原处,最后还是悄悄滴回去睡觉了. 又过了一会 ... ... 又过了一会 ... 总之5个家伙都起床过,都做了一样的事情 早上大家都起床,各自心怀鬼胎的分椰子了,这个猴子还真不是一般的幸运,因为这次把椰子分成5分后居然还是多一个椰子,只好又给它了。 问题来了,问这堆椰子最少有1个?
推荐
 这堆椰子最少有15621
    第一个人给了猴子1个,藏了3124个,还剩12496个;
    第二个人给了猴子1个,藏了2499个,还剩9996个;
    第三个人给了猴子1个,藏了1999个,还剩7996个;
    第四个人给了猴子1个,藏了1599个,还剩6396个;
    第五个人给了猴子1个,藏了1279个,还剩5116个;
    最后大家一起分成5份,每份1023个,多1个,给了猴子。


编辑于 2015-02-02 15:31:50 回复(3)
15621个,假设从别处弄来4个椰子,则第一个家伙分完后,他还是原来的那份加上猴子的那个,弄来的4个椰子被分在剩下的四份里,这样剩下的椰子又可以分为五份。。。。重复。。。这个过程进行了6次,则5^6-4=15621个椰子
发表于 2015-06-10 09:06:15 回复(1)
借给海盗们4个椰子。这样第一个海盗藏起来的加上他给猴子的,正好是椰子总数的五分之一。第二个海岛藏起来的加上他给猴子的,正好是剩下椰子数的五分之一,以此类推。5*5*5*5*5*5-4=15621个椰子。
发表于 2015-06-10 20:37:20 回复(0)
假设总共有x个椰子,第一个人藏的有x1个,第二个人藏了x2个,第三个藏了x3个,第四个藏了x4个,第五个藏了x5个椰子,第二天早上剩下的椰子有y个,最后公开每个人分得y1个椰子。那么:
因为五个人各自藏了一部分之后剩下的是四份,所以必须能被4整除,而且还除以5余1
x=5*x1+1;4*x1=5*x2+1;4*x2=5*x3+1;4*x3=5*x4+1;4*x4=5*x5+1;4*x5=y;y=5*y1+1;
最后得 x=(15625*y1+11529)/1024=(15*y1+11)+265(y1+1)/1024
当y1=1023时,x有最小值 x=15*1023+11+265=15621

发表于 2015-06-10 10:24:11 回复(2)
一棵树上长15621个椰子  此乃神树 不可侵犯。五个海盗,一天能摘 15621个椰子,这是什么效率!
发表于 2016-07-22 15:30:25 回复(0)

for(NSInteger x = 16; x < 20000; x++) {

        NSInteger temp = x;
for (NSInteger i = 0; i <= 5; i++) {

if ((temp - 1) % 5 == 0) {

                temp = (temp - 1) * 4 / 5;

            }

            else {

                temp = -1;

            }

        }

        if (temp != -1) {

            NSLog(@"%ld:%ld",x,temp);

        }

    }

结果:15621:4092
发表于 2015-10-25 19:46:07 回复(0)
15621个 
用的逆向思维的方法编写得到程序

    for(int j=0;j<20000;j++){
            int temp = j;
            
            if(temp%5 == 1){
                for(int i=0;i<5;i++){
                    if(temp*5%4 == 0)
                        temp = temp*5/4+1;
                    else{
                        temp =  -1;
                    }
                }
                if(temp != -1)
                    System.out.println(temp);
                else
                    continue;
            }    
     }
 
发表于 2015-06-10 10:12:02 回复(0)
#include <iostream> //#include <cctype> using namespace std; int main(){ const int M=100000; int i,k=0; int j; for(i=6; i<M; i++){ k=i; j=0; if((k-1)%5 != 0)continue; for(; j<5; j++) { if((k-1)%5 != 0)break; k=k-k/5-1; } if(j == 5 && (k-1)%5 == 0)break; } cout<<i<<endl; return 0; }
发表于 2017-04-11 12:05:32 回复(0)
//  假设这堆椰子至少有x个
//  a =(x - 1)/5*4;// 第一个人分剩下的
//  b =(a - 1)/5*4;// 第二个人分剩下的
//  c = (b - 1)/5*4;// 第三个人分剩下的
//  d = (c - 1)/5*4;// 第四个人分剩下的
//  e = (d - 1)/5*4;// 第五个人分剩下的
//  f =(e - 1)/5*4;// 六个人一起分剩下的
public class Demo1 {
public static void main(String[] args) {
for (int i = 1; i <= 20000; i++) {
boolean result = resolve(i);
//调用resolve()方法,判读i是否满足条件,返回布尔类型的值ressult
if (result == true) {
System.out.println("这堆椰子最少的个数是:" + i + "个。");
break;
} else {
continue;
}

}
}

// 此方法用来判断i是否满足条件,满足返回true,不满足返回false.
public static boolean resolve(int choic) {
int bool = 0;
// 若连续6个次划分,每次分都满足条件,则加1,若有一次不满足跳出循环。有且只有6次分满足条件bool==6
for (int j = 1; j <= 6; j++) {
if ((choic - 1) % 5 == 0) {
choic = (choic - 1) / 5 * 4;// 第j个人分留下的
bool++;
} else {
break;
}
}
if (bool == 6) {
return true;
} else
return false;
}
}
发表于 2017-03-25 11:19:50 回复(1)
#include<cstdio>
#include<algorithm>
using namespace std;
bool ok=false;
int num=0;
bool solve(int index){
    int res=index*5;
    for(int i=0;i<5;i++){
        if((res+1)*5%4){
            return false;
        }
        res=(res+1)*5/4;
    }
    num=res+1;
    return true;
}
int main(){
    for(int i=1;i<=10000;i++){
        ok=solve(i);
        if(ok){
            printf("%d\n",num);
            break;
        }
    }
    return 0;
}
编辑于 2016-07-29 22:25:43 回复(0)

public static void main(String args[]) {
System.out.println("Hello World!");
for (int i = 1;; i++) {
if (((i - 1) % 5 == 0)
&& ((((i - 1) * 4 / 5) - 1) % 5 == 0)
&& ((((((i - 1) * 4 / 5) - 1) * 4 / 5) - 1) % 5 == 0)
&& ((((((((i - 1) * 4 / 5) - 1) * 4 / 5) - 1) * 4 / 5) - 1) % 5 == 0)
&& ((((((((((i - 1) * 4 / 5) - 1) * 4 / 5) - 1) * 4 / 5) - 1) * 4 / 5) - 1) % 5 == 0)
&& ((((((((((((i - 1) * 4 / 5) - 1) * 4 / 5) - 1) * 4 / 5) - 1) * 4 / 5) - 1) * 4 / 5) - 1) % 5 == 0)) {
System.out.println(i);
break;
}
}
}
发表于 2015-11-12 13:56:36 回复(0)
15621

#include <iostream>

using namespace std;

int fun(int num,int res)
{
    if(num == 0){
        return res;
    }else{
        int temp = res;
        res = res/4*5+1;
        if((res-1)/5*4 != temp){
            return -1;
        }else{
            return fun(num-1, res);
        }
    }
}

int main()
{
    int res = 1;
    int result = 0;
    while(-1 ==
        (result = fun(5, res*5+1))
          && res <= 10000){
            res ++;
    }

        cout<<result<<endl;
    return 0;
}


发表于 2015-06-10 22:56:41 回复(0)

1.假设到最后剩下了a0=x个椰子,则经过第5个人操作之前就有a1=5*a0/4+1个椰子,经过第4个人操作之前有a2 =5*a1/4+1个椰子,因此可以得到递公式a(i+1) = 5*a(i)/4+1,而且a(i)(i=0,1,2,3,4,5)都能够被5整除且余数为1,求最小的a5。C++代码如下:
#include<iostream>
using namespace std;

int main()
{
    for(int i=1;;i++)
    {
        int k=0,temp=i;
        while(k<6)
        {
            if (5*temp%4==0)      
            {
                k=k+1;   
                temp = 5*temp/4+1; 
                cout<<"i="<<i<<"  k="<<k<<"  temp="<<temp<<endl; 
            }
            else
            {
                break;    
            }       
        } 
        if(k==6)
        {
            cout<<temp<<endl;break; 
        }
    }   
    system("pause");
    return 0;    
}
//最后答案为15621

编辑于 2015-06-10 21:03:34 回复(0)
15621
#include <iostream>

using namespace std;

int main()
{
    int i, sum = 0;
    int j = 1;
    sum = j * 5 + 1;
    for (i = 0; i < 6; i++){
        if (sum % 4 == 0)
            sum = (sum / 4) * 5 + 1;
        else {
            i = 0;
            j = j + 1;
            sum = j * 5 + 1;
        }
    }
    cout << sum << endl;
    return 0;
}

发表于 2015-06-10 19:43:44 回复(0)
15621
每次分椰子时椰子树num-1需要整除5,且留下(num-1)*4/5的椰子数以备下一次分发,一共分发了6次,遍历结果如下:
#include<iostream>
using namespace std;
int main()
{
    int num = 5;
    bool flag = false;
    while (!flag)
    {
        flag = true;
        num++;
        int temp = num;
        for (int i = 0; i < 6; i++)
        {
            if (temp % 5 == 1 && (temp - 1) / 5 >= 1)
                temp = (temp - 1) / 5 * 4;
            else
            {
                flag = false;
                break;
            }            
        }
    }
    cout << num<<endl;
    return 0;
}



发表于 2015-06-10 16:54:31 回复(0)
递归调用,回溯,最少15621
bool fun(int num,int n){
    int totle = n*5+1;
    num--;
    if(num<1){
        cout<<totle<<endl;
        return true;
    }
    if(totle%4==0){
        fun(num,totle/4);
    }
    else{
        return false;
    }
} 

int main(){
    bool right=false;
    for(int i=1;i<INT_MAX&&!right;i++){
        right = fun(6,i);
    }
    return 0;
}

发表于 2015-06-10 14:55:37 回复(0)
public class D {
    public static void main(String[] args) {
        boolean flag=true;
        double i=10;
        while(flag){
            
            if((i-1)%5==0){
                double b=(i-1)*0.8;
                if((b-1)%5==0){
                    double c=(b-1)*0.8;
                    if((c-1)%5==0){
                        double d=(c-1)*0.8;
                        if((d-1)%5==0){
                            double e=(d-1)*0.8;
                            if((e-1)%5==0){
                                double f=(e-1)*0.8;
                                if((f-1)%5==0){
                                    flag=false;
                                }
                            }
                        }
                    }
                }
            }
                i++;
        }
        System.out.println(i-1);
    }
}

发表于 2015-06-10 14:44:50 回复(0)
3121个
int _tmain(int argc, _TCHAR* argv[])
{
 int i=0;
 int temp1;
 int temp2;
 int temp3;
 int temp4;
  
  
  for(i=0;i<10000;i++)
 {
  temp1=i-i/5-1;//第一个人剩下的
     temp2=temp1-temp1/5-1;//第二个人剩下的
     temp3=temp2-temp2/5-1;//第三个人剩下的
     temp4=temp3-temp3/5-1;//第四个人剩下的
  if((i%5==1)&&(temp1%5==1)&&(temp2%5==1)&&(temp3%5==1)&&(temp4%5==1))
  {
   printf("%d\n",i);
  }
 }
 system("pause");
 return 0;
}
编辑于 2015-06-10 11:58:45 回复(0)
题目问的是最少有多少个  

假设 最后每个人 分到的椰子有 1个
/**
 *         使用 递归计算
 * 
 * @access global
 * @param mixed $num          分椰子的次数
 * @param mixed $x            最后每个人分到椰子的个数
 * @return void    
 */
function test($num,$x)
{
    $total = 0;
    $total = ($x * 5) +1;
    $num--;
    if($num < 1)
    {
        echo $total;
    }else
    {
        test($num,$total);
    }
}
test(6,1);

那最少 椰子的个数为 19531个
编辑于 2015-06-10 11:16:32 回复(0)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
   int x=1;
   for(int i=0;i<=5;++i){
      x=5*x+1;
   }
   printf("这堆椰子最少有%d个",x);
   return 0;
}
编辑于 2015-06-10 10:57:07 回复(1)
RNA头像 RNA
15621
发表于 2015-06-10 10:00:57 回复(0)