创建算法以在单个列表中扫描奇数然后偶数页面之后交换页面顺序 [英] Creating an algorithm to swap page order after scanning odd then even pages in a single list

查看:78
本文介绍了创建算法以在单个列表中扫描奇数然后偶数页面之后交换页面顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试编写一个程序,模拟扫描页面,然后另一个模拟双面扫描,然后将页面重新排序为逻辑顺序。

例如

如果我按照1,3,5的顺序扫描一堆页面,那么另一边6,4,2。第二次扫描你翻页,所以它从最后一页开始,因此是6,4,2序列。我最后得到的页码是1,3,5,6,4,2的顺序,只交换我希望序列为1,2,3,4,5,6的数字。 (它必须交换,因为班级不允许添加,插入删除。)



我在下面手动运行了几个示例但是除了开始之外交换是一样的,我看不到一种模式,我可以用它来把它放到一个公式和循环中。下面的数字显示了各种堆栈大小的页面的扫描顺序,下一列是交换顺序以使它们对齐。下一行显示交换的页面然后是下一个交换序列

有没有人看到模式或者更好的还有算法?



2 4张纸张

1,3,4,2:2-4

1,2,4,3:3-4

1,2,3,4



3张纸6面

1,3,5,6,4,2: 2-6

1,2,5,6,4,3:3-6

1,2,3,6,4,5:4-5

1,2,3,4,6,5:5-6

1,2,3,4,5,6



4张纸8面

1,3,5,7,8,6,4,2:2-8

1, 2,5,7,8,6,4,3:3-8

1,2,3,7,8,6,4,5:4-7

1,2,3,4,8,6,7,5:5-8

1,2,3,4,5,6,7,8



5张纸10面

1,3,5,7,9,10,8,6,4,2:2-10
1,2,5,7,9,10,8,6,4,3:3-10

1,2,3,7,9,10,8, 6,4,5:4-9

1,2,3,4,9,10,8,6,7,5:5-10

1, 2,3,4,5,10,8,6,7,9:6-8

1,2,3,4,5,6,8,10,7,9:7 -9

1,2,3,4,5,6,7,10,8,9:8-9

1,2,3,4,5 ,6, 7,8,10,9:9-10

1,2,3,4,5,6,7,8,9,10



6张纸12面

1,3,5,7,9,11,12,10,8,6,4,2:2-12

1,2,5,7,9,11,12,10,8,6,4,3:3-12

1,2,3,7,9,11, 12,10,8,6,4,5:4-11

1,2,3,4,9,11,12,10,8,6,7,5:5-12

1,2,3,4,5,11,12,10,8,6,7,9:6-10

1,2,3,4 ,5,6,12,10,8,11,7,9:7-9

1,2,3,4,5,6,7,10,8,11,12, 9:8-9

1,2,3,4,5,6,7,8,10,11,12,9:9-12

1, 2,3,4,5,6,7,8,9,11,12,10:10-12

1,2,3,4,5,6,7,8,9 ,10,12,11:11-12

1,2,3,4,5,6,7,8,9,10,11,12

Hi all,

I am trying to write a program that simulates scanning pages one side then the other to simulate a duplex scan and then reorder the pages into their logical sequence.
For example
if I scan a bunch pages in the order 1,3,5 then the other side 6,4,2. The second scan you flip the pages so it starts at the last page hence the 6,4,2 sequence. I end up with the page number in order of 1,3,5,6,4,2 with only swapping the numbers I want the sequence to be 1,2,3,4,5,6. (It must swap as the class won''t allow adding, inserting removing.)

I have run through a few examples manually below but apart from the start of the swaps being the same I can''t see a pattern that I can use to put this into a formula and loop. The numbers below show the scan sequence for various stack size of pages, the next column is the swap order to get them aligned. The next line show the swapped pages and then the next swap sequence
Does anyone see a pattern or better still have an algorithm?

2 sheets of paper 4 sides
1,3,4,2 : 2-4
1,2,4,3 : 3-4
1,2,3,4

3 sheets of paper 6 sides
1,3,5,6,4,2 : 2-6
1,2,5,6,4,3 : 3-6
1,2,3,6,4,5 : 4-5
1,2,3,4,6,5 : 5-6
1,2,3,4,5,6

4 sheets of paper 8 sides
1,3,5,7,8,6,4,2 : 2-8
1,2,5,7,8,6,4,3 : 3-8
1,2,3,7,8,6,4,5 : 4-7
1,2,3,4,8,6,7,5 : 5-8
1,2,3,4,5,6,7,8

5 sheets of paper 10 sides
1,3,5,7,9,10,8,6,4,2 : 2-10
1,2,5,7,9,10,8,6,4,3 : 3-10
1,2,3,7,9,10,8,6,4,5 : 4-9
1,2,3,4,9,10,8,6,7,5 : 5-10
1,2,3,4,5,10,8,6,7,9 : 6-8
1,2,3,4,5,6,8,10,7,9 : 7-9
1,2,3,4,5,6,7,10,8,9 : 8-9
1,2,3,4,5,6,7,8,10,9 : 9-10
1,2,3,4,5,6,7,8,9,10

6 sheets of paper 12 sides
1,3,5,7,9,11,12,10,8,6,4,2 : 2-12
1,2,5,7,9,11,12,10,8,6,4,3 : 3-12
1,2,3,7,9,11,12,10,8,6,4,5 : 4-11
1,2,3,4,9,11,12,10,8,6,7,5 : 5-12
1,2,3,4,5,11,12,10,8,6,7,9 : 6-10
1,2,3,4,5,6,12,10,8,11,7,9 : 7-9
1,2,3,4,5,6,7,10,8,11,12,9 : 8-9
1,2,3,4,5,6,7,8,10,11,12,9 : 9-12
1,2,3,4,5,6,7,8,9,11,12,10 : 10-12
1,2,3,4,5,6,7,8,9,10,12,11 : 11-12
1,2,3,4,5,6,7,8,9,10,11,12

推荐答案

我没有看到一个模式,但算法只是你应用的那个。



1 /写出序列两边,比方说1,3,5,7,8,6,4,2

2/1已经放好了

3/3不按顺序排列与2交换 - >搜索第2边

4 /交换边3和2,即2-8,给出1,2,5,7,8,6,4,3

5 / 5不按顺序,应与3 - >交换;搜索第3边

6 /交换第5和第3边,即3-8,给1,2,3,7,8,6,4,5

。 ..



I don''t see a pattern, but the algorithm is just the one you applied.

1/ Write the sequence of the sides, say 1,3,5,7,8,6,4,2
2/ 1 is already well placed
3/ 3 is out of sequence and should be swapped with 2 -> search for side 2
4/ swap sides 3 and 2, i.e. 2-8, giving 1, 2, 5, 7, 8, 6, 4, 3
5/ 5 is out of sequence and should be swapped with 3 -> search for side 3
6/ swap sides 5 and 3, i.e. 3-8, giving 1,2,3,7,8,6,4,5
...

i= 2
while i+1 < N
  /* S[i] is misplaced */
  search side i in S[i+1..N], let S[j]
  swap S[i] with S[j]
  /* S[i] is now well placed */





除此之外,通过简化问题重新思考问题可能是值得的:一方面忽略偶数页的反转;另一方面,忽略奇数页和偶数页的去交织。在这两种情况下,模式都会简化,并允许您解决一般情况。



Besides that, it is probably worth to rethink the problem by simplifying it: one one hand ignore the reversal of the even pages; on the other hand, ignore the de-interleaving of the odd and even pages. In both cases the pattern will simplify and mabe allow you to solve the general case.


我相信我有办法解决这个问题。我需要在扫描时一次一页地重新排序偶数页(第二批扫描)。我没想过要做的事情。在第一次扫描时,扫描所有偶数页,然后扫描奇数页,然后重新排序。

以下示例显示2,3和4张。



2张

1,3首次扫描所有奇数页

1,3,4扫描偶数批次的第1页

1,3,4,2交换4:2

1,2,4,3交换4:3

1,2,3,4 final订购



3张

1,3,5扫描

1,3,5,6扫描

1,3,5,6,4交换5:3

1,3,4,6,5交换5:4

1 ,3,4,5,6扫描

1,3,4,5,6,2交换6:2

1,2,4,5,6, 3交换6:3

1,2,3,5,6,4交换6:4

1,2,3,4,6,5交换6: 5

1,2,3,4,5,6



4张

1,3, 5,7扫描

1,3,5,7,8扫描

1,3,5,7,8,6交换6:4

1,3,5,6,8,7交换6:5

1,3,5,6,7,8扫描

1,3, 5,6,7,8,4交换7:3

1,3,4,6,7,8,5交换7:4

1,3, 4,5,7,8,6交换7:5

1,3,4,5,6,8,7交换7:6

1 ,3,4,5,6,7,8扫描

1,3,4,5,6,7,8,2交换8:2

1, 2,4,5,6,7,8,3交换8:3

1,2,3,5,6,7,8,4交换8:4

1,2,3,4,6,7,8,5交换8:5

1,2,3,4,5,7,8,6交换8:6

1,2,3,4,5,6,8,7交换8:7

1,2,3,4,5,6,7,8



VB中的代码

_SwapPage最初设置为第一批扫描的页数。即奇数页数

I believe I have a way to solve this. I need to re-order the even pages (the second batch of scanning) one page at a time as they are scanned. Something I hadn''t thought of doing. On the first scan, scan of all the even pages and second scan the odd ones, reordering as you go.
The examples below show 2,3 and 4 sheets.

2 sheets
1,3 first scan all odd pages
1,3,4 scan 1st page of the even batch
1,3,4,2 swap 4:2
1,2,4,3 swap 4:3
1,2,3,4 final order

3 sheets
1,3,5 scan
1,3,5,6 scan
1,3,5,6,4 swap 5:3
1,3,4,6,5 swap 5:4
1,3,4,5,6 scan
1,3,4,5,6,2 swap 6:2
1,2,4,5,6,3 swap 6:3
1,2,3,5,6,4 swap 6:4
1,2,3,4,6,5 swap 6:5
1,2,3,4,5,6

4 sheets
1,3,5,7 scan
1,3,5,7,8 scan
1,3,5,7,8,6 swap 6:4
1,3,5,6,8,7 swap 6:5
1,3,5,6,7,8 scan
1,3,5,6,7,8,4 swap 7:3
1,3,4,6,7,8,5 swap 7:4
1,3,4,5,7,8,6 swap 7:5
1,3,4,5,6,8,7 swap 7:6
1,3,4,5,6,7,8 scan
1,3,4,5,6,7,8,2 swap 8:2
1,2,4,5,6,7,8,3 swap 8:3
1,2,3,5,6,7,8,4 swap 8:4
1,2,3,4,6,7,8,5 swap 8:5
1,2,3,4,5,7,8,6 swap 8:6
1,2,3,4,5,6,8,7 swap 8:7
1,2,3,4,5,6,7,8

The code in VB
_SwapPage is initially set to the number of pages scanned in the first batch. ie number of odd pages
Private Sub DuplexSwapOnTheFly()
     Dim LastImage As Integer = AcquiredImages.Count
     Dim i As Integer

     'the first scan of the reverse side is not swapped
     If LastImage - _SwapPage = 1 Then Exit Sub

     For i = _SwapPage To LastImage - 1
         AcquiredImages.Swap(LastImage, i )
     Next
     _SwapPage -= 1
 End Sub


这篇关于创建算法以在单个列表中扫描奇数然后偶数页面之后交换页面顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆