求高手帮忙把C++代码中的cin cout改成scanf printf谢谢~

2024-11-27 04:30:06
推荐回答(2个)
回答1:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;

typedef _int64 LLN;
const double pi = 2.0 * acos(0.0);
const double eps = 1.0e-9;
const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};
const int dr6[] = {1, 1, 0, -1, -1, 0}, dc6[] = {0, 1, 1, 0, -1, -1};
const int dr8[] = {-1, -1, 0, 1, 1, 1, 0, -1}, dc8[] = {0, 1, 1, 1, 0, -1, -1, -1};

const int M = 98765431;

LLN pwr(LLN x, LLN p)
{
LLN t = 1 % M;
while (p > 0)
{
if (p & 0x01) t = (t * x) % M;
x = (x * x) % M;
p >>= 1;
}
return t;
}

void calc(int* v, int n, int t, LLN s, LLN* sol)
{
LLN d = pwr(n, M - 2);

LLN x = pwr(n - 1, t) % M;

if (t & 0x01) x = (x + 1) * d % M; else x = (-x + 1) * d % M;

x = s * x % M;

for (int i = 0; i < n; ++i) sol[i] = (v[i] - x) % M;
if (t & 0x01) for (int i = 0; i < n; ++i) sol[i] = (-sol[i]) % M;
for (i = 0; i < n; ++i) if (sol[i] < 0) sol[i] += M;
}

int main(void)
{
int kase = 1000000000;

for (int ks = 1, n, t; ks <= kase && scanf("%d %d",&n,&t); ++ks)
{
int v[50100];
LLN s = 0;
for (int i = 0; i < n && scanf("%d",&v[i]); ++i) s += v[i];
s %= M;

if (n > 1)
{
LLN sol[50100];

calc(v, n, t, s, sol);
for (int i = 0; i < n; ++i) printf("%I64d\n",sol[i]);
for (i = 0; i < 10 && i <= t; ++i)
{
calc(v, n, i, s, sol);
printf("%d:",i);
for (int j = 0; j < n; ++j) printf("%I64d\n",sol[i]);

}
}
else printf("0\n");

}

return 0;
}

回答2:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using
namespace
std;
typedef
_int64
LLN;
const
double
pi
=
2.0
*
acos(0.0);
const
double
eps
=
1.0e-9;
const
int
dr[]
=
{-1,
0,
1,
0},
dc[]
=
{0,
1,
0,
-1};
const
int
dr6[]
=
{1,
1,
0,
-1,
-1,
0},
dc6[]
=
{0,
1,
1,
0,
-1,
-1};
const
int
dr8[]
=
{-1,
-1,
0,
1,
1,
1,
0,
-1},
dc8[]
=
{0,
1,
1,
1,
0,
-1,
-1,
-1};
const
int
M
=
98765431;
LLN
pwr(LLN
x,
LLN
p)
{
LLN
t
=
1
%
M;
while
(p
>
0)
{
if
(p
&
0x01)
t
=
(t
*
x)
%
M;
x
=
(x
*
x)
%
M;
p
>>=
1;
}
return
t;
}
void
calc(int*
v,
int
n,
int
t,
LLN
s,
LLN*
sol)
{
LLN
d
=
pwr(n,
M
-
2);
LLN
x
=
pwr(n
-
1,
t)
%
M;
if
(t
&
0x01)
x
=
(x
+
1)
*
d
%
M;
else
x
=
(-x
+
1)
*
d
%
M;
x
=
s
*
x
%
M;
for
(int
i
=
0;
i
<
n;
++i)
sol[i]
=
(v[i]
-
x)
%
M;
if
(t
&
0x01)
for
(int
i
=
0;
i
<
n;
++i)
sol[i]
=
(-sol[i])
%
M;
for
(i
=
0;
i
<
n;
++i)
if
(sol[i]
<
0)
sol[i]
+=
M;
}
int
main(void)
{
int
kase
=
1000000000;
for
(int
ks
=
1,
n,
t;
ks
<=
kase
&&
scanf("%d
%d",&n,&t);
++ks)
{
int
v[50100];
LLN
s
=
0;
for
(int
i
=
0;
i
<
n
&&
scanf("%d",&v[i]);
++i)
s
+=
v[i];
s
%=
M;
if
(n
>
1)
{
LLN
sol[50100];
calc(v,
n,
t,
s,
sol);
for
(int
i
=
0;
i
<
n;
++i)
printf("%I64d\n",sol[i]);
for
(i
=
0;
i
<
10
&&
i
<=
t;
++i)
{
calc(v,
n,
i,
s,
sol);
printf("%d:",i);
for
(int
j
=
0;
j
<
n;
++j)
printf("%I64d\n",sol[i]);
}
}
else
printf("0\n");
}
return
0;
}