• 【bzoj1258】三角形tri[CQOI2007](乱搞)


      题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1258

      这是道很意思的大水题,虽然看上去一脸懵逼,但画张图出来看看也可以窥见一丝端倪。

      首先,如果给定三角形编号的末位是‘4’,那么与它接壤的三角形,就只有它周围的三个,于是直接把最后的'4'改成‘1’,‘2’,‘3’就行了。

      然而如果末位不是‘4’,似乎情况要稍微复杂一些……慢着,好像对于任意一个三角形,都最多只有3个与它接壤的三角形,这是因为这个三角形的三条边最多只能与一个三角形接壤,并且此时这些三角形的编号都是原三角形编号的前缀,把最后一位改为'4'。并且,如果在一个三角形中,若编号中有重复的数值,那么对于每个数值,只有最后一个能通过这种方式变为与原三角形接壤的三角形。

      解释:

      注意这个图,假设当前三角形是T11,那么他不可能与T4接壤,因为在第二个'1'出现时,它就会被挤到角落去,无法与中心的T4接壤。

      于是代码就好写了。

    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<ctime>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<map>
    #define ll long long
    #define ull unsigned long long
    #define max(a,b) (a>b?a:b)
    #define min(a,b) (a<b?a:b)
    #define lowbit(x) (x& -x)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define eps 1e-18
    #define maxn 100020
    inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
    inline ll power(ll a,ll b){ll ans=0; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
    inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
    using namespace std;
    char s[60];
    bool vis[4];
    int n;
    int main()
    {
        scanf("%s",s); n=strlen(s);
        if(s[n-1]=='4'){
            s[n-1]='1'; printf("%s
    ",s);
            s[n-1]='2'; printf("%s
    ",s);
            s[n-1]='3'; printf("%s
    ",s);
            return 0;
        }
        for(int i=n-1;i;i--){
            if(vis[s[i]-'0'])continue;
            vis[s[i]-'0']=1;
            s[i]='4'; s[i+1]='';
            printf("%s
    ",s);
        }
    }
    bzoj1258
  • 相关阅读:
    python爬虫headers设置后无效解决方案
    idea建立web项目servlet映射的地址/jsp访问不到
    bootstrap栅格系统错位问题
    python2 python3共存解决方案
    Springboot+Thymeleaf框架的button错误
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
  • 原文地址:https://www.cnblogs.com/quzhizhou/p/9390865.html
Copyright © 2020-2023  润新知