pku1148 Utopia Divided
来源:互联网 发布:定时复制文件软件 编辑:程序博客网 时间:2024/04/28 20:33
题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1148
题意简述:给定n,给定2*n个正整数,用这些数去描述点,然后给定几个数表示坐标轴象限,要求每次选取一个点(可以对给定的整数设置正负)使得与前面一个点的连线组成的向量所对应的坐标在这个象限内,当然把起始点设在(0,0)。求这写点。
解题思路:看到这题感觉没想法,看了一份英文版的解题报告,讲的很详细。再此就引用那一份解题报告了。
问题描述 – utopia.doc
- 问题分析
• 两个彼此独立的序列
• 对于一维问题求解
• 符号序列 si
• 数值序列 xi
• 对xi重新排列并加相应的正负号,使其按新顺序逐一相加后,等到符号si.
- 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.
- 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.
- 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.
- 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.
3) 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=S-sb, 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).
- 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 );
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.
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.
Step 4. //write output
print (xi1,yi1),(xi2,yi2),…,(xiN,yiN).
代码:
- pku1148 Utopia Divided
- utopia
- Utopia
- UTOPIA
- zoj 2838 Utopia
- Divided Product
- Divided Product
- Divided Land
- wooyun puzzle注入trick -- Utopia
- hdu 5050 Divided Land
- HDU - 5050 Divided Land
- hdu 5050 Divided Land
- hdu 5050 Divided Land
- HIHOCODER#1096 : Divided Product
- HDU 5050 Divided Land
- divided two integers
- 关于Utopia Level 2的一个问题
- hdu 5050 Divided Land java
- share search engine
- Anthem.NET框架的使用
- Java虚拟机(JVM)参数配置说明(转自:http://lavasoft.blog.51cto.com/62575/25492)
- CString的使用与效率
- 专业技术和软实力的权衡?
- pku1148 Utopia Divided
- EXCEL从ACCESS中取值
- ASP.NET页面刷新方法总结
- [技术学习]WEB技术学习总结1
- [转]Windows Socket 网络编程
- 分手第四天
- 提升数据库性能
- .NET各子技术领域之应用前景
- 【转】背包九讲