cf 435C 暴力

直接暴力求出所有的坐标然后输出,记住每行的长度是固定的,是最长的那一行,也就是输出的个数,不够的行要用空格补齐

AC代码如下:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

struct Point{
    int x, y;
    int statu;
    bool operator<( const Point &b )const{
        if( y != b.y ){
            return y > b.y;
        }else{
            return x < b.x;
        }
    }
};

Point point[1100000];
int cnt;
int a[1100], N;

int main(){
    while( scanf( "%d", &N ) != EOF ){
        for( int i = 0; i < N; i++ ){
            scanf( "%d", &a[i] );
        }
        int nowx, nowy, nowt;
        nowx = nowy = 0;
        nowt = -1;
        cnt = 0;
        for( int i = 0 ; i < N; i++ ){
            nowt = -nowt;
            point[cnt].x = nowx;
            point[cnt].y = nowy;
            point[cnt].statu = nowt;
            cnt++;
            for( int j = 1; j < a[i]; j++ ){
                nowx++;
                nowy += nowt;
                point[cnt].x = nowx;
                point[cnt].y = nowy;
                point[cnt].statu = nowt;
                cnt++;
            }
            nowx++;
        }
        sort( point, point + cnt );
        int prey = point[0].y;
        point[0].y = 0;
        for( int i = 1; i < cnt; i++ ){
            if( point[i].y != prey ){
                prey = point[i].y;
                point[i].y = point[i-1].y + 1;
            }else{
                point[i].y = point[i-1].y;
            }
        }
        nowx = nowy = 0;
        for( int i = 0; i < cnt; i++ ){
            while( nowy < point[i].y ){
                while( nowx < cnt ){
                    printf( " " );
                    nowx++;
                }
                printf( "\n" );
                nowy++;
                nowx = 0;
            }
            while( nowx < point[i].x ){
                printf( " " );
                nowx++;
            }
            if( point[i].statu == 1 ){
                printf( "/" );
            }else{
                printf( "\\" );
            }
            nowx++;
        }
        while( nowx < cnt ){
            printf( " " );
            nowx++;
        }
        cout << endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值