zoukankan      html  css  js  c++  java
  • 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门

      1 /*
      2     无算法
      3     三种可能:1.交换一对后正好都相同,此时-2
      4                 2.上面的情况不可能,交换一对后只有一个相同,此时-1
      5                 3.以上都不符合,则不交换,-1 -1
      6     
      7 */
      8 #include <cstdio>
      9 #include <iostream>
     10 #include <algorithm>
     11 #include <cmath>
     12 #include <cstring>
     13 #include <string>
     14 #include <map>
     15 #include <set>
     16 #include <vector>
     17 #include <set>
     18 using namespace std;
     19 
     20 const int MAXN = 2e5 + 10;
     21 const int INF = 0x3f3f3f3f;
     22 
     23 char s[MAXN], t[MAXN];
     24 int p[30][30];
     25 
     26 bool check1(int cnt)
     27 {
     28     for (int i=0; i<26; ++i)
     29     {
     30         for (int j=0; j<26; ++j)
     31         {
     32             if (p[i][j] && p[j][i])
     33             {
     34                 printf ("%d
    ", cnt-2);
     35                 printf ("%d %d
    ", p[i][j], p[j][i]);
     36                 return true;
     37             }
     38         }
     39     }
     40     
     41     return false;
     42 }
     43 
     44 bool check2(int cnt)
     45 {
     46     for (int i=0; i<26; ++i)
     47     {
     48         for (int j=0; j<26; ++j)
     49         {
     50             if (p[i][j])
     51             {
     52                 for (int k=0; k<26; ++k)
     53                 {
     54                     if (p[k][i])
     55                     {
     56                         printf ("%d
    ", cnt-1);
     57                         printf ("%d %d
    ", p[i][j], p[k][i]);
     58                         return true;
     59                     }
     60                 }
     61             }
     62         }
     63     }
     64     
     65     return false;
     66 }
     67 
     68 void work(int n)
     69 {
     70     int cnt = 0;
     71     for (int i=0; i<n; ++i)
     72     {
     73         if (s[i] != t[i])
     74         {
     75             p[s[i]-'a'][t[i]-'a'] = i + 1;
     76             cnt++;
     77         }
     78     }
     79     if (check1 (cnt))   return ;
     80     if (check2 (cnt)) return ;
     81     
     82     printf ("%d
    ", cnt);
     83     puts ("-1 -1");
     84 }
     85 
     86 int main(void)
     87 {
     88     //freopen ("B.in", "r", stdin);
     89     
     90     int n;
     91     while (~scanf ("%d", &n))
     92     {
     93         memset (p, 0, sizeof (p));
     94         scanf ("%s", &s);
     95         scanf ("%s", &t);
     96         
     97         work (n);
     98     }
     99     
    100     return 0;
    101 }
    编译人生,运行世界!
  • 相关阅读:
    题解 P3842 【[TJOI2007]线段】
    题解 CF1366A 【Shovels and Swords】
    题解 CF1391D
    题解 CF1374B 【Multiply by 2, divide by 6】
    CSP-J2020爆零记
    YbtOJ20025 放置石子
    YbtOJ20001 立方数差
    [仅供参考]W-RB的码风及要求
    [敲黑板]CSP考试策略
    [水沝淼㵘]向量水解
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4366802.html
Copyright © 2011-2022 走看看