设为首页 加入收藏

TOP

POJ 3087 Shuffle'm Up(模拟退火)
2015-07-20 17:53:46 来源: 作者: 【 】 浏览:1
Tags:POJ 3087 Shuffle' 模拟

Description

A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several different colors.

The actual shuffle operation is performed by interleaving a chip from S1 with a chip from S2 as shown below for C = 5:

\

The single resultant stack, S12, contains 2 * C<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPjwvZW0+IGNoaXBzLiBUaGUgYm90dG9tbW9zdCBjaGlwIG9mIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gaXMgdGhlIGJvdHRvbW1vc3QgY2hpcCBmcm9tIDxzdHJvbmc+UzxzdWI+Mjwvc3ViPjwvc3Ryb25nPi4gT24gdG9wIG9mIHRoYXQgY2hpcCwgaXMgdGhlIGJvdHRvbW1vc3QKIGNoaXAgZnJvbSA8c3Ryb25nPlM8c3ViPjE8L3N1Yj48L3N0cm9uZz4uIFRoZSBpbnRlcmxlYXZpbmcgcHJvY2VzcyBjb250aW51ZXMgdGFraW5nIHRoZSAyPHN1cD5uZDwvc3VwPiBjaGlwIGZyb20gdGhlIGJvdHRvbSBvZiA8c3Ryb25nPlM8c3ViPjI8L3N1Yj48L3N0cm9uZz4gYW5kIHBsYWNpbmcgdGhhdCBvbiA8c3Ryb25nPlM8c3ViPjEyPC9zdWI+PC9zdHJvbmc+LCBmb2xsb3dlZCBieSB0aGUgMjxzdXA+bmQ8L3N1cD4gY2hpcCBmcm9tIHRoZQogYm90dG9tIG9mIDxzdHJvbmc+UzxzdWI+MTwvc3ViPjwvc3Ryb25nPiBhbmQgc28gb24gdW50aWwgdGhlIHRvcG1vc3QgY2hpcCBmcm9tIDxzdHJvbmc+UzxzdWI+MTwvc3ViPjwvc3Ryb25nPiBpcyBwbGFjZWQgb24gdG9wIG9mIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4uPC9wPgo8cD5BZnRlciB0aGUgc2h1ZmZsZSBvcGVyYXRpb24sIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gaXMgc3BsaXQgaW50byAyIG5ldyBzdGFja3MgYnkgdGFraW5nIHRoZSBib3R0b21tb3N0IDxlbT48c3Ryb25nPkM8L3N0cm9uZz48L2VtPiBjaGlwcyBmcm9tIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gdG8gZm9ybSBhIG5ldyA8c3Ryb25nPlM8c3ViPjE8L3N1Yj48L3N0cm9uZz4gYW5kIHRoZSB0b3Btb3N0IDxlbT48c3Ryb25nPkM8L3N0cm9uZz48L2VtPiBjaGlwcwogZnJvbSA8c3Ryb25nPlM8c3ViPjEyPC9zdWI+PC9zdHJvbmc+IHRvIGZvcm0gYSBuZXcgPHN0cm9uZz5TPHN1Yj4yPC9zdWI+PC9zdHJvbmc+LiBUaGUgc2h1ZmZsZSBvcGVyYXRpb24gbWF5IHRoZW4gYmUgcmVwZWF0ZWQgdG8gZm9ybSBhIG5ldyA8c3Ryb25nPlM8c3ViPjEyPC9zdWI+PC9zdHJvbmc+LjwvcD4KPHA+Rm9yIHRoaXMgcHJvYmxlbSwgeW91IHdpbGwgd3JpdGUgYSBwcm9ncmFtIHRvIGRldGVybWluZSBpZiBhIHBhcnRpY3VsYXIgcmVzdWx0YW50IHN0YWNrIDxzdHJvbmc+UzxzdWI+MTI8L3N1Yj48L3N0cm9uZz4gY2FuIGJlIGZvcm1lZCBieSBzaHVmZmxpbmcgdHdvIHN0YWNrcyBzb21lIG51bWJlciBvZiB0aW1lcy48L3A+Cgo8cCBjbGFzcz0="pst">Input

The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

Each dataset consists of four lines of input. The first line of a dataset specifies an integer C, (1 ≤ C ≤ 100) which is the number of chips in each initial stack (S1 and S2). The second line of each dataset specifies the colors of each of the C chips in stack S1, starting with the bottommost chip. The third line of each dataset specifies the colors of each of the C chips in stack S2 starting with the bottommost chip. Colors are expressed as a single uppercase letter (A through H). There are no blanks or separators between the chip colors. The fourth line of each dataset contains 2 * C uppercase letters (A through H), representing the colors of the desired result of the shuffling of S1 and S2 zero or more times. The bottommost chip’s color is specified first.

Output

Output for each dataset consists of a single line that displays the dataset number (1 though N), a space, and an integer value which is the minimum number of shuffle operations required to get the desired resultant stack. If the desired result can not be reached using the input for the dataset, display the value negative 1 (?1) for the number of shuffle operations.

Sample Input

2
4
AHAH
HAHA
HHAAAAHH
3
CDE
CDE
EEDDCC

Sample Output

1 2
2 -1

按照要求模拟一遍,注意分配的顺序。模拟退火呀

#include
        
         
#include
         
           #include
          
            #include
           
             #include
            
              #include
              using namespace std; char s1[110],s2[110]; char s[110*2]; int n,c; int main() { cin>>n; for(int t=1;t<=n;t++) { cin>>c>>s1>>s2>>s; map
              
               visit;//标志映射 visit[s]=true; int step=0; while(true) { char str[110*2]; int len=0; for(int i=0;i
               
                

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVALive 4730 Kingdom 线段树+并.. 下一篇POJ 1080 Human Gene Functions(..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: