127 - "Accordian" Patience
Moderator: Board moderators
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
rainbow.mimuw.edu.pl/~kd209203/127/127.tar.bz2
There are 10000 test cases. I guess that should be enough.
There are 10000 test cases. I guess that should be enough.
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Thanks. I tested with the I/O from your website, found some bugs, removed them, and now my program output matches the output you gave for all 10000 inputs, without crash. I am still getting RTE from the judge though. I submitted to OJ and the reply was: Invalid memory reference. Before crash, it ran for 4.615s. My program used 396KB of memory in the OJ. I don't how the memory routines can cause invalid memory reference.
Here is my code, I cannot find the problem. Maybe there is something I missed.
[c]
Resolved.
[/c]
Basically to cut down execution time, I try to assign the contents pointed to by a pointer to another pointer directly instead of actually copying the contents. I used an array of Stack pointers.
Here is my code, I cannot find the problem. Maybe there is something I missed.
[c]
Resolved.
[/c]
Basically to cut down execution time, I try to assign the contents pointed to by a pointer to another pointer directly instead of actually copying the contents. I used an array of Stack pointers.
Last edited by chunyi81 on Mon Aug 09, 2004 4:25 am, edited 1 time in total.
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Invalid memory reference happens when you read or write not allocated memory. For instance, the following loop will (probably) cause it:
[c]int tab[50];
for(int i = 0; i <= 50; ++i)++tab;[/c]
There is a place in your code where you have exactly such an error. Time that your code was running is also a hint. Do you see it now?
[c]int tab[50];
for(int i = 0; i <= 50; ++i)++tab;[/c]
There is a place in your code where you have exactly such an error. Time that your code was running is also a hint. Do you see it now?
#127, if you get AC, please try this input
Code: Select all
6D QS AD 2D JD 4S 9H 3S TD 8H 2H TS 5H TC 5D 9S 7H 8C 8S 3C AC 2S 9C AH KD TH
3H 8D JS 9D 6C 5C 2C QC KH JC JH 6S QH 4H 6H 7D KC QD 5S 7S 4D KS AS 4C 7C 3D
6C 4C 7H 8H 7S JD 6S JS 3D 5D KS 4H 2H 9D QD 6H JH 5S 8D AH QH QC TD 5C QS TS
3S 4S 2C 2D AC TC 2S AD 9H 7C 8S KC 9C KH 3C 6D AS 7D 9S 5H TH JC KD 3H 8C 4D
4S TC 5D 3D 2D 4C QD 6H KH JD 5H 3H 6C 7D JH KC 3C 5S 8S AH KD 9D AD 2H 8C AC
7S 7C 9C TS KS JS TH 2C QC AS 8H TD 3S QH 4H 9S 6D 7H 6S 4D 2S 8D 5C JC 9H QS
JC 6D 5D QH 8C AS 4S 9C QS 8H 2D 9H AC JH KC TH TD 8D AD 3H JS 5S 7C 6H 7S TS
2H KH QC 3C 6S 4D JD 4C 5H 5C AH 6C KS 2C QD 9D 4H 3D TC 7D 3S 9S 7H 2S 8S KD
QC 6S 2C 6D 6C TC JH 8C 7S 7H 9S 3H QD 3S AC JD TS JS 9D KC 5C 4C 5D 5H KD 8D
KS 7D 5S AD AS 3D KH 6H JC AH 3C QH 2D 4S 4D 7C 9C TH QS 8S 2S 2H 9H 4H 8H TD
KD 6D 5D JH 5C TD 8H 8D QS JD 4S QH 9H 8S 9S AH 7H KS TH JC 3S 7D QC 5S QD 2C
4D 4C TC 8C 2D 9D AC 6C 7S 3D AD 2S 6S 9C JS 3H 5H 7C KC 4H 2H 3C TS 6H KH AS
KH 7S TS 3S 9C 3C QH 4H 2S 5S KC 8D AC 9H AH AD 4S 4D 5D 3D QS KS 5C 8S 2D 6S
2H JH 4C QC 5H JC 9D 2C 9S TD AS 7D TH 8H QD 7H KD 7C 6D 8C JD JS 6H TC 6C 3H
3C TH 8S KH QS 8D 7C 5S 9C 5D 2S 6S 6C AC 6D 3H JS QD AH 7D JC 2H 2C 5H KD 8C
8H JH 9D 4H AD 3S 4C 9S 4D QC 4S 5C TS QH JD KS AS 6H TD TC 2D KC 9H 3D 7S 7H
AH 4S 6D AC 7H JD QD 8D 5C 4C KC 8C 4D 7C 8S 9C 5S 3C JC 7D 3H 8H 6C QH JS TS
3S 2H 5D 9S 4H 2S JH 3D 9H 6S 6H 2D TD 5H QC 2C KD TC 7S 9D AD AS KS TH QS KH
3C TD 3H 2S AD 4D 9C JS 7C 6H QH 9H QS 6C 8H 8D 4S JC AS 6S 7D TS KH 6D 9D QD
AC AH 5H 4H 3S 5S JH 7H 5C 2H 9S 8S TC KS JD 8C 2C TH KC 7S 4C 5D 2D KD 3D QC
AH QS TC 5C 6S 8C 6H TD 2S 5H JH 9S 9D KS 4C 2C 5S QH 9C 8S 4S QD 3H 8D JS 7H
3S 6D 3C 5D 7D TS JD AD 2H KC KH KD 4H QC TH 7S 9H 4D AS JC AC 8H 6C 3D 7C 2D
TD 6C 5H 5S QS 2D KS 8C 5C AH JC 9C 8D AD 4D 2C 2S 7H KD 7D 7C 9D 5D 8S KH 3C
QD QH 6D 2H KC 7S AS 6H JD QC JH 4S TH 8H 4H 3S TS 3H JS 9H 6S 4C TC AC 3D 9S
8H 4S KD 4C 7S QD QC 6H 9C KH 2H TD TC 9S QH 3H 2S 5D JH TS TH QS 4D JC AD AH
3D 8D 6S KS 3C 6D AC KC 8C AS 9H 5C 5H 7H 2D 5S JS 9D 7D 6C 3S 7C 2C 8S 4H JD
KC 3S 9D 4H 5C 4S 8S TD QS JC 9S JH 7D 6C KH 5H TH TC 8D 7H 3C 6H 7S 9C 5S AH
AC 6S 2H 4D JS 8C QD QH AD KD JD 3D 3H 8H 5D TS 6D 4C QC 2D 2C 9H 7C 2S KS AS
2H 8H KC 5C QS 9H QH 7H 7C TD 2S TS TH 2D 7S 3C 6H JS 3S 4H 5H 4S 5S 9D 3H 8C
AH AC KS 8D AS 5D 2C QD KD 6S 4C JH 3D 4D TC 9C 9S 6C QC JD JC 7D 8S 6D AD KH
3C 3S KC 9H 5S 7D 8D TH 6H 4H KD 8H 2D 5D AD TD 5H 9D AH QS 7C 7H 4D JD 6S 3H
4S 2H AC 2S 4C JS 9C KH QD 3D 8C 9S QC TS 6C AS 7S QH 6D 8S 2C KS JH TC 5C JC
4C 7C 6S 3D JH 3S 6H 2D 2C TS 6D QD 9H TH 5C 7S JS KD 5S JC 5D AC 8D 4D TC AS
3H 3C 2H TD 8C QC AH 8S KS 9S QS 7H JD QH AD 9C 2S KC 8H 9D 4S 7D 6C 4H KH 5H
6D 6H 2D TS 2C 8C 9H 7H QD KC 6S 3D JD 8H 3C 5S 3S 6C 4H 5C 2H 8S 9C AH TC 4S
JC 3H 4C JS AS 7C KD JH TH 7S 8D AD 2S 7D QH 4D KH KS 5H QC 9S 5D TD 9D QS AC
QC 8C 6D KC JC 2C KS 7C JH TC 7D KD AC 4C 8D QS 4D 4H 7H TS 3S AD 9S AS 9D 6H
3D 2H QH 5C JS 9C AH 2S 6C 5H 3H 4S 8S 8H 6S 3C QD TH 7S 9H 5S TD KH 5D 2D JD
KH 6D TC 8D JS JH 2D JC 4C 9C 2S 7C 2H 3H 9D AS 2C 6S 3C 7D QS AH QH AD AC 6H
KC 4H KS 9H 3D 7H 8C QD 4D TS 5S 9S QC 7S 4S TH JD 6C 3S KD 8H 5C 5H 8S TD 5D
KD 5D 9D 9H TS 8D 7C JD JS 2S 3D TD QC 5H 7S AS 5C JH 6S 4H 7H QD QS 8S 5S 9S
4D 2D 8H 3S 8C JC 6D 3C 6H TH 7D KC 2C QH AD TC AC 9C 4C 2H 6C KH 4S AH KS 3H
AS 8D 2H 4C JS KC AH QS 7C 8C 3D KD 6H KH 6S TD AD TH JD QH TC 4D 5H 4H QC 3S
3H 2C 8H 5S 9C 8S 9D 7H 9S 6C 3C JC TS KS 2S JH 4S 2D 7S 5D 5C 9H 7D AC QD 6D
KC 7H AD 6S QH 2C 8D 2S 7S 8S TC JH 9H JC 2H AS 5S 8H QS JS 4H 4D 7D 4C 9D 9C
QD 2D 9S KD KH TH 7C AC 3H 6C JD 5D AH 8C KS TD 3S 6D TS 5C QC 5H 6H 3D 4S 3C
QS 8D 9S 6H AD 4S 2S KH TD QD 6S 8S TS 5C AC KC JD 9H 7D 4D 7S 2D TC KS 4C 3C
8H JH 7C KD QH 8C 5D 5S JS 6D 3H 3D 9C QC 3S JC 5H AS 2C TH 7H 6C 2H 4H 9D AH
AS KS 5C 5S KC 4H 6H 7H JC AD 9C TH TC 8C QC 4C 4D JS JD 7C 9S 3S 8H QS 4S 2D
7D 9H 5H KD 6C 2S 8S 2C 5D 7S 3C QD 3D 9D 6D AC 8D 2H 6S TS JH QH KH AH 3H TD
7S AD 6C TS 3S 9D 3C 2H KD 3D 4C 6D 7C JH 6S QD 9S 3H JD 5D 8D QC 5H QH 4D TC
6H JS AH 2D TH AC QS 9C 5C JC 8S 8C 2S AS KS 8H 5S 9H TD 7H 4S 4H 2C KC KH 7D
TH 9C 8H QC 5H QH 7C 2S 9S AC 4S 6S KC 2C 2H 3H 8C TS 4D 7D AS AD 3D KH QD 4C
8D JH JC 6D 8S 6H 9H JD 7H JS 9D QS 5S TC KD 3C 7S 5D 5C KS TD 6C 4H AH 2D 3S
KS JH QD AC 5C QC QS 5S QH 3D 6D 5H KC 7D 3S 8H 2S 9S TS JS TH TD 8C 8S AS 7C
KH AD 7H JC 6C KD 2C 2H AH 5D 9H 3H 6S 9D 4C 4D JD 3C 2D TC 9C 6H 4H 8D 4S 7S
3S QD 5C 5S QH 6D AH 7D 6S 3D 3H JS 6C 4H KS TS 9H 7H QS JH 7C 9S 2H 4S AS QC
8S 2S JC 3C 2D 8H 5H 6H AC 9C 7S 4D 5D 4C 9D 2C TH TC TD KC KH JD 8C 8D AD KD
4D 8D QC 4C KH 9D 3H 7H 5D 7D 8H 8C 6H KD 5C 2C 7C 3C 5H JD 2S 4H 6D 7S AC KS
6S JH TC QH 2D TD AH AD 6C 9S 8S JC QD KC TS 3S QS 9H TH 5S 9C 2H 3D JS 4S AS
QC KD 3C 5D TH QH AD 4S 5S 9D TC 3D 5C KH 8S AH 7S 3S 5H KC 7C 7H 2C 2S JC 6D
TD KS 7D AS QS JH 8D 6C QD 8H 9H JD JS 2H 4D TS 3H 6S 6H 4C 9C 9S 4H 2D 8C AC
6H 4D 4S 7C 4C 6C 2H QS 2S JD 9H QC 2C 5C 5D KC 9D AS 3C 8H 5H KH 3H 7H TS 7D
QD AD 3S 8D JS TC AC KS TD 8S TH 7S 8C 2D AH QH JH JC 6D 6S 9C KD 4H 9S 5S 3D
5D 6D 8D 8C AD 6H 8H AS 4D 5C 2S TC TH 4H QC 5H 3H QD QH KH 2C AC JC 6S TD JD
7C KC 2H 5S JS 9H 6C 9C 4S 7S QS TS 9D 3D 9S 2D 7D JH 4C 3C 7H KD AH 3S 8S KS
7H 4S 8S AH 5S TC 2C TS 6H KS 9D AS 4H QS 5D QD 5H 7D QH 5C JS 2D 9H 4C JH KD
TD 8H KC 9C 6S 3S 6D TH QC KH 3C JD 3D 2S 6C 8D 3H 2H AC 9S 7C AD 7S 8C 4D JC
TH 5S 4H 8H 7H TD QC 4C 2D 6D 7C 6S TS 7S 4S 5C QD 9D 9H AC KC 2C TC AD 6H KD
JS 8C KS 5H 6C 3S 3D 8D 7D 4D 3H 3C JD JH QH QS AH 9S 5D 8S JC AS 9C 2H 2S KH
7S 9D 2S 8H 4S 6S KD AD 2H JD AC 6D KH QD 3D 5S TD AS 7D 8C TH AH KC QC TS QS
6C 5D 7C QH JH 4D 3S 3C JC 9C 9S 2D 8S 5C 2C 4H 8D 4C KS 5H TC 7H 9H 6H JS 3H
4C 3S TC JH 3H JD AH 9S QC 7H 6C QH 4S 9H 8C 2S AC 7C KD 5C 9C 7S KS 3D KC 9D
TD KH 8D JC 5H QS TS 6H AS JS 2C 5S QD 3C 2H 8H 7D 8S 2D AD 4D 6D 6S TH 4H 5D
4S KC QS 2H 6D 4D JS 7H 7S TS KH JC 5D AD 7C 6C 9C 3S 9D 7D TH QH QD 3D 4C JD
8H KD 2D 2C 9S 9H AC JH 3H 8S 8C KS 6H QC AS TC 2S 5H 6S 5C 8D 5S 3C 4H AH TD
5H TS 5C 6H 7C 7H QD AC 4H AS 9S KS 5D TH 8D AD 7D KH QC 3C 4S JD 6C 3S 2H QH
AH 3D JH 9H 5S 8S KC TC 8C 4D 9C 2C JC 6D 2S 9D 6S KD 3H 8H 4C 7S 2D QS TD JS
5D AD QC 7H 8D 8S QD 4C AH 4H AS 2S 2D 8H 9D QH JC 6C 6D 2C 9H TS 6S TH 9C TD
KS 3D KD 5H 4S 5C 7D 8C TC 3C 4D 9S 2H AC JD JS 3S JH QS 6H 7S 7C KC KH 3H 5S
TH KS 8C 6D KH 7H AC 9S 8S AH 8D 2H JD QC 5C QH 7C 7D QD KD 5D 3H 6C 9H 2C 3D
AS 6H 9D JS 8H 4D KC 6S 2D 3C 4S 4H AD TS TD 3S JC 5H 2S QS TC 5S JH 4C 7S 9C
KD AC 3H JD TH 9H 9C 9D QS TC 9S 4C 6H AS JH 5C QD 6C 2S 7D KH 5H 4D JC KC 8S
8H 3S 8D 5D QC 6D 4S QH AH 3C 5S 7H 6S 3D 2D KS TS 7C AD 8C JS 2C TD 7S 2H 4H
4D 7C 2S 7D 3C TC 3S 6C JS 9C 9D TS 5D 3H 7H QC 9S 8S 6D 9H KD AH TH 2D 4H AC
4C 8C 5H 6S QH KS 5S 5C JC JH JD 7S 8D 8H AD KC 6H 2H KH AS 3D QS TD 2C 4S QD
7D 6C 4H 6D 7S QC 3D TC 7C AC AS 5D AH 2S 2C 3S 2D 6H QS KS 8S 9S 4S KH 3C 5C
7H AD 5H JC TD 3H 9H 4C JS KC TH 2H 9C 8C 8D 6S JH TS 8H JD QD 4D KD 5S QH 9D
AS 5H TD 8H JS 7D QC QS JD 7C 6C 7H 9D 8C KC KH 5C 2C 2H KD 2D JH KS 4D 8D QH
3H 4S AC 2S 8S 4H JC TS 6D 9C 6H 6S AD 7S 4C 3S 3C AH QD 3D 5D TC 9H 9S TH 5S
2S 8D KS 6C JH 3D 6H QS TS KH 5D 4H AC 9H 3H 4C 3S 5S 5C 3C 2C TH 7D 8H 7H QC
TD 8C 2D 7S 6S JS TC 9C 7C KC 5H 2H KD 8S 9S AD 4S 4D QH JD AS JC QD 9D 6D AH
5C 8H KC AH 9H TS 6S 6C 9S QC 7D 8D AS 8S 5H 3H AD 4H 9D 3C KS 2C 7H 8C 2H 4D
9C 7S 4S 4C JD 6H 3D KD 5S QD 5D 6D TH TC 7C JC 2D TD KH AC QS QH JH 2S JS 3S
TS 5H QC KS 8H JC 7C TD 5S 3C 4S KD AD 4H 8D AS 4D 5D KH QS TH 7D AC 6H JS 5C
9S 6D 8S TC 2D 9H 7H AH 9C 3D 2C QD JD 4C 3H 3S KC 8C 2S 9D 2H JH 7S 6C 6S QH
TH 6H 8H TS QS 6S 9S JD KD 6C 5S 7D AH 6D AD 8S 2H 2C JH 3D AS KS 9D 7S QD 8C
QH 4C 3S 2D 9C 2S JC 9H 8D 4H JS 5H QC 3H 3C KC 4S 7H 4D 5C AC TC 5D KH TD 7C
8C 5H KH TS TC JH 9D JC 8S 3C 9H 9S TD AC 8H 9C 3S 2S KS 7C 5S 6H QD QS 2D AH
7D 2H JD 7S 2C KC JS 4H 6C 3H KD 4C AS AD 7H 8D QC TH 6S 4D 5D 5C QH 6D 3D 4S
KH 8D JD QH 9C 2S AS 8C QS 7S 6D QC 8H 4C 9D AD 3S 7H 6H 2C 3D 4S 5H QD 9H 2D
5C 3H JS 6S KS 5D 6C TH JH AC 7D TC 7C JC KC TS TD 4H 3C KD 8S 4D AH 5S 9S 2H
8H 4D TD 6S KC 4C 7C TC 2H 9S 9D AS QC 7S AD 8C 7H QH KH 6C 3S QD 6H 2D JC 9H
JH AC 8S 5C QS JD TH 8D 2C 3C 5H 2S 3D 9C AH 6D 4H 5D 3H KS JS KD TS 4S 7D 5S
9H QH AH JH JC TS 9D 7D 6D QC 6H 7C 6C TC 2H 4S KD 3H KH 6S JS QD 9C 2S AC 8S
JD 5D 7S 4C 4H 3S AS TD AD 8H 5H 3D 4D 2D KS 7H 2C 8C 9S KC 5C TH 3C 8D QS 5S
TH TC JH QS KD TD AH 4D JS 4S QH QC 7D JD 4C 3H 5S 8D 5D 6D 6S 7C 3C 9D 9C 9S
5H AC 6H 7S TS 5C 2H AD KH 8S 2D JC AS KS 7H 2S KC 8H 4H 6C 9H QD 2C 3D 8C 3S
6H 9D 3C 4S 7D 8S AH 5C TD TC 6S 7H KC 7S 5S KH 5D QH JD 6D AD AC 2D QC 3S 4D
9S 4C 6C 8H TS 8C 3H 2C TH AS 5H 2H QD KS 7C 4H 9H 3D QS 2S 9C JH 8D KD JC JS
KS 6C AD 2S 6H KC 7D AC 4S 4D QS 5C 3S 7H JS 2D 6S 3D 8C QC 8S 3H JH 9S 7S 4C
QH 5D 2C TC 2H 7C 9H TH JD JC 8H TS 3C 9D 4H 6D 5S 8D 5H TD AH KH QD AS KD 9C
JH JS 5H 7S TS 6H 7C 3H AC 3D 7D 9S 9C 2S JD 7H 9H AS 5D 4S 6S 2C QH 8S 2D 4H
4D KD 8C JC QS KS AD 8D 5S 4C AH QC 8H KC TD TC QD 6D 5C 3C TH 3S KH 6C 9D 2H
TS 5C 4S 4C 8H TC 2C 5D 6H QS JC JD 7S 2S AC 6C 4D AS 6S 2H 9H 9S KH 7C 9D KD
JS KS QD 7D 7H 8D TD 3C 3H 3D KC QC JH TH AD 6D 8S 2D 3S 8C QH 5S 5H AH 4H 9C
TS 8D JS 4H JC 2H 8H 9D 6C 9C 9H 6S 9S 3H 2C 3D AD 8C 6D 5D 6H 4C AS 5S AH TH
7D 4S KC KS 4D 7C 3C 5C QC 8S TC QD 2D 7S JD KH 2S AC TD 3S KD 5H QS JH 7H QH
7S QD QH 9D AS 5H 9H JS TH 6D 7D 4H 3H 5D 2D 8D 4C 9C 8C 6H 3S JC 7H 4S 2H TS
2C 3D KC AH KD TC 9S 7C 6C 5S AC 5C QS 8H TD JH 4D KH AD 6S 8S 2S JD KS QC 3C
KD 3H KH 4C AC QS 2H 7D 7C 6C 9S KS TH QD 8D 5H 4D 2S AD 6S 3S 7S 4S 9D 3D AS
TD 5D 8S TS AH JD JC 2C 6D 2D JS 8H 3C KC 5C 9C JH 6H 8C QC QH 7H 5S TC 9H 4H
QS 7D 5S KH 7S 3S 8D 2D 6H 8C AS 4H QC JS JH 3H AC 9S TH 6D 2H 2S KS QD 8S 3C
KC JC 9C 5H 4C TC 7C 6S 6C 9H 5D 9D 5C 4S KD TS 2C 7H 4D AH QH TD AD JD 3D 8H
5D 9C 8H 3D 2S 8S 9S 4C 4D 4H 2H 8D KC KD 7C KS 5H 2D 6D JH AC TH 3H 6S QC QS
3S AH 7S 3C JD 9D AS 7H JS TC QD QH 7D 9H 6C KH AD JC 5S TS 8C TD 6H 4S 5C 2C
KH 3S 8C 5D 3C 6C 8H JS JC TC KD TS KS TH TD 5C JH 4H 6D AD 9S 9D QD 7D 2H KC
2S JD 4D 9C QS 6H 7S AH 4S 7C AC 8S AS 3H 7H 8D 5S QH 2D 2C 4C 3D 6S 9H QC 5H
7C KD QC AC 6H 7S 4D 3C 9C 6C QH QS KC 5H JS KH JH 6S 8D 5D TC 2S TH 5S KS TS
4H 9D 3D 7H 7D 4S AS TD 2H 5C QD AH 2C JC 9S AD 3S 4C 8H 6D JD 2D 3H 9H 8C 8S
TC 7D 2C 2S 3S 9S 9D KD 6D QH JC 3C 8D 9H 7C 6S AH 2H JD TH TD QC KC 7S 5D KS
4S 5H 9C 7H 4D QS 3H TS 8C 6H 2D AD 6C 8H AS AC 5S JH 4C 5C QD 8S JS KH 3D 4H
9H 8D 3H 9D 2D JD QS AS AD 3D JS 2H 9S 7C JC 9C KH JH AC KC 7H 2C 2S QC 3C 3S
AH 6H 7D 4H 7S 8S 5D KD 8H 4C QD QH 6S TS 6D 5S 5C 5H KS 6C TH TC 4S 4D 8C TD
KC 2S 5H 2C 6S 4C QD 5S 6D 5C 2H QH AH 9H AS 9S JD 4D 6C 8S 9D 3H 2D TC JS KS
3S 6H 9C KH JH 4H TS 8H AD TD 7C 3D 8C 7S AC 7H 7D 4S QC KD JC 8D TH QS 5D 3C
5C AS 6C 7H 4S QD JD 3C 3H 8S 8H KC 9S TD 7C AC AH 3S 6D TC 2C 5S 2D 9C JS 6H
4D JH QH 6S 9H TH AD 8D 4H JC TS 2S 4C 7S KS QS 9D QC KD 5D 8C 3D 7D 5H KH 2H
KC KS 6C 8H 7S QD 3S QC 5H TS 5D AC KH 8D 9S 6S 3D 9H JD JS 9D KD TD 4C 4S 5S
3H 8C 2S 5C 2D 4H 2H QH JC 8S 4D 2C 7C QS TC AH 3C 7H TH JH 6H 9C 7D AD AS 6D
AC 3C QH QD TH KH 6S 9C 3D AD 8D 9S 6D 2D 8H 3H 4C 4D JC 7C 8C 5D 2S 4S AS 2C
5S 8S 6C 4H 2H 6H 5H AH JS KS TC KC 3S 5C 9H 7H 7S QS JH 9D TD KD TS 7D QC JD
2C 4H JS 7S JC 3S 9C 3H 6S 2S QC 9D KS JH TD 7H 2D KH QD 8H 2H 5D 5S 6H 9S QS
TC 4S 6C 4C AD 6D JD KD 4D 7C AH 7D 9H 8D TH TS 5H KC AS QH 5C 8S 3D 8C AC 3C
6H KH 8S 4S 6C AC 7D KD 5D 7H QH QC KC JC 2H 5S QD 8D AD KS 4C 3S 2C 6S 8H 8C
6D JS TD TS 9C 5C 2S 5H 3C 3H 4H TC 7C JH QS AH AS 4D 2D 7S TH 9H 3D JD 9S 9D
QD 9C AC 4C 7S TH 8S 3C JD QC QS 6C 7C 5D 2C AH TC 2D 6S 5S 2S 8C 4H 2H QH TD
KD 6D 4S 3S JC 5H 5C KH 4D KS 9D TS JS 6H 9S AS 9H 7D KC 3D 3H 8H AD 8D JH 7H
7S 2S QD 9D 4C AD 9S AH 4H QC JD 5H 4S 3C QH 3H 5S 5D 8D 6H TC 3S 7C KS 3D 7D
AC 6D KC 9C JC JH KH AS 2D 6C KD 9H QS TS JS 4D 2C TH TD 8S 5C 8C 7H 6S 8H 2H
2H 8C 3C 2D AH TC 8S 6D 9C 6S 4C 9H AC KS 2C KC 4D 8D 9S 3D 4S 3H TS QC 2S 6H
AS 6C 7D AD JS TH 5D JH JC 5C QH 5S 8H 5H KH TD KD QS 7H 7S 7C QD 9D 3S JD 4H
8D 9H 5H 7C 5C AC 4H 3C 2C 6S 6C TH KC 3H TD 5S 6D QD 7H KH JC KS 6H JH TS 7D
3D 7S AD 3S QC 9S 8C AS AH 2H 9D 4S TC 4C JS 9C 2D 5D KD QH 2S 8S 8H QS 4D JD
2S 2D 8H AS KS 9H AD 2H 3D TS 6H QS 6C TH TC TD 6D 9S 5D 4H 6S 7D 9C 7S 8C JC
QD 3C JS JD 2C 5S KH 5C 4C 3S QH 9D KC AH 8S JH 5H 7C 4D 7H 4S 8D KD 3H QC AC
9D KD 4S QH 8S 9H 4C 5C JD 8H 7D 9S 4D KH JS 2C KS TC 6D 5H KC AD JC 9C 2H TD
5S 3C 3H 6H 8D QD AC 3S TS TH AH JH 5D 8C 6S 7C 2S 7H 7S 3D 2D QC AS QS 4H 6C
TC 7S 3S AD 9C 4D 4S 9H TS 2D 7H 5C TD AH 6S 8H 5S QS AC 3C 8C 6D 6C 6H JH 7D
QH JD 8D QD 9D 3D JS 2C JC 2S KS 3H 7C KD KH KC 4H QC TH 8S 5D 9S 4C AS 2H 5H
QH 8C 6H AD TC JC 6D 5C 2H 4S 2D 9C 8H 9S QS 3D 9D 5S 6C 7D KS 3C 8D TH 5H JH
TD KC JS KD 4H TS AC 2C 2S 7S 5D 4C QC JD AH AS QD KH 7H 6S 9H 8S 3S 3H 7C 4D
7C 3H AH 4S 9H 5C 8S 5D TH 3D KD 6S JC 8H 8D JD 6C QH KC TS QS AS 4H 5H JS 2D
8C AD QC 2H AC 7D 4D 9S JH 3S 2S TD 9D 5S 9C KS 4C TC QD 7S 2C KH 6D 7H 3C 6H
2H 7D AH JS 3H 4C QD 8H JD 6D TH 7S 4H TD TC TS KD JC 7C 8S 5H KH 2C KS 9S 9D
5D 7H 5C 6C AC JH 2D 4S 8D 6S 4D 8C 3S QC 9C QH 3C AD 9H 2S QS 3D 6H AS 5S KC
5D 6C AC AS 5C KH 6S AH KD KC 9H 3S 2S JH AD TD 3D 4S KS 9S JD 2D 6H 8S JS 5H
4D TH 7D QS TC 4H QH 6D 3C 7C TS 9C 2H QD 7H 8H QC 3H 5S 8D 9D JC 4C 7S 2C 8C
KH 8C QC 2S JH AD 3C 5D 4S 9S JC 3S 3H 5H 2D 4D 6C TC 8H 7D 5C QH 2H 7H KS QS
9D 3D TH JD KC 5S AS 4H JS 9H 7C 6S QD 8S AC TS TD KD 7S 9C AH 8D 6H 4C 2C 6D
QD TD 6D 9S JS TH 8D QC 9C 4D 7C AC 7S AD 8H KS 5H 4S 3C QH 7H JD 2S 9D 2C KD
TC 2H 2D KH 8S 4H 8C 3H AS 6C 3S AH 5D QS 6H KC TS 5S 6S 9H 7D 4C 5C JC 3D JH
9C TC 4C 7C 4D JD 2D JS QC JH 4S KC AH 3D 3H 6H 7H 3S 9S 6C 7D TS 8H 2H TH 9H
KD 9D AS 6D QD 4H 8S 5D 8C 6S JC 8D AD 2C 5S 5C 5H QS KH 7S 3C TD 2S AC QH KS
TH 9S AD 2C 6S AS 9C 9D 3D QH AH 4D 4C 8S 4S JC 8C 7S 4H JH 5S 5C KH 7D JS TD
9H 6H TC KC 7C TS QS KD KS 5D AC 2D QC QD 6D 3H 7H 3S 3C 5H 8H 2S JD 8D 2H 6C
TD 5D 8S 2C 5C 8H AS KH 2D 6S QC 9C 4S JH 7H 3H TC 3S 8C AD 6H QH AH 2H KS AC
9D QD 5S 7D 9H 3D 7S QS TH 8D JS 3C KD 2S KC 6C TS 5H JC 4C JD 6D 4H 7C 9S 4D
TS TC KD TH 4C 6D 2D 3H 6S QD 3D KS KC 6H 9C 9S 5C QH 9H 8H 5S QS AH JD 2H 8C
QC TD AC 5H JC 2S 7C 4D AS 7S 8D 9D JS AD 3C JH 4S 5D 7H 3S 8S 2C 6C 7D KH 4H
AH 3C 7H 2D 7S 6H QD JC 8H 2C KH TS 2H JD TH 7D QH KD JH 4H AS 5C 5D 5H 3D 8S
TD KS 5S 6D 9C QC AD 9D JS 7C 3S 9S 4C 4S 2S QS KC 6C 8C AC 9H 8D 4D TC 6S 3H
7H 2C 8C 6C AD 7C QS 6D AH KH 5S 4C 9C 2D TD 6S TC 5D JS 8S QC JC 3D 3H KD TH
7S 7D 8D 5H 3C 9D AS 2H 2S KC QD TS 5C QH JH JD 4H KS 3S 8H 6H 9S 9H 4S AC 4D
JH AH 2C 6H 7S 9D 4H TS TH 6D 8C 3D 7H JS AC TD 3S TC 7D 3H QS 2D 2S 7C 2H 5C
5S 4S 6C 5H JC 9H 4D 4C 8S JD KD QD AS KC 9C KS AD 5D KH 8D 8H 9S QC 3C 6S QH
9D 5H 5S 7S AH 6S TH 2H 4H AC 9C 8H 8C 4D JC AS 2D 5D AD QC 9S 8S 8D 7D TS KS
KC QD QS JD 4C 5C 4S JS JH 2S 7H 3D KD 6D QH 6C 3C TD 7C 3H 2C TC KH 9H 3S 6H
5H QC 5C 9S QS 6D 7S QD KS KC AH 2C 2D TC 5S AC 8H 9C 8D 3H TH 7H 5D 9H QH 4D
KH 4C JD 7D 2S 6H 4S 3D 7C 6S JS 3C 4H 8S KD TS AS 8C 6C 9D JH JC 2H TD AD 3S
3C 5D 9H 5S 3D 4C 2D 2C 6D 5C JC 7D JH 6H 7C KD AC 3H AD 9C 6C QH 5H JD AS KC
KS 8S TC 3S TH 8H AH QC 4D 6S 2H 4H KH 7S 2S 8C JS 9D 4S TD 9S TS 8D QD 7H QS
JS 6C 7H 4H 9D 9C 8C 8S 3D AC 6H TH QD JD 9S JH 7D 5D KD 4D 4C 7C 3H KC QS 2C
2S 2H QC KS AS 5C AH JC 8D 4S 9H AD KH 2D 5H 5S 8H 3S 6S TC 6D TS 7S 3C QH TD
9D 9S QS 6S JD 2S TD 7S 8C 3C 4H 4C AD KH 3H 9H 4D 5D 7C 8D 4S AS 5H 3D 2C QH
8S 6D TC QC KD TS 7H 8H AC 2D KC JS 7D 3S 9C 6H 5C QD 5S 6C JH 2H AH TH JC KS
7D 8C 6S AS 9H QH 7H QD KS TC 5D 4D JD 3C 5H TH KD 3H 4S QS 7C AH AC 6C 2C JH
TS 9S 9D KC 2H 8S 4H 9C 5C JC 7S 8H 3S JS KH 6H 2D QC 3D TD 6D 5S 8D 4C 2S AD
#
Code: Select all
15 piles remaining: 15 1 5 3 4 5 2 5 2 1 1 3 2 1 2
7 piles remaining: 34 8 6 1 1 1 1
7 piles remaining: 45 1 1 1 2 1 1
5 piles remaining: 33 12 4 1 2
7 piles remaining: 25 8 4 5 2 7 1
3 piles remaining: 28 23 1
5 piles remaining: 41 1 7 2 1
15 piles remaining: 30 1 3 1 1 1 1 3 1 2 1 3 2 1 1
3 piles remaining: 50 1 1
9 piles remaining: 28 2 9 4 2 1 1 4 1
9 piles remaining: 37 2 1 1 4 1 3 1 2
7 piles remaining: 33 2 6 3 6 1 1
5 piles remaining: 45 3 2 1 1
7 piles remaining: 32 13 1 1 1 1 3
4 piles remaining: 49 1 1 1
10 piles remaining: 29 9 3 2 1 1 1 4 1 1
7 piles remaining: 43 2 1 1 3 1 1
4 piles remaining: 46 4 1 1
6 piles remaining: 42 1 5 1 1 2
2 piles remaining: 39 13
7 piles remaining: 33 7 8 1 1 1 1
20 piles remaining: 3 7 3 1 7 5 3 1 1 3 4 1 1 4 1 2 1 2 1 1
2 piles remaining: 51 1
4 piles remaining: 41 2 7 2
2 piles remaining: 38 14
10 piles remaining: 11 2 9 7 3 4 7 4 1 4
11 piles remaining: 24 3 7 5 5 2 1 1 2 1 1
7 piles remaining: 41 1 1 2 2 1 4
2 piles remaining: 50 2
10 piles remaining: 25 6 4 3 4 2 2 4 1 1
8 piles remaining: 41 1 4 1 1 1 1 2
8 piles remaining: 39 5 1 1 3 1 1 1
11 piles remaining: 32 6 3 1 1 1 2 1 2 1 2
4 piles remaining: 49 1 1 1
12 piles remaining: 30 3 5 2 1 3 1 1 1 2 1 2
14 piles remaining: 24 2 2 2 4 2 1 4 2 2 1 4 1 1
10 piles remaining: 36 2 2 1 2 4 1 1 2 1
5 piles remaining: 40 7 2 1 2
10 piles remaining: 40 3 1 2 1 1 1 1 1 1
7 piles remaining: 42 5 1 1 1 1 1
14 piles remaining: 24 6 6 1 2 3 2 1 1 2 1 1 1 1
6 piles remaining: 46 1 1 1 1 2
13 piles remaining: 28 4 3 1 1 2 1 3 3 1 3 1 1
17 piles remaining: 20 6 1 1 1 2 2 1 2 4 2 1 2 1 4 1 1
5 piles remaining: 30 15 3 2 2
9 piles remaining: 34 2 1 2 5 5 1 1 1
4 piles remaining: 47 1 1 3
4 piles remaining: 40 2 2 8
3 piles remaining: 45 6 1
6 piles remaining: 37 8 2 3 1 1
6 piles remaining: 35 11 2 1 2 1
3 piles remaining: 50 1 1
13 piles remaining: 34 4 1 1 1 3 1 1 1 1 1 1 2
8 piles remaining: 41 1 2 1 1 2 1 3
4 piles remaining: 46 2 3 1
20 piles remaining: 26 1 1 3 1 1 1 3 2 1 2 1 1 2 1 1 1 1 1 1
8 piles remaining: 38 6 2 1 1 2 1 1
6 piles remaining: 39 1 5 3 1 3
6 piles remaining: 32 10 3 3 1 3
7 piles remaining: 30 2 5 5 7 1 2
8 piles remaining: 40 3 1 2 2 2 1 1
11 piles remaining: 28 3 1 1 6 1 5 4 1 1 1
16 piles remaining: 20 9 1 2 6 1 2 1 1 1 2 1 1 1 1 2
17 piles remaining: 15 2 1 9 1 1 7 1 1 2 2 2 2 3 1 1 1
3 piles remaining: 40 5 7
3 piles remaining: 34 8 10
4 piles remaining: 47 3 1 1
9 piles remaining: 39 5 1 1 1 2 1 1 1
12 piles remaining: 17 4 2 8 2 1 3 8 2 1 1 3
9 piles remaining: 39 2 1 3 1 1 1 3 1
12 piles remaining: 32 4 1 1 3 1 3 3 1 1 1 1
5 piles remaining: 36 4 4 5 3
13 piles remaining: 10 16 4 5 4 1 1 2 1 1 5 1 1
3 piles remaining: 49 1 2
8 piles remaining: 37 4 2 2 4 1 1 1
7 piles remaining: 44 2 2 1 1 1 1
3 piles remaining: 45 2 5
15 piles remaining: 25 3 5 2 1 2 1 2 1 2 3 1 1 1 2
5 piles remaining: 48 1 1 1 1
10 piles remaining: 39 4 1 1 1 1 1 1 1 2
15 piles remaining: 23 2 4 1 1 1 1 1 3 2 2 6 2 2 1
2 piles remaining: 49 3
8 piles remaining: 30 13 2 1 3 1 1 1
5 piles remaining: 37 9 3 1 2
19 piles remaining: 21 2 1 3 3 1 1 1 2 1 5 1 2 1 1 1 3 1 1
4 piles remaining: 42 5 3 2
18 piles remaining: 23 6 4 1 3 1 1 1 1 2 1 1 2 1 1 1 1 1
3 piles remaining: 50 1 1
5 piles remaining: 36 8 3 4 1
4 piles remaining: 40 8 3 1
8 piles remaining: 28 6 12 1 2 1 1 1
10 piles remaining: 37 2 2 1 5 1 1 1 1 1
10 piles remaining: 28 2 1 1 1 11 4 1 2 1
7 piles remaining: 41 4 3 1 1 1 1
3 piles remaining: 49 2 1
5 piles remaining: 38 5 7 1 1
6 piles remaining: 39 4 4 3 1 1
17 piles remaining: 6 1 4 12 2 3 1 2 1 1 3 2 2 6 1 4 1
8 piles remaining: 43 3 1 1 1 1 1 1
I stay home. Don't call me out.
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Fine? Thanks. But I get WA.
Code: Select all
#include<stdio.h>
char card[52][52][2];
int cnt_card[52],
look,match;
int ifMatch(int mode)
{
int step,i;
step=0;
match=look;
while(step<mode && match>0)
{
if(cnt_card[--match]!=0)
step++;
}
if(step<mode)
return 0;
if(card[look][cnt_card[look]-1][0]==card[match][cnt_card[match]-1][0] || card[look][cnt_card[look]-1][1]==card[match][cnt_card[match]-1][1])
{
card[match][cnt_card[match]][0]=card[look][cnt_card[look]-1][0];
card[match][cnt_card[match]][1]=card[look][cnt_card[look]-1][1];
cnt_card[match]++;
cnt_card[look]--;
return 1;
}
return 0;
}
int main()
{
char line1[200],line2[100];
int result[52],cnt_result,
i,j,k;
while(gets(line1),line1[0]!='#')
{
gets(line2);
i=0;
for(j=0;j<26;j++)
{
k=0;
while(k<2)
{
if(line1[i]>='0' && line1[i]<='9' || line1[i]>='A' && line1[i]<='Z')
card[j][0][k++]=line1[i];
i++;
}
}
i=0;
for(j=26;j<52;j++)
{
k=0;
while(k<2)
{
if(line2[i]>='0' && line2[i]<='9' || line2[i]>='A' && line2[i]<='Z')
card[j][0][k++]=line2[i];
i++;
}
}
for(i=0;i<52;i++)
cnt_card[i]=1;
look=1;
while(look<52)
{
if(cnt_card[look]!=0)
{
if(ifMatch(3)==1)
look=match;
else if(ifMatch(1)==1)
look=match;
else
look++;
}
else
look++;
}
cnt_result=0;
for(i=0;i<52;i++)
if(cnt_card[i]>0)
result[cnt_result++]=cnt_card[i];
printf("%d piles remaining:",cnt_result);
for(i=0;i<cnt_result;i++)
printf(" %d",result[i]);
printf("\n");
}
return 0;
}
I stay home. Don't call me out.
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
I have tried this input. My output is the same as yours, but I get WA.
The code is in pure C, no C++ extensions.
Can anybody say what is wrong?
The code is in pure C, no C++ extensions.
Can anybody say what is wrong?
Code: Select all
#include <stdio.h>
#define NCARDS 52
struct s_card {char face, suit;
struct s_card *prev, *next, *down;};
typedef struct s_card card;
card pack[NCARDS];
card first={'Z','Z',&first,pack,NULL};
card last={'Y','Y',pack+NCARDS-1,&last,NULL};
int input (void)
{
int i;
char c;
scanf ("%c",&c);
if (c=='#') return 0;
ungetc (c, stdin);
for (i=0; i<NCARDS; i++) scanf ("%c%c ", &pack[i].face, &pack[i].suit);
return 1;
}
void init (void)
{
card *p1, *p2;
pack[0].prev=&first;
for (p2=(p1=pack)+1; p2<pack+NCARDS; p1=p2++)
{
p1->next=p2; p2->prev=p1;
p1->down=NULL;
}
pack[NCARDS-1].down = NULL;
pack[NCARDS-1].next = &last;
}
void move (card *p, card *q)
{
if (p->down != NULL)
{
p->next->prev=p->prev->next=p->down;
p->down->prev=p->prev;
p->down->next=p->next;
}
else
{
p->next->prev=p->prev;
p->prev->next=p->next;
}
p->down=q;
p->prev=q->prev; p->next=q->next;
p->next->prev=p->prev->next=p;
}
void process (void)
{
card *p,*q;
init();
p=pack;
while (p!=&last)
{
if ((q=p->prev->prev->prev)->face==p->face || q->suit==p->suit ||
(q=p->prev)->face==p->face || q->suit==p->suit)
{
move (p,q);
}
else p=p->next;
}
}
void output (void)
{
int n;
card *p, *q;
for (n=0,p=first.next; p!=&last; n++,p=p->next);
printf ("%d pile",n);
if (n>1) printf ("s");
printf (" remaining:");
for (p=first.next; p!=&last; p=p->next)
{
for (n=0,q=p; q!=NULL; n++,q=q->down);
printf (" %d",n);
}
printf ("\n");
}
int main (void)
{
while (input())
{
process();
output();
}
return 0;
}