LOI 54 成立一周年纪(zuo)念(si)

---恢复内容开始---

本来今天双向BFS题解都写了一半了,忘保存,然后关了,所以就。。。。。。呵呵

然后,今天是LOI 54成立一周年(或许吧,时间不是太精确)。

so,今天不写题解了,作死啊。。。。。。。。

今天有一道题还没A,但是快了,毕竟,string-findnext还不会。

算了,不说了,贴个代码草草收场吧。

题目:

1099 字串变换

2002年NOIP全国联赛提高组

时间限制: 1 s
空间限制: 128000 KB
题目等级 : 黄金 Gold
 
 
 
题目描述 Description

已知有两个字串 A$, B$ 及一组字串变换的规则(至多6个规则):
     A1$ -> B1$
     A2$ -> B2$
  规则的含义为:在 A$中的子串 A1$ 可以变换为 B1$、A2$ 可以变换为 B2$ …。
    例如:A$='abcd' B$='xyz'
  变换规则为:
    ‘abc’->‘xu’ ‘ud’->‘y’ ‘y’->‘yz’

  则此时,A$ 可以经过一系列的变换变为 B$,其变换的过程为:
   ‘abcd’->‘xud’->‘xy’->‘xyz’

  共进行了三次变换,使得 A$ 变换为B$。

输入描述 Input Description

输入格式如下:

   A$ B$
   A1$ B1$ \
   A2$ B2$  |-> 变换规则
   ... ... / 
  所有字符串长度的上限为 20。

输出描述 Output Description

若在 10 步(包含 10步)以内能将 A$ 变换为 B$ ,则输出最少的变换步数;否则输出"NO ANSWER!"

样例输入 Sample Input

abcd xyz
abc xu
ud y
y yz

样例输出 Sample Output

3

数据范围及提示 Data Size & Hint

hehe 

 

80分代码(有个bug以后再说):

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 using namespace std;
 6 struct state
 7 {
 8     string a;
 9     int dep;
10 }fir[5010],las[5010];
11 int cnt=1;
12 string s[8],t[8];
13 int lens[8],lent[8];
14 void bfs()
15 {
16     int head1,tail1,head2,tail2;
17     head1=tail1=head2=tail2=1;
18     while(head1<=tail1 && head2<=tail2)
19     {
20         if (fir[head1].dep+las[head2].dep>10)
21         {
22             printf("NO ANSWER!\n");
23             return ;
24         }
25         for(int i=1;i<=cnt;i++)
26         {
27             int pos=fir[head1].a.find(s[i]);
28             if(pos!=string::npos)
29             {
30                 string ss="";
31                 for(int j=0;j<pos;j++)ss+=fir[head1].a[j];
32                 ss+=t[i];
33                 for(int j=pos+lens[i];j<fir[head1].a.length();j++)ss+=fir[head1].a[j];
34                 tail1++;
35                 fir[tail1].a=ss;
36                 fir[tail1].dep=fir[head1].dep+1;
37           //      cout << fir[tail1].a << endl;
38                 for (int k=1;k<=tail2;k++)
39                     if (fir[tail1].a==las[k].a)
40                     {
41                        printf("%d\n",fir[tail1].dep+las[k].dep);
42                        return;
43                     }
44             }
45         }
46         head1++;
47         for(int i=1;i<=cnt;i++)
48         {
49             int pos=las[head2].a.find(t[i]);
50             if(pos!=string::npos)
51             {
52                 string ss="";
53                 for(int j=0;j<pos;j++)ss+=las[head2].a[j];
54                 ss+=s[i];
55                 for(int j=pos+lent[i];j<las[head2].a.length();j++)ss+=las[head2].a[j];
56                 tail2++;
57                 las[tail2].a=ss;
58                 las[tail2].dep=las[head2].dep+1;
59             //    cout << las[tail2].a << endl;
60                 for (int k=1;k<=tail1;k++)
61                     if (fir[k].a==las[tail2].a)
62                     {
63                        printf("%d\n",fir[k].dep+las[tail2].dep);
64                        return;
65                     }
66             }
67         }
68         head2++;
69     }
70     printf("NO ANSWER!\n");
71 }
72 int main()
73 {
74     cin>>fir[1].a>>las[1].a;
75     fir[1].dep=las[1].dep=0;
76     while(cin>>s[cnt]>>t[cnt])
77     {
78         lens[cnt]=s[cnt].length();
79         lent[cnt]=t[cnt].length();
80         cnt++;
81     }
82     cnt--;
83     bfs();
84 }
View Code

 

转载于:https://www.cnblogs.com/Skyvot/p/4046185.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮我地道的翻译:The differential variational inequalities ((DVIs), for short) are useful for the study of models involving both dynamics and constraints in the form of in￾equalities. They arise in many applications: electrical circuits with ideal diodes, Coulomb friction problems for contacting bodies, economical dynamics, dynamic traffic networks. Pang and Stewart [26], [27] established the existence, unique￾ness, and Lipschitz dependence of solutions subject to boundary conditions for (DVIs) in finite dimensional spaces. Han and Pang investigated a class of dif￾ferential quasi-variational inequalities in [11], and Li, Huang and O’Regan [18] studied a class of differential mixed variational inequalities in finite dimensional Well-Posedness of Differential Mixed Quasi-Variational-Inequalities 137 spaces. Gwinner [8] obtained an equivalence result between (DVIs) and projected dynamical systems. In [9] he also proved a stability property for (DVIs) by using the monotonicity method of Browder and Minty, and Mosco set convergence. Chen and Wang [4] studied dynamic Nash equilibrium problems which have the formulation of differential mixed quasi-variational inequalities. Elastoplastic contact problems can also be incorporated into (DMQVIs) formulation because general dynamic processes in the nonsmooth unilateral contact problems are governed by quasi-variational inequalities. A numerical study for nonsmooth contact problems with Tresca friction can be found in [10], Liu, Loi and Obukhovskii [19] studied the existence and global bifurcation for periodic solutions of a class of (DVIs) by using the topological degree theory for multivalued maps and the method of guiding functions. For more details about (DVIs) we refer to [3], [30], [12], [22]–[21].
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值