hdu 4119 (模拟+字符串)成都现场赛I题
2014-03-24 00:11
411 查看
题意:有一个矩阵每个格子有一个字母或者空格,现在有一个Mask旋转四次一定能覆盖所有的空格且不重复。然后Mask初始有四种不同的情况所以会产生四句话。要求输出所有单词都在字典里的那句话,如有多句则输出字典序最小的。
思路:这道题若是不灵活使用STL则代码会很长,其实只要用map存字典,然后使用stringstream分割单词,在使用set得出字典序最小的就可以了。
代码如下:
View Code
思路:这道题若是不灵活使用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
相关文章推荐
- HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)
- 【模拟】2011 Asia ChenDu Regional Contest 成都现场赛 hdu 4119
- HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)
- HDU 4119 Isabella's Message (2011年成都赛区现场赛I题)
- hdu 4119 Isabella's Message【字符串模拟】
- [HDU 4119]Isabella's Message[字符串模拟]
- hdu 3715(2-sat入门题目)2010成都现场赛1007题
- hdu 5414 CRB and String(字符串模拟)
- HDU 5455 Fang Fang(字符串模拟)
- HDU 4119 Isabella's Message(模拟)
- HDU_4788_Hard Disk Drive(打表)(13成都现场H题)
- HDU 4054 Hexadecimal View【模拟】【字符串处理】
- HDU 1483 Automatic Correction of Misspellings (字符串大模拟)
- hdu 4119 Isabella's Message(模拟+字典树)
- HDU 4821 String (2013长春现场赛I题) 字符串Hash
- HDU - 4119 Isabella's Message (字符串+模拟)
- hdu 4119 Isabella's Message ( 模拟 )
- HDU 5611 Baby Ming and phone number(字符串模拟)
- HDU - 4841: 圆桌问题(vector模拟、字符串模拟)
- HDU 4787 GRE Words Revenge 分块式在线AC自动机 2013年成都现场赛G题