首页 > 其他分享 >F - Transpose

F - Transpose

时间:2024-08-04 15:28:34浏览次数:6  
标签:ll Transpose next dfn low st now

原题链接

题解

很有意思的思想,一遇到括号就倒过来

code

#include<bits/stdc++.h>
#define ll long long
#define lb long double
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll inf=1e18;
const ll mod=1e9+7;
const ll N=4e5;
ll qpow(ll a,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
ll inv(ll x)
{
    return qpow(x,mod-2);
}
ll fa[2000005];
ll finds(ll now){return now==fa[now]?now:finds(fa[now]);}

vector<ll> G[200005];

ll dfn[200005],low[200005];
ll cnt=0,num=0;
ll in_st[200005]={0};
stack<ll> st;
ll belong[200005]={0};

void scc(ll now,ll fa)
{
    dfn[now]=++cnt;
    low[now]=dfn[now];
    in_st[now]=1;
    st.push(now);

    for(auto next:G[now])
    {
        if(next==fa) continue;

        if(!dfn[next])
        {
            scc(next,now);
            low[now]=min(low[now],low[next]);
        }
        else if(in_st[next])
        {
            low[now]=min(low[now],dfn[next]);
        }
    }

    if(low[now]==dfn[now])
    {
        ll x;
        num++;
        do
        {
            x=st.top();
            st.pop();
            in_st[x]=0;
            belong[x]=num;
        }while(x!=now);
    }
}

int trans[500005];
void solve()
{
    string s;
    cin>>s;
    int n=s.size();

    stack<int> st;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='(') st.push(i);
        else if(s[i]==')')
        {
            int last=st.top();
            st.pop();

            trans[last]=i;
            trans[i]=last;
        }
    }

    int step=1,sum=0,tem=0,id=0;
    while(tem<n)
    {
        if(s[id]=='('||s[id]==')')
        {
            id=trans[id];
            step=-step;
            sum++;
        }
        else
        {
            if(sum%2==0)
            {
                cout<<s[id];
            }
            else
            {
                if(s[id]>='a'&&s[id]<='z') cout<<(char)(s[id]-'a'+'A');
                else cout<<(char)(s[id]-'A'+'a');
            }
        }

        id+=step;
        tem++;
    }
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int TT=1;
    //cin>>TT;
    while(TT--) solve();
    return 0;
}


标签:ll,Transpose,next,dfn,low,st,now
From: https://www.cnblogs.com/pure4knowledge/p/18341786

相关文章

  • LeetCode //Bash - 194. Transpose File
    194.TransposeFileGivenatextfilefile.txt,transposeitscontent.Youmayassumethateachrowhasthesamenumberofcolumns,andeachfieldisseparatedbythe’’character. Example:Iffile.txthasthefollowingcontent:nameagealice21......
  • F - Transpose
    F-Transposehttps://atcoder.jp/contests/abc350/tasks/abc350_f 思路开辟数组,记录左右括号配对的位置值,例如:串:a(s)l位置:01234 数组值为配对数组:03010数组构成方法为使用stack记录左括号位置,遇到右括号时候,将当前位置值记录为stacktop值 基于此数组,使用df......
  • Tensorflow 中conv2d_transpose函数output_shape参数的由来和范围
    目录1.卷积和转置卷积(1)卷积(2)转置卷积2.tf.nn.conv2d函数和tf.nn.conv2d_transpose函数(1)tf.nn.conv2d函数(2)tf.nn.conv2d_transpose函数3.转置卷积output_shape参数的探讨(1)卷积过程中,存在尺度丢失现象。(2)转置卷积是恢复卷积之前原始信息的过程1.卷积和转置卷积(1)卷积......
  • NX二次开发 转置矩阵 UF_MTX3_transpose
    简介:    NX二次开发转置矩阵UF_MTX3_transpose。代码:#include"me.hpp"externDllExportvoidufusr(char*param,int*returnCode,intrlen){UF_initialize();doubledMtx[9]={1.000000000,0.000000000,0.000000000,0.000000000......
  • C++通过pybind11调用Python 实现transpose
    在某些场合需要在C++实现类似numpy的numpy.transpose(a,axes)功能,但是很多库如NumCpp都没有提供这样的方法,只有二维矩阵的转置,没法进行多维矩阵任意维度的转换。比较简单的想法就是利用numpy现有的功能,在c++代码里面通过调用python来调用Numpy的transpose。直接调用Python提......
  • Transpose a data frame in R语言 转置
     #firstrememberthenamesn<-df.aree$name#transposeallbutthefirstcolumn(name)df.aree<-as.data.frame(t(df.aree[,-1]))colnames(df.aree)<-ndf.aree$myfactor<-factor(row.names(df.aree))str(df.aree)#CheckthecolumntypesR......
  • 无涯教程-JavaScript - TRANSPOSE函数
    描述TRANSPOSE函数将单元格的垂直范围作为水平范围返回,反之亦然。必须将TRANSPOSE函数作为数组公式输入,该范围必须具有与行范围和列范围相同的行和列数。您可以使用TRANSPOSE在工作表上移动数组或范围的垂直和水平方向。语法TRANSPOSE(array)键入函数后,按CTRL+SHIFT......
  • nn.MaxPool2d()、transpose().contiguous()、view()说明
    1.nn.MaxPool2d()和nn.Conv2D()基本一样,但是stride默认值是kernel_size。2.transpose().contiguous()、view()contiguous一般与transpose,permute,view搭配使用:使用transpose或permute进行维度变换后,调用contiguous,然后方可使用view对维度进行变形print(x.shape)x=x.transpos......
  • 对DenseTensor进行Transpose
    ML.NET是微软推出的为.NET平台设计的深度学习库,通过这个东西(ModelBuilder)可以自己构建模型,并用于后来的推理与数据处理。虽然设计是很好的,但是由于现在的AI发展基本上都以python实现作为基础,未来这个东西的发展不好说,特别是模型构建部分。我个人认为,它提供的最有价值的场景......
  • np.transpose功能解析
    #代码1和代码2得到的结果是一样的,功能一致#features:(8325,62,5)#代码1feat_array_temp=np.transpose(features,(2,0,1))#5,8325,62ndarray#代码2feat_array_temp2=[]foriinrange(5):feat_array_temp2.append(features[:,:,i])feat_array_te......