需要想一下,今天边和姐姐聊天儿,边做题,感觉很好,题显得不重要了,贴一下代码,喜欢Waterloo的题
#include
<
iostream
>
#include
<
algorithm
>
using
namespace
std;
#define
N 1000005
double
Min,Max;
double
ants[N];
int
main()
{
int
ca,i,len,num;
scanf(
"
%d
"
,
&
ca);
while
(ca
--
)
{
scanf(
"
%d%d
"
,
&
len,
&
num);
for
(i
=
0
;i
<
num;i
++
)
scanf(
"
%lf
"
,
&
ants[i]);
sort(ants,ants
+
num);
double
mid
=
len
/
2.0
;
for
(i
=
0
;i
<
num;i
++
)
if
(ants[i]
>
mid)
break
;
if
(ants[num
-
1
]
<=
mid)
Min
=
ants[num
-
1
];
else
if
(ants[
0
]
>=
mid)
Min
=
len
-
ants[
0
];
else
if
(ants[i]
-
mid
>
mid
-
ants[i
-
1
])
Min
=
ants[i
-
1
];
else
Min
=
len
-
ants[i];
if
(len
-
ants[
0
]
>
ants[num
-
1
])
Max
=
len
-
ants[
0
];
else
Max
=
ants[num
-
1
];
printf(
"
%d %d\n
"
,
int
(Min),
int
(Max));
}
return
0
;
}
然后贴一下标程
#include
<
stdio.h
>
int
c,big,little,L,i,j,k,n;
main()
{
scanf(
"
%d
"
,
&
c);
while
(c
--
&&
(
2
==
scanf(
"
%d%d
"
,
&
L,
&
n)))
{
big
=
little
=
0
;
for
(i
=
0
;i
<
n;i
++
)
{
scanf(
"
%d
"
,
&
k);
if
(k
>
big) big
=
k;
if
(L
-
k
>
big) big
=
L
-
k;
if
(k
>
L
-
k) k
=
L
-
k;
if
(k
>
little) little
=
k;
}
printf(
"
%d %d\n
"
,little,big);
}
if
(c
!=
-
1
) printf(
"
missing input\n
"
);
}
喜欢这种风格和想法,总是显得简单扼要,直命主题。