例题:ioi2002 day 1 task 2
utopia
问题描述 – utopia.doc
问题分析
•
•
•
•
•
两个彼此独立的序列
对于一维问题求解
符号序列 si
数值序列 xi
对xi重新排列并加相应的正负号,使其按新顺序
逐一相加后,等到符号si.
例题:ioi2002 day 1 task 2
utopia --问题的解
Definition – alternating sequence
A sequence of non-zero integers X=(xa, xa+1,…, xb,),
a≤b is an alternating sequence if
1) |xa|< |xa+1|< …<|xb|, and
2) for all i, a<i≤b, the sign of xi is different from the
sign of xi-1.
Here, |xa| is the absolute value of xa.
例题:ioi2002 day 1 task 2
utopia --问题的解
Lemma 1. Let X=(xa, xa+1,…, xb) be an
alternating sequence. The sign of xb is equal
to the sign of ∑a≤i≤bxi , the total sum of
elements in X.
例题:ioi2002 day 1 task 2
utopia --问题的解
Proof
Assume:
• xb is positive
• number of elements in X is even
Then:
xa+xa+1 , xa+2+xa+3 , … , xb-1+xb are all positive,
thus the total sum ∑a≤i≤bxi is positive.
例题:ioi2002 day 1 task 2
utopia --问题的解
Example 1.
(-1,+2,-5,+6) = (-1+2)+(-5+6)=+2
which is positive.
Example 2.
(+3,-4,+5,-6,+7) =(+3)+(-4+5)+(-6+7)
=+5, which is also positive.
例题:ioi2002 day 1 task 2
utopia --问题的解
Theorem 1.
Let X=(xa, xa+1,…, xb), a≤b be an alternating
sequence, and let S=(sa, sa+1,…, sb) , a≤b be a
sequence of signs. If the sign of xb is equal to sb ,
then there exists a sequence X’=(xia, xia+1,…, xib)
such that
1) {xa, xa+1,…, xb} ={xia, xia+1,…, xib}, and
2) X’ is valid with respect to S.
例题:ioi2002 day 1 task 2
utopia --问题的解
Proof
The proof is by induction on the number of k of elements in X.
When k=1, it is easy to see that X’=X is a valid sequence
with respect to S. Now we assume that k≥2. We let S1=Ssb, that is, S1=(sa,sa+1,…,sb-1).
Case 1. The sign of sb-1 is equal to xb ,
Let X1=X-xa, that is, X1=(xa+1,xa+2,…,xb).
Case 2. The sign of sb-1 is equal to xb-1 ,
Let X1=X-xb, that is, X1=(xa,xa+1,…,xb-1).
例题:ioi2002 day 1 task 2
utopia --问题的解
Example 3.
X=(-4,+5,-7,+8),S=(+,-,-,+), we have
S1 = (+,-,-), X1=(-4,+5,-7),
S2 = (+,-), X2=(+5,-7),
S3 = (+), X3=(+5).
Thus,
X3’=(+5),
X2’=(+5,-7),
X1’=(+5,-7,-4),
X’ =(+5,-7,-4,+8).
例题:ioi2002 day 1 task 2
utopia --问题的解
Example 4.
X=(-1,+2,-3) and S=(-,-,-),
S1=(-,-), X1=(+2,-3),
S2=(-), X2=(-3).
Thus,
X2’=(-3),
X1’=(-3,+2),
X’ =(-3,+2,-1).
例题:ioi2002 day 1 task 2
utopia --问题的解
Algorithm of utopia
Step 1. //read input
1.1 read N;
1.2 read 2N code numbers and
partition
them into A and B such that |A|=|B|;
1.3 read a sequence of regions R=(r1, r2, …,rN );
例题:ioi2002 day 1 task 2
utopia --问题的解
Step 2. //find x-coordinates of code pairs
2.1 find a sequence of signs S=(s1, s2, …,sN ) such that for all
j , 1≤j≤N, sj=‘+’ if rj=1,4; otherwise sj=‘-’.
2.2 find an alternating sequence X=(x1, x2, …,xN ) from A such
that the sign of xN is equal to sN .
2.3 given X and S , find a valid sequence X’=(xi1, xi2, …,xiN )
w.r.t S according to the proof of Theorem 1.
例题:ioi2002 day 1 task 2
utopia --问题的解
Step 3. //find y-coordinates of code pairs
3.1 find a sequence of signs S=(s1, s2, …,sN ) such that for all
j , 1≤j≤N, sj=‘+’ if rj=1,2; otherwise sj=‘-’.
3.2 find an alternating sequence Y=(y1, y2, …,yN ) from B such
that the sign of yN is equal to sN .
3.3 given Y and S , find a valid sequence Y’=(yi1, yi2, …,yiN )
w.r.t S according to the proof of Theorem 1.
例题:ioi2002 day 1 task 2
utopia --问题的解
Step 4. //write output
print (xi1,yi1),(xi2,yi2),…,(xiN,yiN).
例题:ioi2002 day 1 task 2
utopia --问题的解
Theorem 2
Algorithm Utopia is correct, and its running time is O(NlogN).
Proof
The correctness of the algorithm is mainly due to Theorem
1. The complexity of each step except Step2.2 and 3.2 os
O(N), where Step 2.2 and 3.2 require O(NlogN) time for
sorting.
例题:ioi2002 day 1 task 2
utopia --问题的解
Testing data
No
Size, n m
Description
1
N=4
Example 2
2
N=10
Key value:1~20, Circular plane sweep
3
N=10
Key value:Starting from 30, step 1 or 2,
scramled
…
…
…
25
N=10000
Key value:Starting from 80000~99999,
scambled
例题:ioi2002 day 1 task 2
utopia --问题的解
Grading
4*25 = 100
例题:ioi2002 day 1 task 2
utopia --问题的解
考试答题情况
Task Submission No. of full scores Average
Uptopia
209
7
16.21
© Copyright 2026 Paperzz