【oj每周推荐】(算法)勇敢的(或许是不幸的)CSDNer

我姓区不姓区 2009-06-30 02:00:16
加精
10位CSDNer乘坐热气球在太平洋上空旅行,他们打算开香槟庆祝一下这个伟大的时刻。然而很不幸,他们发现气球上破了一个洞,氢气不断外泄,气球开始下降,很快他们就会掉到海洋里成为鲨鱼的甜品。

但他们并没有就此完蛋,只要其中一位能够牺牲自己,跳出气球,就可以挽救其余人的生命。那问题就变成了,谁会愿意这么做呢?有一个公平的办法来解决这个问题。首先,把这十个人从0到9编上号,然后每个人先在纸上写上一个大于等于1小于等于10000的整数,把这10个人写的数字相乘,等到一个结果a,找出a的约数的个数b,则b的个位就是要牺牲自己的CSDNer的编号。把这位英雄找出来吧!!

输入:每行一个大于等于1小于等于10000的整数
输出:b的个位数

样例:
输入:
1
2
6
1
3
1
1
1
1
1

那么a=1*2*6*1*3*1*1*1*1*1=36
a的约数有:1,2,3,4,6,9,12,18,36总共9个
则b=9
那么b的个位也是9
输出:9
...全文
357 153 打赏 收藏 转发到动态 举报
写回复
用AI写文章
153 条回复
切换为时间正序
请发表友善的回复…
发表回复
Allen_studying 2010-07-13
  • 打赏
  • 举报
回复
先看看再说
Allen_studying 2010-07-13
  • 打赏
  • 举报
回复
先看看再说
手抓宝 2010-07-12
  • 打赏
  • 举报
回复
晕,我还是自己跳下去算了
liye0601 2010-05-04
  • 打赏
  • 举报
回复
我是鲨鱼,我饿了~
绿色夹克衫 2009-11-12
  • 打赏
  • 举报
回复
号码为偶数的太吃亏了,因为号码为奇数的人只要够聪明,基本上就不会死。
只要随便找1个>5000的质数猜,别人只要没有猜到你这个数,那么约数的个数就会是偶数。
sostela 2009-07-11
  • 打赏
  • 举报
回复
把150L的 50 改为 36

*_*
libolei 2009-07-08
  • 打赏
  • 举报
回复
XX
一个字
sostela 2009-07-08
  • 打赏
  • 举报
回复
把150L的 n--; 改为 j--;

*_*
sostela 2009-07-08
  • 打赏
  • 举报
回复
把140L的又改了...


#include <iostream>
using namespace std;

int main()
{
int a[36],b[36],i,j,n,sum;
bool tempb;
for(i=0;i<50;i++){b[i]=0;a[i]=0;}
a[0]=2;
n=1;
//a[n]数组保存2~100的质数
for(i=3;i<100;i++)
{
tempb=true;
for(j=0;j<n;j++)
{
if(i%a[j]==0)
{
tempb=false;
break;
}
}
if(tempb)
{
a[n]=i;
n+=1;
}
}
//b[j]保存给出的10个数中的质因数a[n]的个数
for(i=0;i<10;i++)
{
cin>>a[n];
tempb=true;
for(j=0;j<n;j++)
{
if(a[n]%a[j]==0)
{
a[n]/=a[j];
n--;
tempb=false;
b[j]+=1;
}else if(a[n]<a[j]){continue;}
}
if(tempb&&a[n]!=1)
{
n+=1;
}
}
//由约数个数定理求出a的约数个数
sum=1;
for(i=0;i<n;i++)
{
sum*=b[i]+1;
}
cout<<""<<sum%10<<""<<endl;
return 0;
}


就不检测输入的数据是否符合要求了,要是谁给出的数不符合要求,就把他丢下去。
zhangyueliwoaini 2009-07-07
  • 打赏
  • 举报
回复
上面的代码,请大家多多指教,依照大家的一致提醒,我觉得是成功的
zhangyueliwoaini 2009-07-07
  • 打赏
  • 举报
回复
#include <stdio.h>
void main()
{
int sum=1;
int i,j;
int a[10];
int b[101]={0};
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
if(a[i]==1)
continue;
for(j=2;j<=100&&a[i]!=0;j++)
{
while(!(a[i]%j)&&a[i]!=1)
{
a[i]/=j;
b[j]++;
}
}
}
for(i=0;i<101;i++)
sum*=(++b[i]);
sum=sum%10;
printf("the person is %dth",sum);
}
kevinhu520 2009-07-06
  • 打赏
  • 举报
回复
顶,学习学习
mistysunlight 2009-07-06
  • 打赏
  • 举报
回复
好像这个题目不靠谱,这并不是一个公平的选择,明显是要抽到9的Csdner跳下去嘛,,,
以下是我初步分析,欢迎拍砖:
首先,0这个编号,就已经排除在计算之外了 (1 * 1 ....) 怎么可能约数的个数是0?
再者,1这个编号,只要他写一个>1的数字,就不可能是他了,因为要求是>=1的数字,此时假设都是1,才有可能是1
而以此类推,编号2的CSDNer只要写一个约数多余两个的,就不可能是他了。 (1 * 2 * 3)
...
到第9个Csdner,只要写一个(1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9) * (其他的人的数字乘积大于等于1)
当然,题目限制在10000以内的数字,因此,看了下,还是第最后一位壮士牺牲下吧... 自觉的跳下去,还能成英雄,要是做完题目跳,就啥也不是了~呵呵,其他9个都已经合谋好了... 就是要让你跳的~~~
OnlyAlone 2009-07-06
  • 打赏
  • 举报
回复
根本连题都没看清,不是约数的个数,而是约数的个数的个位数。如果最后成绩的约数是10,20,30……怎么补可能是0.
实际上我赶紧0的可能性是最大的,质因数分解,出现一个2一个5,就100%是0号。
其它就不用说了。
[Quote=引用 142 楼 mistysunlight 的回复:]
好像这个题目不靠谱,这并不是一个公平的选择,明显是要抽到9的Csdner跳下去嘛,,,
以下是我初步分析,欢迎拍砖:
首先,0这个编号,就已经排除在计算之外了 (1 * 1 ....) 怎么可能约数的个数是0?
再者,1这个编号,只要他写一个>1的数字,就不可能是他了,因为要求是>=1的数字,此时假设都是1,才有可能是1
而以此类推,编号2的CSDNer只要写一个约数多余两个的,就不可能是他了。 (1 * 2 * 3)
...
到第9个Csdner,只要写一个(1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9) * (其他的人的数字乘积大于等于1)
当然,题目限制在10000以内的数字,因此,看了下,还是第最后一位壮士牺牲下吧... 自觉的跳下去,还能成英雄,要是做完题目跳,就啥也不是了~呵呵,其他9个都已经合谋好了... 就是要让你跳的~~~
[/Quote]
OnlyAlone 2009-07-06
  • 打赏
  • 举报
回复
算法证明不是我的强项,我只能简单的讲解一下我的想法。
首先,求10个数的乘积的约数的个数的个位(设乘积为a,10个数分别为a1到a10),我们首先想到的是求a的约数的个数。根据数学知识,对a进行质因数分解,得到a=b1的n1次方xb2的n2次方xb3的n3次方……这样的形式,然后a的质因数的个数就是(n1+1)x(n2+1)x(n3+3)……
我们需要把a计算出来吗?a=a1xa2xa3x……xa10,所以我们不需要计算出a,只要分别对a1到a10进行质因数分解就可以了。然后统计各质因数的个数,得到n1,n2,n3……。
n1,n2,n3……的乘积,就是a的质因数的个数,但是我们只需要这个乘积的个位。两个数相乘,积的个位只取决于因数的个位(这个回想一下竖式乘法就很容易理解)
所以我们只在每一次相乘中取个位就可以了,在前面的注释不够清楚,对10取余,其实就是取个位。

[Quote=引用 136 楼 yanxiangtianji 的回复:]
能证明一下getheroid()尤其是这行
HeroID = HeroID * (DivisorCount + 1) % 10;//计算约数的个数,但是只需要个位,所以取余
的正确性吗
引用 38 楼 onlyalone 的回复:
我也来发一个,求约数个数的思想和6楼的差不多,分别对输入的数进行质因数分解,以达到对乘积进行质因数分解的目的。然后求约数个数,求的过程中都只取个位。
C# codenamespace FindHero
{publicclass FindHero
  {publicvirtualint GetHeroID()
      {//对各CSDNer输入的数进行排序        SortByNuber();//求各CSDNer输入的数进行质因数分解        GetSubmultiple();//将上面的质因数分解结果汇总,即得各CSDNer输入的数的乘积的质因数分解结果        List <int> TotalDivisor=new List <int>();for (int i=0; i < CSDNerCount;++i)
        {if (_people[i].Number!=1)
            {
              TotalDivisor.Add(_people[i].Number);
            }
            TotalDivisor.AddRange(_people[i].Divisor);
        }//对乘积的质因数分解的结果进行排序,以方便统计各质因数出现的次数        TotalDivisor.Sort();int DivisorCount=1, HeroID=1;//统计各质因数出现的次数,同时计算约数个数的个位数for (int i=1; i < TotalDivisor.Count;++i)
        {if (TotalDivisor[i]== TotalDivisor[i-1])
            {//如果这个质因数和上一个相同,则这个质因数的出现次数加一++DivisorCount;
            }else
            {//如果这是一个新的质因数,则进行计算,并重置计数器              HeroID= HeroID* (DivisorCount+1)%10;//计算约数的个数,但是只需要个位,所以取余              DivisorCount=1;
            }
        }
        HeroID= HeroID* (DivisorCount+1)%10;//将最后一个质因数个数加入计算return HeroID;
      }protectedvirtualvoid GetSubmultiple()
      {int StartIndex=0;int[] HalfNumber=newint[CSDNerCount];for (int i=0; i < CSDNerCount;++i)
        {
            HalfNumber[i]= (int)_people[i].Number/2;
        }
        {int i=2;while (i < HalfNumber[CSDNerCount-1])
            {bool flag;while (i> HalfNumber[StartIndex])
              {++StartIndex;
              }
              flag=true;for (int m= StartIndex; m < CSDNerCount;++m)
              {if ((_people[m].Number% i)==0)
                  {
                    _people[m].Number/= i;
                    flag=false;
                    _people[m].Divisor.Add(i);
                  }
              }if (flag)
              {++i;
              }
            }
        }
      }publicvirtualvoid SortByNuber()
      {int tmpNumber, tmpID;for (int i=0; i < CSDNerCount-1;++i)
        {for (int m= i+1; m < CSDNerCount;++m)
            {if (_people[i].Number> _people[m].Number)
              {
                  tmpNumber= _people[i].Number;
                  tmpID= _people[i].ID;
                  _people[i].Number= _people[m].Number;
                  _people[i].ID= _people[m].ID;
                  _people[m].Number= tmpNumber;
                  _people[m].ID= tmpID;
              }
            }
        }
      }publicstruct Person
      {publicint ID;publicint Number;public List <int> Divisor;
      }public FindHero()
      {
        _people=new Person[CSDNerCount];for (int i=0; i < CSDNerCount;++i)
        {
            _people[i].Divisor=new List <int>();
        }
      }publicint[] Numbers
      {get
        {int[] tmp=newint[CSDNerCount];for (int i=0; i < CSDNerCount;++i)
            {
              tmp[i]= _people[i].Number;
            }return tmp;
        }set
        {for (int i=0; i < CSDNerCount;++i)
            {if (value[i] < MIN_VALUE|| value[i]> MAX_VALUE)
              {throw (new OverflowException());
              }
              _people[i].Number= value[i];
              _people[i].ID= i;
            }
        }
      }protectedconstint CSDNerCount=10, MIN_VALUE=1, MAX_VALUE=10000;protected Person[] _people;
  }class Program
  {staticvoid Main(string[] args)
      {int[] Data=newint[10];
        FindHero test=new FindHero();for (int i=0; i <10;++i)
        {while (!int.TryParse(Console.ReadLine(),out Data[i])) ;
        }
        test.Numbers= Data;
        Console.WriteLine(test.GetHeroID());
      }
  }
}

[/Quote]
liyachi 2009-07-06
  • 打赏
  • 举报
回复
int n1 = Convert.ToInt32(Console.ReadLine());
int n2 = Convert.ToInt32(Console.ReadLine());
int n3 = Convert.ToInt32(Console.ReadLine());
int n4 = Convert.ToInt32(Console.ReadLine());
int n5 = Convert.ToInt32(Console.ReadLine());
int n6 = Convert.ToInt32(Console.ReadLine());
int n7 = Convert.ToInt32(Console.ReadLine());
int n8 = Convert.ToInt32(Console.ReadLine());
int n9 = Convert.ToInt32(Console.ReadLine());
int n10 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine(DateTime.Now.ToString());

int sum = 0;

int num = n1 * n2 * n3 * n4 * n5 * n6 * n7 * n8 * n9 * n10;

Console.WriteLine(num);

for (int i = 1; i <= num; i++)
{
if (num % i == 0)
sum++;
}

Console.WriteLine(sum);

int n = Convert.ToInt32(sum.ToString().Substring(sum.ToString().Length - 1));

Console.WriteLine(n);

Console.WriteLine(DateTime.Now.ToString());
liwei3232004 2009-07-05
  • 打赏
  • 举报
回复
import java.util.Scanner;

public class Test1 {

/**
* @param args
*/
public static void main(String[] args) {

int[] nums = new int[10];

int num = 1;

Scanner sc = new Scanner(System.in);

for (int i = 0; i < nums.length; i++) {

System.out.print("请第" + (i + 1) + "个飞人输入自己的数字(1<=x<=10000):");
int io = sc.nextInt();
if (io < 1 || io > 10000) {

i--;
continue;
}
nums[i] = io;
num = num * nums[i];
}
System.out.println(num);
int count = 1;
for (int i = 1; i <= num / 2; i++) {

if (num % i == 0) {
count++;
}
}
System.out.println(num + "一共有" + count + "个约数!");

while (count / 10 >= 1) {

count = count % 10;
}
System.out.println("恭喜第" + count + "位飞人,梦想成真!");

}

}
sostela 2009-07-05
  • 打赏
  • 举报
回复
再改139L.

#include <iostream>
using namespace std;

int main()
{
int a[36],b[36],i,j,n,sum;
bool tempb;
for(i=0;i<50;i++){b[i]=0;a[i]=0;}
a[0]=2;
n=1;
for(i=3;i<100;i++)
{
tempb=true;
for(j=0;j<n;j++)
{
if(i%a[j]==0)
{
tempb=false;
//cout<<a[j]<<"break"<<i<<endl;
break;
}
}
if(tempb)
{
a[n]=i;
//cout<<" "<<a[n]<<" "<<n<<endl;
n+=1;
}
}

for(i=0;i<10;i++)
{
cin>>a[n];
tempb=true;
for(j=0;j<n;j++)
{
if(a[n]%a[j]==0)
{
tempb=false;
b[j]+=1;
}
}
if(tempb&&a[n]!=1)
{
//cout<<"tempb"<<a[n]<<endl;
n+=1;

}
}
sum=1;
for(i=0;i<n;i++)
{
sum*=b[i]+1;
}
cout<<"把"<<sum%10<<"号仍了"<<endl;
cout<<n<<endl;
return 0;
}


sostela 2009-07-05
  • 打赏
  • 举报
回复
改一下138L.

#include <iostream>
using namespace std;

int main()
{
int a[35],b[35],i,j,n,sum;
bool tempb;
a[0]=2;
n=1;
for(i=3;i<100;i++)
{
tempb=true;
for(j=0;j<n;j++)
{
if(i%a[j]==0)
{
tempb=false;
break;
}
}
if(tempb)
{
a[n]=i;
n+=1;
//cout<<" "<<i<<" "<<n<<endl;
}
}
for(i=0;i<50;i++){b[i]=0;}
for(i=0;i<10;i++)
{
cin>>a[n];
tempb=true;
for(j=0;j<n;j++)
{
if(a[n]%a[j]==0)
{
tempb=false;
b[j]+=1;
}
}
if(tempb)
{
n+=1;
}
}
sum=1;
for(i=0;i<n;i++)
{
sum*=b[i]+1;
}
cout<<"把"<<sum%10<<"号"<<endl;
cout<<n<<endl;
return 0;
}


sostela 2009-07-05
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;

int main()
{
int a[50],b[50],i,j,n,sum;
bool tempb;
a[0]=2;
n=1;
for(i=0;i<100;i++)
{
tempb=true;
for(j=0;j<n;j++)
{
if(i%a[j]==0)
{
tempb=false;
break;
}
}
if(tempb)
{
a[n]=i;
n+=1;
}
}
for(i=0;i<50;i++){b[i]=0;}
for(i=0;i<10;i++)
{
cin>>a[n];
tempb=true;
for(j=0;j<n;j++)
{
if(a[n]%a[j]==0)
{
tempb=false;
b[j]+=1;
}
}
if(tempb)
{
n+=1;
}
}
sum=1;
for(i=0;i<n;i++)
{
sum*=b[i]+1;
}
cout<<"ーム"<<sum%10<<"コナネヤチヒ"<<endl;
return 0;
}


加载更多回复(133)

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧