首页 > 代码库 > hdu 3257 Hello World!(位运算 & 模拟)
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?
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...
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.
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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。