hdu 3257 Hello World!(位运算 & 模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3257

Hello World!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 476    Accepted Submission(s): 180

Problem Description

Your task is to print ... er ... "Hello World" ... in a fantastic way -- using a beautiful font.

I‘ve sent you a nice font for you to use, but I‘m too busy to tell you how. Can you help yourself?

Input

The first line contains a single integer T (T <= 20), the number of test cases.

Each case begins with an integer C (1 <= C <= 80) in a single line, then each of the following C lines contains five two-digit numbers in hex (letters will be in uppercase). Don‘t ask me what they mean, I‘m too busy...

Output

For each test case, print the case number in the first line, then followed by a blank line.

After that, print all T characters. Use a single blank column of spaces between two consecutive characters. Each line should have exactly 6C-1 character (again, don‘t ask me why).

Don‘t forget to print another blank line after the output of each test case.

Sample Input

2
11
7F 08 08 08 7F
38 54 54 54 18
00 41 7F 40 00
00 41 7F 40 00
38 44 44 44 38
00 00 00 00 00
3F 40 38 40 3F
38 44 44 44 38
7C 08 04 04 08
00 41 7F 40 00
38 44 44 48 7F
5
14 08 3E 08 14
04 02 01 02 04
40 40 40 40 40
04 02 01 02 04
14 08 3E 08 14

Sample Output

Case 1:

#   #        ##    ##               #   #              ##       #
#   #         #     #               #   #               #       #
#   #  ###    #     #    ###        #   #  ###  # ##    #    ## #
##### #   #   #     #   #   #       # # # #   # ##  #   #   #  ##
#   # #####   #     #   #   #       # # # #   # #       #   #   #
#   # #       #     #   #   #       # # # #   # #       #   #   #
#   #  ###   ###   ###   ###         # #   ###  #      ###   ####

Case 2:

        #           #
  #    # #         # #    #
# # # #   #       #   # # # #
 ###                     ###
# # #                   # # #
  #                       #
            #####            

Source

2009 Asia Regional Ningbo Online

思路:

首先想到这题是十六进制转换为二进制,我们先令tt为1,然后在用位运算向左移动(<<),

每移动一次就让所有的a[]和当前的tt&(与)一次,如果值为1那么就说明当前的a[i]的二进制

中在此处有1,也就是应该输出“#”,(主要是用到了位运算的‘<<’和‘&’);

再细细体味一下吧!

代码如下:

//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
//const double pi = atan(1.0)*4;
const double pi = 3.1415926535897932384626;
#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
#define MAXN 80*5+47
int main()
{
    int t;
    int n;
    int a[MAXN];
    int cas = 0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i = 0; i < 5*n; i++)
        {
            scanf("%X",&a[i]);
        }
        int tt;
        printf("Case %d:\n\n",++cas);
        for(int i = 0; i < 7; i++)
        {
            tt = 1;
            tt <<= i;
            for(int j = 0; j < 5*n; j++)
            {
                if(j != 0 && j %5 == 0)
                    printf(" ");
                if(a[j] & tt)
                    printf("#");
                else
                    printf(" ");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

hdu 3257 Hello World!(位运算 & 模拟)

时间: 2024-10-11 02:43:37

hdu 3257 Hello World!(位运算 & 模拟)的相关文章

hdu 1882 Strange Billboard(位运算+枚举)

http://acm.hdu.edu.cn/showproblem.php?pid=1882 感觉非常不错的一道题. 给一个n*m(1<=n,m<=16)的矩阵,每一个格子都有黑白两面,当翻一个格子时,它的上下左右都要翻转,问最后使格子全变为白色的最少翻转步数. 仅仅需枚举第一行的状态即可,由于对于第i(i>=2)行j列翻转情况受上一行的制约,仅仅有当上一行也是'X'的时候,该行j列才干翻转,使i-1行j列变为'.',否则i行j列不能翻转.依次进行下去,当最后一行全变为白色,说明翻转成功

HDU 1882 Strange Billboard(位运算)

题目链接 题意 : 给你一个矩阵,有黑有白,翻转一个块可以让上下左右都翻转过来,问最少翻转多少次能让矩阵变为全白. 思路 : 我们从第一行开始枚举要翻转的状态,最多可以枚举到2的16次方,因为你只要第一行的确定了,第二行要翻转的也就确定了,所以第一行的状态决定了最后的状态.看了网上大神,真是让位运算废了啊,,,,,太复杂了...... 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #

HDU 5491 The Next(位运算)

题意:已知D(0<=D<2^31).s1.s2,其中L为D转化为二进制数时1的个数,题目保证s1<=L<=s2,求一个数,满足以下条件: 1.比D大 2.转化为二进制时1的个数在[s1, s2]内 3.找出满足1.2条件的最小数字 分析: 1.首先将D加1,假设该数为x,求出x转化为二进制时1的个数cnt. 2.若s1<=cnt<=s2,则输出x 3.若cnt<s1,则应当增加1的数目,因为要保证找到的数字最小,所以要从二进制数的最右边开始改变. 方法:从右向左,

[HDU] 3711 Binary Number [位运算]

Binary Number Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1475    Accepted Submission(s): 933 Problem Description For 2 non-negative integers x and y, f(x, y) is defined as the number of dif

HDU - 6186 前缀和位运算

异或操作蒙蔽了我的双眼 以至于没有第一时间想到前缀和与后缀和 水题做的不够多 #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=j;i<=k;i++) #define rrep(i,j,k) for(register int i=j;i>=k;i--) using namespace std; typedef long long ll; const int maxn = 1e5+11; ll xxor[max

【模拟+递归+位运算】POJ1753-Flip Game

由于数据规模不大,利用爆搜即可.第一次用位运算写的,但是转念一想应该用递归更加快,因为位运算没有剪枝啊(qДq ) [思路] 位运算:时间效率较低(172MS),有些辜负了位运算的初衷.首先将二维数组倒序看作一个二进制数num.我们假设1代表翻转,0代表不翻转,可以发现以下规律:0 xor 1=1,1 xor 1=0;0 xor 0=0,1 xor 0=1,恰巧满足异或运算.我们假设另一个二进制数i∈[0,2^16),通过异或运算就可以模拟出所有清形. 用check和i进行&操作可以求出以哪些位

HDU 5023 A Corrupt Mayor&#39;s Performance Art(线段树+优美的位运算)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this

HDU 2276 Kiki &amp; Little Kiki 2 (位运算+矩阵快速幂)

HDU 2276 Kiki & Little Kiki 2 (位运算+矩阵快速幂) ACM 题目地址:HDU 2276 Kiki & Little Kiki 2 题意: 一排灯,开关状态已知,每过一秒:第i个灯会根据刚才左边的那个灯的开关情况变化,如果左边是开的,它就会变化,如果是关的,就保持原来状态.问m秒后的状态. 第1个的左边是最后一个. 分析: 转移不好想啊... 变化是这样的: 原来 左边 变化 1 1 0 1 0 1 0 1 1 0 0 0 然后想到 (~原来)^(左边)=变化

hdu 2721(字符串处理,位运算 暴力)

Persistent Bits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 201    Accepted Submission(s): 116 Problem Description WhatNext Software creates sequence generators that they hope will produce