码迷,mamicode.com
首页 > 其他好文 > 详细

贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

时间:2015-05-22 00:14:28      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     题意:找到一个字符串p,使得它和s,t的不同的总个数相同
 3     贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案
 4 */
 5 #include <cstdio>
 6 #include <algorithm>
 7 #include <cstring>
 8 #include <cmath>
 9 #include <iostream>
10 using namespace std;
11 
12 const int MAXN = 1e5 + 10;
13 const int INF = 0x3f3f3f3f;
14 int p[MAXN];
15 char s[MAXN], t[MAXN];
16 
17 int main(void)        //Codeforces Round #303 (Div. 2) B. Equidistant String
18 {
19     //freopen ("B.in", "r", stdin);
20 
21     while (scanf ("%s%s", s+1, t+1) == 2)
22     {
23         memset (p, 0, sizeof (p));
24         int len = strlen (s+1);        bool flag = false;
25         for (int i=1; i<=len; ++i)
26         {
27             if (s[i] == t[i])    p[i] = 0;
28             else
29             {
30                 if (flag)    {p[i] = t[i] - 0;    flag = !flag;}
31                 else    {p[i] = s[i] - 0;    flag = !flag;}
32             }
33         }
34         if (flag)    puts ("impossible");
35         else
36         {
37             for (int i=1; i<=len; ++i)
38                 printf ("%d", p[i]);
39             puts ("");
40         }
41     }
42 
43 
44     return 0;
45 }

 

贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4520866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!