String Transformation + CCPC2018-湖南全国邀请赛

Bobo has a string S=s1s2sn consists of letter `a`, `b` and `c`.
He can transform the string by inserting or deleting substrings `aa`, `bb` and `abab`.

Formally, A=uwv (`` '' denotes string concatenation) can be transformed into A=uv and vice versa where u, v are (possibly empty) strings and w{aa,bb,abab}.

Given the target string T=t1t2tm, determine if Bobo can transform the string S into T
.
Input The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains a string s1s2sn.
The second line contains a string t1t2tm.
Output For each test case, print `Yes` if Bobo can. Print `No` otherwise.

## Constraint

* 1n,m104
* s1,s2,,sn,t1,t2,,tm{a,b,c}
* The sum of n and m does not exceed 250,000.
Sample Input
ab
ba
ac
ca
a
ab
Sample Output
Yes
No
No


        
  
Hint
For the first sample, Bobo can transform as `ab => aababb => babb => ba`.
 

#define happy

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;


#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)

#define all(a) (a).begin(),(a).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second

ll rd(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

const int N=1e4+10;

char a[N],b[N];

int main(){
#ifdef happy
    freopen("in.txt","r",stdin);
#endif
    int n;
    while(~scanf("%s %s",a,b)){
        int len=strlen(a)-1;
        vector<int> aa,bb;
        int s,t;
        s=t=0;
        int aaa,bbb;
        aaa=bbb=0;
        rep(i,0,len){
            if(a[i]=='c'){
                aa.pb(s%2);
                aa.pb(t%2);
                s=t=0;
                aaa++;
            }else{
                if(a[i]=='a'){
                    s++;
                }else{
                    t++;
                }
            }
        }
        aa.pb(s%2);
        aa.pb(t%2);
        s=t=0;
        len=strlen(b)-1;
        rep(i,0,len){
            if(b[i]=='c'){
                bb.pb(s%2);
                bb.pb(t%2);
                s=t=0;
                bbb++;
            }else{
                if(b[i]=='a'){
                    s++;
                }else{
                    t++;
                }
            }
        }
        bb.pb(s%2);
        bb.pb(t%2);
        s=t=0;
        if(aaa!=bbb){
            puts("No");
            continue;
        }
        if(aa.size()!=bb.size()){
            puts("No");
            continue;
        }
        len=aa.size()-1;
        bool f=false;
        rep(i,0,len){
            if(aa[i]!=bb[i]){
                f=true;
                break;
            }
        }
        if(f){
            puts("No");
        }else puts("Yes");
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用PCL库实现ISS+SAC-IA点云配准的代码示例: ```C++ #include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/features/normal_3d.h> #include <pcl/features/iss_3d.h> #include <pcl/registration/ia_ransac.h> int main(int argc, char** argv) { // 加载点云 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>); pcl::io::loadPCDFile<pcl::PointXYZ>("input_cloud.pcd", *cloud_in); pcl::io::loadPCDFile<pcl::PointXYZ>("target_cloud.pcd", *cloud_out); // 计算法线 pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne; pcl::PointCloud<pcl::Normal>::Ptr normals_in(new pcl::PointCloud<pcl::Normal>); pcl::PointCloud<pcl::Normal>::Ptr normals_out(new pcl::PointCloud<pcl::Normal>); pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>); tree->setInputCloud(cloud_in); ne.setInputCloud(cloud_in); ne.setSearchMethod(tree); ne.setRadiusSearch(0.02); ne.compute(*normals_in); tree->setInputCloud(cloud_out); ne.setInputCloud(cloud_out); ne.setSearchMethod(tree); ne.compute(*normals_out); // 计算ISS关键点 pcl::ISSKeypoint3D<pcl::PointXYZ, pcl::PointXYZ> iss_detector; pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints_in(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints_out(new pcl::PointCloud<pcl::PointXYZ>); iss_detector.setInputCloud(cloud_in); iss_detector.setNormals(normals_in); iss_detector.setSalientRadius(6 * 0.01); iss_detector.setNonMaxRadius(4 * 0.01); iss_detector.setThreshold21(0.99); iss_detector.setThreshold32(0.99); iss_detector.compute(*keypoints_in); iss_detector.setInputCloud(cloud_out); iss_detector.setNormals(normals_out); iss_detector.compute(*keypoints_out); // SAC-IA配准 pcl::SampleConsensusInitialAlignment<pcl::PointXYZ, pcl::PointXYZ, pcl::FPFHSignature33> sac_ia; pcl::PointCloud<pcl::FPFHSignature33>::Ptr fpfhs_in(new pcl::PointCloud<pcl::FPFHSignature33>); pcl::PointCloud<pcl::FPFHSignature33>::Ptr fpfhs_out(new pcl::PointCloud<pcl::FPFHSignature33>); pcl::FPFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::FPFHSignature33> fpfh; fpfh.setInputCloud(keypoints_in); fpfh.setInputNormals(normals_in); fpfh.setSearchMethod(tree); fpfh.setRadiusSearch(0.05); fpfh.compute(*fpfhs_in); fpfh.setInputCloud(keypoints_out); fpfh.setInputNormals(normals_out); fpfh.compute(*fpfhs_out); sac_ia.setInputSource(keypoints_in); sac_ia.setSourceFeatures(fpfhs_in); sac_ia.setInputTarget(keypoints_out); sac_ia.setTargetFeatures(fpfhs_out); pcl::PointCloud<pcl::PointXYZ>::Ptr aligned(new pcl::PointCloud<pcl::PointXYZ>); sac_ia.align(*aligned); // 输出变换矩阵 std::cout << "Transformation matrix:" << std::endl << sac_ia.getFinalTransformation() << std::endl; // 可视化结果 pcl::visualization::PCLVisualizer viewer("PointCloud Viewer"); viewer.setBackgroundColor(0.0, 0.0, 0.0); viewer.addPointCloud<pcl::PointXYZ>(cloud_in, pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>(cloud_in, 255, 0, 0), "cloud_in"); viewer.addPointCloud<pcl::PointXYZ>(cloud_out, pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>(cloud_out, 0, 255, 0), "cloud_out"); viewer.addPointCloud<pcl::PointXYZ>(aligned, pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>(aligned, 0, 0, 255), "aligned"); viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "cloud_in"); viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "cloud_out"); viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "aligned"); viewer.addCoordinateSystem(1.0); viewer.initCameraParameters(); while (!viewer.wasStopped()) { viewer.spinOnce(); } return 0; } ``` 需要注意的是,这里使用了点云的ISS关键点和FPFH描述子来进行配准,因此需要先计算点云的法线,并提取ISS关键点和FPFH描述子。配准的结果可以通过变换矩阵来表示。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值