zoukankan      html  css  js  c++  java
  • BZOJ1258: [CQOI2007]三角形tri

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1258

    如果最后一位是4,那就改成123就好了。

    然后最后一位不是4的话,至多三个答案,然后可以发现把给的串最后一个改成4的一定会有。然后可以发现1继承其祖先12的,2继承13的,3继承23的,然后扫一遍。。

    (口胡了这么多还是自己找找规律吧TAT

    #include<cstring>
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #define rep(i,l,r) for (int i=l;i<=r;i++)
    #define down(i,l,r) for (int i=l;i>=r;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define maxn 2000
    using namespace std;
    int n,f[4];
    char s[maxn];
    int read(){
        int x=0,f=1; char ch=getchar();
        while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
        while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
        return x*f;
    }
    void out(){
        putchar('T');
        rep(i,1,n-1) putchar(s[i]);
        puts("4");
    }
    int main(){
     //     freopen("in.txt","r",stdin);
        scanf("%s",s);
        n=strlen(s)-1;
        if (s[n]=='4'){
            rep(i,1,3){
                putchar('T');
                rep(j,1,n-1) putchar(s[j]);
                printf("%d
    ",i);
            }
            return 0;
        }
        if (s[n]=='1') f[1]=f[3]=1;
        if (s[n]=='2') f[1]=f[2]=1;
        if (s[n]=='3') f[2]=f[3]=1;
        out();
        while (--n){
            int x=s[n]-'0';
            if (x==1) {
                if (f[2]) f[2]=0,out();
            }
            if (x==2){
                if (f[3]) f[3]=0,out();
            }
            if (x==3){
                if (f[1]) f[1]=0,out();
            }
        }
        return 0;
    }
  • 相关阅读:
    调用百度地图API添加点聚合时,marker标注的label标签刷新丢失问题
    redis--基本命令
    centos8安装redis6.0.5
    centos8更改镜像源
    centos8重启网络服务
    搭建eureka高可用
    html5图片缩放后上传blob
    mysql主从复制
    zTree
    datetimepicker使用总结
  • 原文地址:https://www.cnblogs.com/ctlchild/p/5143956.html
Copyright © 2011-2022 走看看