| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1572 人关注过本帖
标题:Nankai Online Judge Problem 1002
只看楼主 加入收藏
Jackzdong
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2006-6-1
收藏
 问题点数:0 回复次数:10 
Nankai Online Judge Problem 1002
这几天遇到了一个难题,对给定的f(n) 当 n>=50025002 的时候,f(n)=n-5;当 n<50025002 的时候,f(n)=f(f(n+2005))。输入一个数, 范围相当的大啊 -2147483647<n<2147483647,求F(N), 不要用函数嵌套, 因为数字大了以后, 嵌套的次数多了,超过内存限制或时间超时


==============================================================
added by HJin

1. problem statement at http://acm.nankai.edu.cn/p1002.html
2. modified your title so that it is more descriptive.

[此贴子已经被HJin于2007-7-18 1:19:43编辑过]

搜索更多相关主题的帖子: Judge Problem Nankai Online 
2007-07-17 13:32
stupid_boy
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2007-7-6
收藏
得分:0 

高精度吗?

用数组解决

搜索一下就能有很多资料了。


失眠。。。
2007-07-17 13:54
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
LS不对哦,别人都限定了-2147483647<n<2147483647

LZ是想不用递归吧(就是你说的嵌套,可以试着用迭代,效率好很多)。

Fight  to win  or  die...
2007-07-17 16:04
Jackzdong
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2006-6-1
收藏
得分:0 

想了很多方法都是一定范围内的数可以实现,但是数字很大以后就会得到错误的答案, 有能力的可以去http://acm.nankai.edu.cn/p1002.html看看, 希望AC的大鸟能给我份SOURCE CODE

2007-07-17 18:32
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 

你是初学ACM还是初学C++啊?初学C++就没必要做这种题了,初学ACM的话做做到是不错

2007-07-17 20:24
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 

还要谢你介绍了一个不错的OJ,以前不知道南开的OJ这么好(从设计上),应该弄的比较晚吧


#include <stdio.h>
#include <stdlib.h>

inline int mod(int a,int b)
{
return a>=0?a%b:a%b+b;
}

int main()
{
int n;
while(scanf(\"%d\",&n)!=EOF){
if(n>=50025002){
printf(\"%d\n\",n-5);
}
else if(n>=0){
printf(\"%d\n\",50024997+mod(n-1002,2000));
}
else {
printf(\"%d\n\",50024997+mod(n+998,2000));
}
}
}

2007-07-17 21:22
hao678
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-7-17
收藏
得分:0 

嘿嘿`
我刚加进来的
多多指教哈!


2007-07-17 21:30
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
seems it is the math for an explicit formula of f(n) that makes this problem worth a point.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-17 22:17
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
leeco:

(guess you are right --- found my mistake)

Is your result 100% correct? Seems that I have a math theorem:

N-5 <= f(n) < N+1995 if n <N, where N = 50025002.

[此贴子已经被作者于2007-7-18 1:23:16编辑过]


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-18 00:35
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
回复:(Jackzdong)初学c++遇到的难题

There is a lot of math involved here. Here is my attack, which
is accepted at http://acm.nankai.edu.cn/p1002.html


To compete for smaller source file size, I rewrote it as a .c file (accepted of course and but with no readability).

I don't know why the online judge said that my program needs 672kb memory while other people are using
just 32kb. Frankly, I don't think the following one line source code will need 672kb memory.

What is wrong here?


int main(){int n;while(scanf(\"%d\",&n)!=-1){while(n<50025002)n+=2000;printf(\"%d\n\",n-5);}return 0;}


===============================================================

(.cpp file)
#include <iostream>
using namespace std;

int f(int a, int b, int N, int n)
{
int temp = a - b;
while(n<N)
{
n+=temp;
}

return n-b;
}

int main()
{
int n;

while ( scanf("%d", &n) != EOF )
{
printf("%d\n", f(2005, 5, 50025002, n));
}

return 0;
}

[此贴子已经被作者于2007-7-18 7:16:36编辑过]


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-18 01:16
快速回复:Nankai Online Judge Problem 1002
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012738 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved