zoukankan      html  css  js  c++  java
  • 2020杭电多校 第十场

    http://acm.hdu.edu.cn/search.php?field=problem&key=2020+Multi-University+Training+Contest+10&source=1&searchmode=source

    1003 Mine Sweeper 构造

     题意:

    构造一个r*c的网格,网格包含地雷单元和非地雷单元,地雷单元上没有数字,非地雷单元上有数字,非地雷单元上的数字等于非地雷单元上下左右和四个斜对角线上地雷单元的数量,现在给定一个n,构造一个r*c的网格,使得非地雷单元的数字和等于n。

    思路:

    (和牛客第三场D题有点像 https://ac.nowcoder.com/acm/contest/5668/D

    当n<24时,构造这样的序列就可以 : X.X.X.X.X.X.X.X.X.,,,

    当n>=24: 

    啊,图片最前面的矩阵截图没截完,缺了一排,和最后一排一样,全是X,手动补齐

       X X X X X X X

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN=1e5+5;
    const int mod=1e9+7;
    typedef long long ll;
    typedef  unsigned long long ull;
    typedef __int128 LL;
    const double eps=10e-8;
    const double pi=acos(-1.0);
    #define between(x,a,b)(a<=x && x<=b)
    //const int dir[8][2]={1,0,0,1,-1,0,0,-1-1,-1,-1,1,1,-1,1,1};
    const int inf=0x3f3f3f3f;
    const long long INF=0x3f3f3f3f3f3f3f3f;
    typedef pair<ll,ll> pII;
    typedef pair<int,int> pii;
    typedef pair<int,ll> piI;
    char ans[30][30];
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("1.in", "r", stdin);
        freopen("debug.out", "w", stdout);
    #endif
        int t;
        scanf("%d",&t);
        while(t--)
        {
            memset(ans,0,sizeof(ans));
            int n;
            scanf("%d",&n);
    
            if(n<24)
            {
                int sum=0;
                int i;
                for(i=1;;i++)
                {
                    if(i%2==0)ans[1][i]='.';
                    else ans[1][i]='X';
                    if(i>1)sum++;
                    if(sum==n)break;
                }
                printf("%d %d
    ",1,i);
                for(int j=1;j<=i;j++)printf("%c",ans[1][j]);
                printf("
    ");
            }
            else
            {
                int a=0,b=0;
                int nn=n/8;
                int cnt=n%8;
                int tmp=sqrt(nn);
                if(tmp*tmp==nn)a=tmp,b=tmp;
                else if(tmp*(tmp+1)>=nn)a=tmp,b=tmp+1;
                else a=tmp+1,b=tmp+1;
                int f=0;
                for(int i=1;i<=a;i++)
                {
                    for(int j=1;j<=b;j++)
                    {
                        ans[i*2][j*2]='.';
                        nn--;
                        if(nn==0)
                        {
                            f=1;
                            break;
                        }
                    }
                    if(f)break;
                }
                if(cnt>=1)ans[1][1]='.';
                if(cnt>=2)ans[1][2]='.';
                if(cnt>=3)ans[1][2*b+1]='.';
                if(cnt>=4)ans[1][2*b]='.';
                if(cnt>=5)ans[a*2+1][1]='.';
                if(cnt>=6)ans[a*2+1][2]='.';
                if(cnt>=7)
                {
                    if(ans[a*2][b*2]=='.')ans[a*2+1][b*2+1]='.';
                    else
                    {
                        ans[1][2]='X';
                        ans[1][1]='X';
                        ans[a*2+1][b*2+1]='.';
                    }
                }
                printf("%d %d
    ",a*2+1,b*2+1);
                for(int i=1;i<=2*a+1;i++)
                {
                    for(int j=1;j<=2*b+1;j++)
                    {
                        if(ans[i][j]=='.')printf("%c",ans[i][j]);
                        else printf("X");
                    }
                    printf("
    ");
                }
            }
        }
        return 0;
    }
    View Code

    有人随机过了,太强了,学到了!!!

    代码:(贴的别人代码,不想写了

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll N = 1e5 + 7;
    const ll mod = 1e9 + 7;
    
    int n;
    int b[N], a[N][2];
    struct gird{
        int siz;
        char g[25][25];
    };
    map<ll, gird> mp;
    int t;
    int lim = 20;
    gird gg;
    int gt[25][25];
    int fix[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1};
    
    bool ju(int x,int y)
    {
        if(x < 0 || y < 0 || x >= lim || y >= lim)
            return 0;
        return 1;
    }
    
    int main()
    {
        for (int kk = 2; kk <= 25;kk++)
        {
            lim = kk;
            for (int i = 0; i < lim; i++)
            {
                for (int j = 0; j < lim; j++)
                    gg.g[i][j] = '.', gt[i][j] = 0;
            }
    
            int t = 10000;
            int cot = 0;
            gg.siz = kk;
            mp[cot] = gg;
            srand(time(0));
            while(t--)
            {
                int x = rand() % lim;
                int y = rand() % lim;
    
                if(gg.g[x][y] == '.')
                {
                    gg.g[x][y] = 'X';
                    cot -= gt[x][y];
                    gt[x][y] = 0;
                    for (int i = 0; i < 8;i++)
                    {
                        int fx = x + fix[i][0];
                        int fy = y + fix[i][1];
                        if(ju(fx, fy) && gg.g[fx][fy] == '.')
                        {
                            gt[fx][fy]++;
                            cot++;
                        }
                    }
                }
                else if(gg.g[x][y] == 'X')
                {
                    gg.g[x][y] = '.';
                    int tmp = 0;
                    for (int i = 0; i < 8;i++)
                    {
                        int fx = x + fix[i][0];
                        int fy = y + fix[i][1];
                        if(ju(fx, fy))
                        {
                            if(gg.g[fx][fy] == '.')
                            {
                                gt[fx][fy]--;
                                cot--;
                            }
                            else
                            {
                                gt[x][y]++;
                            }
                        }
                    }
                    cot += gt[x][y];
                }
                if(mp.count(cot) == 0) mp[cot] = gg;
            }
        }
    
        int tn;
        scanf("%d", &tn);
        while(tn--)
        {
            int nn;
            scanf("%d", &nn);
            if(nn == 1 )
            {
                printf("1 2
    ");
                printf("X.
    ");
                continue;
            }
            else if( nn == 2)
            {
                printf("1 3
    ");
                printf("X.X
    ");
                continue;
            }
            else
            {
                gird tmp = mp[nn];
                printf("%d %d
    ", tmp.siz, tmp.siz);
                for (int i = 0; i < tmp.siz;i++)
                {
                    for (int j = 0; j < tmp.siz;j++)
                    {
                        printf("%c", tmp.g[i][j]);
                    }
                    printf("
    ");
                }
            }
        }
        return 0;
    }
    View Code

    1011 Task Scheduler

    题意:

    官方题解:

     练习就是 嗯,,,不会,,,,

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN=1e5+5;
    const int mod=1e9+7;
    typedef long long ll;
    typedef  unsigned long long ull;
    typedef __int128 LL;
    const double eps=10e-8;
    const double pi=acos(-1.0);
    #define between(x,a,b)(a<=x && x<=b)
    //const int dir[8][2]={1,0,0,1,-1,0,0,-1-1,-1,-1,1,1,-1,1,1};
    const int inf=0x3f3f3f3f;
    const long long INF=0x3f3f3f3f3f3f3f3f;
    typedef pair<ll,ll> pII;
    typedef pair<int,int> pii;
    typedef pair<int,ll> piI;
    struct node
    {
        int w,id;
    }a[105];
    bool cmp(node x,node y)
    {
        if(x.w==y.w)return x.id<y.id;
        return x.w>y.w;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("1.in", "r", stdin);
        freopen("debug.out", "w", stdout);
    #endif
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n,m,k;
            scanf("%d%d%d",&n,&m,&k);
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i].w);
                a[i].id=i;
            }
            if(k)sort(a+1,a+1+n,cmp);
            for(int i=1;i<=n;i++)
            {
                printf("%d%c",a[i].id,i==n?'
    ':' ');
            }
        }
        return 0;
    }
    View Code

    (一开始就猜了个结论,然后一看复杂度,没敢写,最后快10分钟,听隔壁队说猜了猜过了,嗯??然后我们一看过题时间,好多0ms过的,冲了,然后神奇的过了,,,,我tm之前在哪儿犹豫个啥????

  • 相关阅读:
    开源程序postGIS为postgresql提供存储空间地理数据的支持
    oracle官方文档
    postgresql转换符
    【转】oracle的Interval类型详解
    [转]千万不要把灯泡放进嘴里
    服务器运维指令
    莫名其妙的时区问题
    Linux内存思想
    oracle提高查询效率24法
    哈佛大学图书馆凌晨4点的景象
  • 原文地址:https://www.cnblogs.com/MZRONG/p/13537384.html
Copyright © 2011-2022 走看看