作业帮 > 综合 > 作业

ACM 题 简单的dp 但一直提示 Runtime Error(Segment Fault) 求指导

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/07/15 16:32:59
ACM 题 简单的dp 但一直提示 Runtime Error(Segment Fault) 求指导
Description
zyf最喜欢的数字是1!所以他经常会使用一些手段,把一些非1的数字变 成1,并为此得意不已.他会且仅会的两种手段是:
1.把某个数m除以某个质数p——当然p必须能整除这个数,即m=m/p
2.把某个数m减1,即m=m-1
有一天他突发奇想,想把[a,b]区间中所有的数一个一个地变成1,这是一个巨大的无聊的工程,所以他想知道他最少得花多少操作才能达到目 的.
Input
  输入包含多组数据(1000组数据),EOF结束.
  每组数据以两个整数开头:a,b(0
ACM 题 简单的dp 但一直提示 Runtime Error(Segment Fault) 求指导
我的环境OK,没有发现问题.
不过,int dp[100200];这个真的很差,很多环境可能出问题.
这个应该malloc,不清楚具体环境
再问: 还是错误
再答: 你有测试数据吗?或者在什么环境提交? A. 每一次必出问题 B. 只有几组数据不过 C. 随机 ----------------------------------------------------------- 如果和数据有关,除非start,end超过了要求,因为没有检查输入。 比如,start=-1000000或者end=1000000,这样count+=dp[i]是错误的。
再问: http://acm.xidian.edu.cn/land/problem/detail?problem_id=1003 就这个,不用注册也可以提交
再答: long start,end,n=0; 知道了,scanf("%d%d",&start,&end),这个是致命的。 因为,long可能不是int。那样堆栈可能被破坏!替换所有long为int,accepted。 不过程序慢慢改进吧^_^ 下面是编译器对你的程序不满意的地方。 ----------------- ../acm1/main.c: In function 'isprime': ../acm1/main.c:11: warning: implicit declaration of function 'sqrt' ../acm1/main.c:11: warning: incompatible implicit declaration of built-in function 'sqrt' ../acm1/main.c: In function 'main': ../acm1/main.c:47: warning: format '%d' expects type 'int *', but argument 2 has type 'long int *' ../acm1/main.c:47: warning: format '%d' expects type 'int *', but argument 3 has type 'long int *' ../acm1/main.c:54: warning: format '%u' expects type 'unsigned int', but argument 2 has type 'long unsigned int' ----------------- #include #include #define inf 100000; /*dp*/ int dp[100200]; int isprime(int a)//判断素数 { int i; double n=sqrt(a+1); for(i=2;(a%i)!=0&&i=n&&a!=1&&a!=0) return 1; return 0; } void dpc(int n) { if(n==100000)return; int i,t; for(i=2;(t=i*n)dp[n]+1)dp[t]=dp[n]+1; } if(dp[n+1]>dp[n]+1)dp[n+1]=dp[n]+1; return; } void calc() { int i; for(i=1;i