首页 > 其他 > 详细

sgu 170 Particles

时间:2018-10-15 10:17:13      阅读:126      评论:0      收藏:0      [点我收藏+]

题意:一个串变为另一个串要移动的次数。

串中相对位置相同的移过去就行。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#define mkp make_pair
using namespace std;
const double EPS=1e-8;
const int SZ=5010,INF=0x7FFFFFFF;
typedef long long lon;

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    //cin>>casenum;
    //for(lon time=1;time<=casenum;++time)
    {
        string str1,str2;
        cin>>str1>>str2;
        vector<int> arr,dst;
        for(int i=0;i<str1.size();++i)if(str1[i]==+)arr.push_back(i);
        for(int i=0;i<str2.size();++i)if(str2[i]==+)dst.push_back(i);
        if(arr.size()!=dst.size())cout<<-1<<endl;
        else
        {
            int res=0;
            for(int i=0;i<arr.size();++i)
            {
                res+=abs(arr[i]-dst[i]);
            }
            cout<<res<<endl;
        }
        
    }
    return 0;
}

 

sgu 170 Particles

原文:https://www.cnblogs.com/gaudar/p/9789263.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!