• hdu 4357 2012 多校


    题意:在一个字符串上有一种操作:交换两个字符然后两个都加一,'z'->'a'问你能不能通过这种操作把a串变为b串?

    思路:totally是一道智商题有木有。当字符串小于3的时候暴力算,大于等于三的时候一定有(a, b, c) -> (a, b+2, c)因此只要相差为偶数都可以,奇数则不行。

    代码如下:

     1 /**************************************************
     2  * Author     : xiaohao Z
     3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
     4  * Last modified : 2014-05-11 21:51
     5  * Filename     : H.cpp
     6  * Description     : 
     7  * ************************************************/
     8 
     9 #include <iostream>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <string>
    13 #include <cstdlib>
    14 #include <cmath>
    15 #include <algorithm>
    16 #include <queue>
    17 #include <stack>
    18 #include <vector>
    19 #include <set>
    20 #include <map>
    21 #define MP(a, b) make_pair(a, b)
    22 #define PB(a) push_back(a)
    23 
    24 using namespace std;
    25 typedef long long ll;
    26 typedef pair<int, int> pii;
    27 typedef pair<unsigned int,unsigned int> puu;
    28 typedef pair<int, double> pid;
    29 typedef pair<ll, int> pli;
    30 typedef pair<int, ll> pil;
    31 
    32 const int INF = 0x3f3f3f3f;
    33 const double eps = 1E-6;
    34 
    35 string sa, sb;
    36 
    37 void add(char &c){
    38     if(c == 'z') c = 'a';
    39     else c++;
    40 }
    41 
    42 void out(){
    43     for(int i=0; i<26; i++){
    44         if(sa == sb){
    45             cout << "YES" << endl;
    46             return ;    
    47         }
    48         swap(sa[0], sa[1]);
    49         add(sa[0]); add(sa[1]);
    50     }
    51     cout << "NO" << endl;
    52 }
    53 
    54 int main()
    55 {
    56 //    freopen("in.txt", "r", stdin);
    57 
    58     int T, ans, kase = 1;
    59     cin >> T;
    60     while(T--){
    61         cin >> sa >> sb;
    62         int cnt = 0;
    63         for(int i=0; i<sa.size(); i++){
    64             cnt += abs(sb[i] - sa[i]);
    65         }
    66         printf("Case #%d: ", kase++);
    67         if(sa.size() == 2) out();
    68         else if(cnt % 2 == 1) cout << "NO" << endl;
    69         else cout << "YES" << endl;
    70     }
    71     return 0;
    72 }
    View Code
  • 相关阅读:
    正则表达式匹配负数和数字
    下拉框select chosen被遮盖
    获取JavaScript对象的方法
    管理机--Jumpserver由docker搭建
    腾讯云--腾讯云sdk-实现脚本修改腾讯云负载均衡权重
    Linux系统中使用confluence构建企业wiki
    腾讯云--对象存储cos绑定自定义域名
    python(一)python的操作符
    pytest(五)用例传fixture参数
    pytest(四)firture自定义用例预置条件
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3722462.html
Copyright © 2020-2023  润新知