HDOJ 2074 叠筐

66 篇文章 0 订阅

题意:给出环的层数和两种图案,按样例要求输出

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2074

思路:找到规律,用循环模拟

注意点:无


以下为AC代码:

Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor
129761332015-02-22 15:53:15Accepted20740MS1304K2421 BG++luminous11
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define RDI(a) scanf ( "%d", &a )
#define RDII(a, b) scanf ( "%d%d", &a, &b )
#define RDIII(a, b, c) scanf ( "%d%d%d", &a, &b, &c );
#define RDS(s) scanf ( "%s", s );
#define PIL(a) printf ( "%d\n", a );
#define PIIL(a,b) printf ( "%d %d\n", a, b );
#define PIIL(a,b,c) printf ( "%d %d %d\n", a, b, c );
#define PSL(s) printf ( "%s\n", s );
#define REP(i,m,n) for ( int i = m; i <= n; i ++ )
#define DEP(i,m,n) for ( int i = m; i >= n; i -- )
#define REPI(i,m,n,k) for ( int i = m; i <= n; i += k )
#define DEPI(i,m,n,k) for ( int i = m; i >= n; i -= k )
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-10;
const int dir[4][2] = { 1,0, -1,0, 0,1, 0,-1 };
struct node{
    int x, y, cnt;
    node(){}
    node( int _x, int _y ) : x(_x), y(_y) {}
    node( int _x, int _y, int _cnt ) : x(_x), y(_y), cnt(_cnt) {}
};
int n;
int l, r, u, d;
string str_1, str_2;
char str[100][1001];
char a, b;
void init()
{
    l = 0;
    r = n - 1;
    u = 0;
    d = n - 1;
    clr ( str, 0 );
    a = str_1[0];
    b = str_2[0];
    if ( ( n - 1 ) % 4 == 0 )
        swap ( a, b );
}
void solve()
{
    char tmp;
    REP ( i, 0, ( n - 1 ) / 2 ){
        if ( i & 1 )
            tmp = a;
        else
            tmp = b;
        REP ( j, u, d ){
            REP ( k, l, r ){
                str[j][k] = tmp;
            }
        }
        u ++;
        d --;
        l ++;
        r --;
    }
    if ( n != 1 ){
        str[0][0] = str[0][n-1] = str[n-1][0] = str[n-1][n-1] = ' ';
    }
    REP ( i, 0, n - 1 ){
        PSL ( str[i] );
    }
}
int main()
{
    ios::sync_with_stdio( false );
    bool flag = 0;
    while ( cin >> n >> str_1 >> str_2 ){
        init();
        if ( flag )puts("");
        solve();
        flag = 1;
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值