zoukankan      html  css  js  c++  java
  • hdu 4119 (模拟+字符串)成都现场赛I题

    题意:有一个矩阵每个格子有一个字母或者空格,现在有一个Mask旋转四次一定能覆盖所有的空格且不重复。然后Mask初始有四种不同的情况所以会产生四句话。要求输出所有单词都在字典里的那句话,如有多句则输出字典序最小的。

    思路:这道题若是不灵活使用STL则代码会很长,其实只要用map存字典,然后使用stringstream分割单词,在使用set得出字典序最小的就可以了。

    代码如下:

     1 /**************************************************
     2  * Author     : xiaohao Z
     3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
     4  * Last modified : 2014-03-22 16:59
     5  * Filename     : hdu_chengdu1.cpp
     6  * Description     : 
     7  * ************************************************/
     8 
     9 #include <iostream>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <cstdlib>
    13 #include <cmath>
    14 #include <algorithm>
    15 #include <queue>
    16 #include <stack>
    17 #include <vector>
    18 #include <sstream>
    19 #include <set>
    20 #include <map>
    21 #define MP(a, b) make_pair(a, b)
    22 #define PB(a) push_back(a)
    23 
    24 using namespace std;
    25 typedef long long ll;
    26 typedef pair<int, int> pii;
    27 typedef pair<unsigned int,unsigned int> puu;
    28 typedef pair<int, double> pid;
    29 typedef pair<ll, int> pli;
    30 typedef pair<int, ll> pil;
    31 
    32 const int INF = 0x3f3f3f3f;
    33 const double eps = 1E-6;
    34 const int LEN = 101;
    35 int n, m;
    36 map<string, int> mp;
    37 char Map[LEN][LEN], Mask[LEN][LEN], tMask[LEN][LEN];
    38 
    39 void read(){
    40     mp.clear();
    41     scanf("%d", &n);
    42     getchar();
    43     for(int i=0; i<n; i++){
    44         for(int j=0; j<n; j++){
    45             scanf("%c", &Map[i][j]);
    46         }
    47         getchar();
    48     }
    49     for(int i=0; i<n; i++){
    50         for(int j=0; j<n; j++){
    51             scanf("%c", &Mask[i][j]);
    52         }
    53         getchar();
    54     }
    55     scanf("%d", &m);
    56     char tmp[LEN];
    57     for(int i=0; i<m; i++){
    58         scanf("%s", tmp);
    59         mp[tmp] = 1;
    60     }
    61 }
    62 
    63 void Roundonce(){
    64     char tmp[LEN][LEN];
    65     for(int i=0; i<n; i++){
    66         for(int j=0; j<n; j++){
    67             tmp[j][n-i-1] = tMask[i][j];
    68         }
    69     }
    70     for(int i=0; i<n; i++){
    71         for(int j=0; j<n; j++){
    72             tMask[i][j] = tmp[i][j];
    73         }
    74     }
    75 }
    76 
    77 void getMask(int num){
    78     memcpy(tMask, Mask, sizeof Mask);
    79     for(int i=0; i<num; i++) Roundonce();
    80 }
    81 
    82 string getstr(){
    83     string ret = "";
    84     for(int i=0; i<4; i++){
    85         for(int j=0; j<n; j++){
    86             for(int k=0; k<n; k++){
    87                 if(tMask[j][k] == '*'){
    88                     if(Map[j][k] != '.') ret += Map[j][k];
    89                     else ret += " ";
    90                 }
    91             }
    92         }
    93         Roundonce();
    94     }
    95     return ret;
    96 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    R语言 逐步回归分析
    R语言 一元线性回归
    基于Qt的信号分析简单应用软件的设计
    【图论 5】图的应用——拓扑排序和关键路径
    【图论 3】图的应用——最小生成树
    B+树
    大概是最简明的B树博客了
    KMP算法
    【内存管理篇】基本分页存储管理方式
    双向链表为何时间复杂度为O(1)?
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3620003.html
Copyright © 2011-2022 走看看