Second——Training

HNAU Second Training Problem

考查知识点  hdu题号    problem_name               难度系数
A.数学题    1220     Cube                                    ★        2.0  
B.字符串    2707     Steganography                    ☆        1.5             
C.搜索       1240     Asteroids!                            ★         2.0  
D.线段树    1540     Tunnel Warfare                         3.0
E.图论       1599       find the mincost route        ★      3.0
F.dp          1545       01-K Code
G.博弈      1536       S-Nim 
H.趣题      1538       A Puzzle for Pirates

hdu 1220 Cube (数学)

Problem Description
Cowl is good at solving math problems. One day a friend asked him such a question: You are given a cube whose edge length is N, it is cut by the planes that was paralleled to its side planes into N * N * N unit cubes. Two unit cubes may have no common points or two common points or four common points. Your job is to calculate how many pairs of unit cubes that have no more than two common points.
Process to the end of file.
 Input
There will be many test cases. Each test case will only give the edge length N of a cube in one line. N is a positive integer(1<=N<=30).
 Output
For each test case, you should output the number of pairs that was described above in one line.
 思路:       对于任何两个单位立方体,交点个数的情况有0个、1个、2个、4个;2个公共点时,有一条公共边;4个公共点时,有一个公共面。
             这题 求不多于两个公共点的单位立方体的对数,则可先求出4个公共点的单位立方体的对数。
 
             4个交点的立方体对是两个立方体共面的情况,求出大的立方体一共有多少个单位面积的公共面;
             即所有单位立方体的面数6*n^3减去在大立方体表面的面数6*n^2就可以了

ans=(n*n*n*(n*n*n-1)/2)-(6*n*n*n-6*n*n)/2;

B  Steganography字符串处理

Problem Description
In cryptography, the goal is to encrypt a message so that, even if the the message is intercepted, only the intended recipient can decrypt it. In steganography, which literally means "hidden writing", the goal is to hide
the fact that a message has even been sent. It has been in use since 440 BC. Historical methods of steganography include invisible inks and tatooing messages on messengers where they can't easily be seen. A modern method is to encode a message using the least-significant bits of the RGB color values of pixels in a digital image.
For this problem you will uncover messages hidden in plain text. The spaces within the text encode bits; an odd number of consecutive spaces encodes a 0 and an even number of consecutive spaces encodes a 1. The
four texts in the example input below (terminated by asterisks) encode the following bit strings: 11111, 000010001101101, 01, and 000100010100010011111. Each group of five consecutive bits represents a
binary number in the range 0–31, which is converted to a character according to the table below. If the last group contains fewer than five bits, it is padded on the right with 0's.
" " (space) 0
"A" – "Z" 1–26
"'" (apostrophe) 27
"," (comma) 28
"-" (hyphen) 29
"." (period) 30
"?" (question mark) 31
The first message is 111112 = 3110 = "?". The second message is (00001, 00011, 01101)2 = (1, 3, 13)10 =
"ACM". The third message is 010002 = 810 = "H", where the underlined 0's are padding bits. The fourth message is (00010, 00101, 00010, 01111, 10000)2 = (2, 5, 2, 15, 16)10 = "BEBOP". 
Input
The input consists of one or more texts. Each text contains one or more lines, each of length at most 80 characters, followed by a line containing only "*" (an asterisk) that signals the end of the text. A line containing only "#" signals the end of the input. In addition to spaces, text lines may contain any ASCII letters, digits, or punctuation, except for "*" and "#", which are used only as sentinels.
 Output
For each input text, output the hidden message on a line by itself. Hidden messages will be 1–64 characters long.
Note: Input text lines and output message lines conform to all of the whitespace rules listed in item 7 of Notes to Teams except that there may be consecutive spaces within a line. There will be no spaces at the beginning or end of a line.
 Sample Input
Programmer,
I  would  like  to  see
a  question
mark.
*
Behold, there is more to  me than you might
think  when  you read  me  the first  time.
*
Symbol for  hydrogen?
*
A B C D  E F G H  I J  K L M N  O P Q  R  S  T  U  V
*
#
 Sample Output
?
ACM
H
BEBOP

题意:数连续的空格数,奇数为0,偶数为1 然后每5个变为一个整数<0,31> 在将整数对应的符号输出。

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

string s;
void output(int x)
{
    switch(x)
    {
        case  0: printf(" ");break;
        case 27: printf("'");break;
        case 28: printf(",");break;
        case 29: printf("-");break;
        case 30: printf(".");break;
        case 31: printf("?");break;
        default: printf("%c",64+x);break;
    }
}
int toint(int k)
{
    int ans=0;
    for(int i=0;i<5;i++)
    {
        ans=ans<<1;
        if(s[k+i]=='1')
        {
           ans=ans+1;
        }
    }
    return ans;
}
void translate()
{
    while(s.length()%5)
    {
        s+='0';
    }
    int len=s.length();
    for(int i=0;i<len;i+=5)
    {
       output(toint(i));
    }
    cout<<endl;
}
int main()
{
    char c;
    int remind=0;
    while((c=getchar())!='#')
    {
        if(c=='*')
        {
            translate();
            s="";
        }
        if(c!=' '&&remind>0)
        {
            s+=((remind&1)?'0':'1');
            remind=0;
        }
        if(c==' ')
            remind++;
    }
    return 0;
}


C Asteroids!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
using namespace std;
#define M 12

char graph[M][M][M];
bool vis[M][M][M];
int n;
struct Point{
  int x,y,z;
  int step;
  bool operator ==(const Point &b)
  {
      return (x==b.x&&y==b.y&&z==b.z);
  }
  bool ok()
  {
      if(x>=0&&x<n&&y>=0&&y<n&&z>=0&&z<n)
        return 1;
      else
        return 0;
  }
}s,e;
int dir[6][3]={{0,0,1},{0,0,-1},{0,-1,0},{0,1,0},{1,0,0},{-1,0,0}};
bool bfs()
{
    memset(vis,0,sizeof(vis));
    vis[s.z][s.x][s.y]=1;
    int i;
    Point pre,now;
    queue<Point>Q;
    Q.push(s);
    while(!Q.empty())
    {
      pre=Q.front();
      //cout<<pre.x<<" "<<pre.y<<" "<<pre.z<<endl;
      Q.pop();
      for(i=0;i<6;i++)
      {
          now.x=pre.x+dir[i][0];
          now.y=pre.y+dir[i][1];
          now.z=pre.z+dir[i][2];
          now.step=pre.step+1;
          if(now.ok()&&!vis[now.z][now.x][now.y]&&(graph[now.z][now.x][now.y]=='O'))
          {
              if(now==e)
              {
                  printf("%d %d\n",n,now.step);
                  return 1;
              }
              Q.push(now);
              vis[now.z][now.x][now.y]=1;
          }
      }
    }
    return 0;
}


int main()
{
    int i,j;
    //freopen("in.txt","r",stdin);
    char str[20];
    while(~scanf("%s",str))
    {
        scanf("%d",&n);
        getchar();
         for(i=0;i<n;i++)//z
          for(j=0;j<n;j++)//x
             scanf("%s",graph[i][j]);
      //graph[z][x]  [y];
        scanf("%d%d%d",&s.x,&s.y,&s.z);
        s.step=0;
        scanf("%d%d%d",&e.x,&e.y,&e.z);
        getchar();
        scanf("%s",str);
        if(graph[s.z][s.x][s.y]=='X'||graph[e.z][e.x][e.y]=='X'||s==e)
        {
            printf("%d 0\n",n);
            continue;
        }
        if(!bfs())
            printf("NO ROUTE\n");
    }
    return 0;
}





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值