| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3409 人关注过本帖
标题:整数最优分解?????????
只看楼主 加入收藏
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
回复:(weishj)基于飞燕MM的思想,我弄了这个程序,...
you got the idea, except overflow of 32-bit int.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-09-18 12:12
weishj
Rank: 1
等 级:新手上路
威 望:2
帖 子:141
专家分:0
注 册:2007-4-22
收藏
得分:0 
晕,没考虑溢出

If you shed tears when you miss the sun, you also miss the stars.
2007-09-18 12:25
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 
以下是引用weishj在2007-9-18 12:08:15的发言:

我晕难道南开的服务器是网通的??这会进N次进不去了
TO:雨中飞燕
不试过我怎么会乱说话呢?

看来你不知道EOF为何物
你不超时才怪,肯定死循环


by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
[url=http://bbs.bc-cn.net/viewthread.php?tid=162918]C++编写的Windows界面游戏[/url]
[url=http://yzfy.org/]C/C++算法习题(OnlineJudge):[/url] http://yzfy.org/

[此贴子已经被作者于2007-9-18 12:36:35编辑过]

2007-09-18 12:35
卧龙孔明
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:59
帖 子:3872
专家分:684
注 册:2006-10-13
收藏
得分:0 
以前见过,vijos上的题
我在http://program.xuntan.com/dispbbs.php?boardid=2&id=65&page=1写过
vijos上AC:
#include<stdio.h>
int s[1001]={0};
int x=1000;
void cheng(int m)
{
int i;
for(i=1000;i>=x;i--) s[i]*=m;
for(i=1000;i>=x;i--) { s[i-1]+=s[i]/10; s[i]%=10; }
if(s[x-1]) x--;
}
int main(void)
{
int i,j,k;
int n;
s[x]=1;
scanf("%d",&n);
while(n>4)
{
n-=3;
cheng(3);
}
cheng(n);
for(i=x;i<1001;i++) printf("%d",s[i]);
return 0;
}

My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.
2007-09-18 12:38
weishj
Rank: 1
等 级:新手上路
威 望:2
帖 子:141
专家分:0
注 册:2007-4-22
收藏
得分:0 
回复:(雨中飞燕)以下是引用weishj在2007-9-18 12:0...
你没看我程序就说
即使while(scanf("%d",&a))是死循环,那下面
if(a<=0)break;
这一句呢?

说实话我每次上这论坛前都先开编译器然后开IE的,我的每一个程序都是亲自测试后发上来的,甚至我说的每一句话也是亲自检验过的。

[此贴子已经被作者于2007-9-18 12:41:17编辑过]


If you shed tears when you miss the sun, you also miss the stars.
2007-09-18 12:39
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
回复:(weishj)回复:(雨中飞燕)以下是引用weishj...

程序代码:


#include <iostream>
using namespace std;

int main()
{
int a;

/** try on a windows machine:

input 6 7 8
and press F6 (F6 means your input is done) + enter

you will see program hangs at 8 forever

*/
while(scanf(\"%d\", &a))
{
cout<<a<<endl;

if(a<=0)
break;
}

return 0;
}



I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-09-18 12:54
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
回复:(卧龙孔明)以前见过,vijos上的题我在http://p...

submitted your code at nku (sorry, without your permission)
and it runs for 340ms.

My code above runs for 220ms.

There are some code which runs for 20ms. I would think for that we need to use assembly language to do the power and multiplication.


#include<stdio.h>
int s[10001]={0};
int x=10000;
void cheng(int m)
{
int i;
for(i=10000;i>=x;i--) s[i]*=m;
for(i=10000;i>=x;i--) { s[i-1]+=s[i]/10; s[i]%=10; }
if(s[x-1]) x--;
}
int main(void)
{
int i,j,k;
int n;
s[x]=1;

while( scanf(\"%d\",&n) != EOF)
{
while(n>4)
{
n-=3;
cheng(3);
}
cheng(n);
for(i=x;i<10001;i++) printf(\"%d\",s[i]);
printf(\"\n\");

}
return 0;
}


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-09-18 13:04
weishj
Rank: 1
等 级:新手上路
威 望:2
帖 子:141
专家分:0
注 册:2007-4-22
收藏
得分:0 

你是说输入6<空格>7<空格>8
然后按F6+Enter吗?
这我试了,确实8不会显示出来,不过再按回车8会显示。
按你说这种方法输入,即使把程序改成
while(scanf("%d",&a)!=-1)
或者while(scanf("%d",&a)!=EOF)也是会在第三个数字时挂起的呀


If you shed tears when you miss the sun, you also miss the stars.
2007-09-18 13:06
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 
以下是引用weishj在2007-9-18 12:39:32的发言:
你没看我程序就说
即使while(scanf("%d",&a))是死循环,那下面
if(a<=0)break;
这一句呢?

说实话我每次上这论坛前都先开编译器然后开IE的,我的每一个程序都是亲自测试后发上来的,甚至我说的每一句话也是亲自检验过的。

遇到EOF标志你的程序就是死循环,谢谢!!!!!!!!!!!!!



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
[url=http://bbs.bc-cn.net/viewthread.php?tid=162918]C++编写的Windows界面游戏[/url]
[url=http://yzfy.org/]C/C++算法习题(OnlineJudge):[/url] http://yzfy.org/

2007-09-18 13:08
weishj
Rank: 1
等 级:新手上路
威 望:2
帖 子:141
专家分:0
注 册:2007-4-22
收藏
得分:0 
算乘方我想可以这样稍作处理:
3^2=(2<<2)+1,
3^n=((3^2)^(n/2)),若n奇数,后面再乘3
但我不知这样会不会稍微提高效率

If you shed tears when you miss the sun, you also miss the stars.
2007-09-18 13:12
快速回复:整数最优分解?????????
数据加载中...
 
   



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

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