USACO6.3.2 Cryptcowgraph(cryptcow)
2015-02-05 21:00
253 查看
模拟
枚举,先找O再找C最后找W会快很多,转换,判断
这种题需要注意细节上的问题
枚举,先找O再找C最后找W会快很多,转换,判断
这种题需要注意细节上的问题
/* ID:10239512 PROG:cryptcow LANG:C++ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define HashSize 131071 const string dest="Begin the Escape execution at the Break of Dawn"; bool searched[HashSize]; int Hash(const string &str) { long long h=0,g; for(int i=0;i<str.size();i++) { h=(h<<4)+str[i]; g=h & 0xf0000000l; if(g) h^=g>>24; h&=~g; } return h; } bool Impossible(const string &text) { if((text.size()-dest.size())%3) return 1; int i=0,j; while(i<text.size()) { j=i+1; if(text[i]!='C' && text[i]!='O' && text[i]!='W') { while(j<text.size()) { if (text[j]=='C' || text[j]=='O' || text[j]=='W') break; j++; } if (dest.find(text.substr(i,j-i))==string::npos) return 1; } i=j; } return 0; } string Transform(const string &str,int c,int o,int w) { static char temp[100]; int ich=0; for(int i=0;i<c;i++) temp[ich++]=str[i]; for(int i=o+1;i<w;i++) temp[ich++]=str[i]; for(int i=c+1;i<o;i++) temp[ich++]=str[i]; for (int i=w+1;i<str.size();i++) temp[ich++]=str[i]; temp[ich++]=0; return string(temp); } bool IsEncrypted(string text) { int hash=Hash(text)%HashSize; if (searched[hash]) return 0; searched[hash]=1; if(text==dest) return 1; if (Impossible(text)) return 0; for(int o=1; o<text.size()-1; o++) if(text[o]=='O') for(int c=0; c<o; c++) if(text[c]=='C') for(int w=text.size()-1; w>o; w--) if(text[w]=='W') if (IsEncrypted(Transform(text,c,o,w))) return 1; return 0; } int main() { freopen("cryptcow.in","r",stdin); freopen("cryptcow.out","w",stdout); string text; getline(cin,text); if(IsEncrypted(text)) cout<<"1 "<<count(text.begin(),text.end(),'C')<<endl; else cout<<"0 0"<<endl; return 0; }
相关文章推荐
- [USACO4.1.4 Cryptcowgraphy]
- [USACO 6.3.2] Cryptcowgraphy
- USACO 6.3.2 Cryptcowgraphy 剪枝
- usaco6.3.2 Cryptcowgraphy
- USACO 4.1 Cryptcowgraphy(DFS)
- Cryptcowgraphy USACO 4.1(dfs搜索+剪枝)
- USACO4.1.4 Cryptcowgraphy
- usaco4.1.4 Cryptcowgraphy
- usaco 4.1 Cryptcowgraphy 剪枝
- Cryptcowgraphy [USACO]
- usaco 4.1 Cryptcowgraphy
- USACO 6.3 Cryptcowgraphy
- usaco 4.1 Cryptcowgraphy(DFS+hash+剪枝)
- USACO Section 4.1 Cryptcowgraphy - BT的DFS剪枝..
- [BZOJ3887][Usaco2015 Jan]Grass Cownoisseur(tarjan+spfa)
- BZOJ1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
- bzoj1666[Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- 【USACO】The Cow Prom
- USACO 2.1 graph
- BZOJ 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛