Today, the fart king asked me to do hdu1128, and his last time was 78 Ms. My time was 500 + Ms. I wrote something simpler than him and the size was smaller than him, he is faster than me, so after discussion, cout is a function and is called every time, while printf is a light output. No wonder he is faster than me ~~~~ I can't.
My: # include <iostream>
Using namespace STD;
Int A [1000010] = {0 };
Int main (void)
{
Int I, J, K;
For (I = 1, K = 0; I <1000001; I ++)
{
K = I; j = I * 10;
While (J/= 10)
K + = J % 10;
A [k] = 1;
If (! A [I])
Cout <I <Endl;
}
Return 0;
}
Her:
# Include <stdio. h>
# Include <string. h>
Int hash [1000005];
Int fun (int K)
{
Int sum = 0;
While (k)
{
Int r = K % 10;
Sum + = R;
K/= 10;
}
Return sum;
}
Int main ()
{
Int I;
Memset (hash, 1, sizeof (hash ));
For (I = 1; I <= 1000000; I ++)
{
Int sum = I;
Int K;
Sum + = fun (I );
Hash [Sum] = 0;
}
For (I = 1; I <= 1000000; I ++)
{
If (hash [I])
Printf ("% d \ n", I );
}
Return 0;
}