您的位置:首页 > 其它

hdu 4119 (模拟+字符串)成都现场赛I题

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

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

代码如下:

/**************************************************
* Author     : xiaohao Z
* Blog     : http://www.cnblogs.com/shu-xiaohao/ * Last modified : 2014-03-22 16:59
* Filename     : hdu_chengdu1.cpp
* Description     :
* ************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <set>
#include <map>
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned int,unsigned int> puu;
typedef pair<int, double> pid;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

const int INF = 0x3f3f3f3f;
const double eps = 1E-6;
const int LEN = 101;
int n, m;
map<string, int> mp;
char Map[LEN][LEN], Mask[LEN][LEN], tMask[LEN][LEN];

void read(){
mp.clear();
scanf("%d", &n);
getchar();
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
scanf("%c", &Map[i][j]);
}
getchar();
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
scanf("%c", &Mask[i][j]);
}
getchar();
}
scanf("%d", &m);
char tmp[LEN];
for(int i=0; i<m; i++){
scanf("%s", tmp);
mp[tmp] = 1;
}
}

void Roundonce(){
char tmp[LEN][LEN];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
tmp[j][n-i-1] = tMask[i][j];
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
tMask[i][j] = tmp[i][j];
}
}
}

void getMask(int num){
memcpy(tMask, Mask, sizeof Mask);
for(int i=0; i<num; i++) Roundonce();
}

string getstr(){
string ret = "";
for(int i=0; i<4; i++){
for(int j=0; j<n; j++){
for(int k=0; k<n; k++){
if(tMask[j][k] == '*'){
if(Map[j][k] != '.') ret += Map[j][k];
else ret += " ";
}
}
}
Roundonce();
}
return ret;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: