| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:这道题我很无奈的做法,超级暴力法!In Reply To:这道题我很无奈的做法,超级暴力法! Posted by:iter at 2008-08-11 16:06:49 > 开始我写的代码如下,用了二重遍历,明显是超时的,这个超时严重没法优化
> 心血来潮把输出的答案用freopen("out.txt","w",stdout);写进记事本(要用,号割开),把答案个数记住
> 然后定义一个长度为答案个数的一维数组a[983];直接把记事本里那983个答案粘贴在数组初始化的地方,
> 用一个for循环输出数组所有元素,就这样给AC了
> 很。。很暴力,呵呵!
>
> #include <iostream>
> using namespace std;
> int main()
> {int i,num,count=0;
> freopen("out.txt","w",stdout);
> for(int n=1;n<10000;n++)
> {
> for(i=1;i<=n;i++)
> {
> if(n==i+i%10+(i/10)%10+(i/100)%10+(i/1000)%10)
> { num=0;
> break;
> }
> else
> num=1;
> }
> if(num==1)
> {
> cout<<n<<",";
> count+=1;
> }
> }
> cout<<count<<endl;
> return 0;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator