TopCoder——SRM 516 DIV 2

来源:互联网 发布:情热传说游戏结局 知乎 编辑:程序博客网 时间:2024/05/16 18:36

这一场比赛可以看做是模拟题专练,基本上每一道题都是可以用最朴素的方法水掉,但是需要把握细节性的处理。

很不幸,1000分挂掉了,尽管当时Room里只有我一人交了1000分,但我知道我没有写对,不过还好,好久没做TCO之后,这次 Rating 增加了95,Rating依旧很低。


Score250

#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<vector>#include<string>#include<queue>#include<list>#include<set>#include<iostream>#include<algorithm>using namespace std;template<class T> T cAbs(T x) { if(x < 0) return -x; return x; }class NetworkXZeroOne{public:string reconstruct(string message) {if( (int)message.length() == 1 ) return message;int pos = -1;for(int i = 0; i < (int)message.length(); ++i) {if( message[i] != '?' ) {pos = i;break;}}if( pos == -1 ) return message;int L = pos - 1, R = pos + 1;while( L >= 0 || R < (int)message.length() ) {if( L >= 0 && message[L] == '?') {if( message[L + 1] == 'o' ) message[L] = 'x';else message[L] = 'o';}if( R < (int)message.length() && message[R] == '?' ) {if( message[R - 1] == 'o' ) message[R] = 'x';else message[R] = 'o';}--L, ++R;} return message;}};


Score500

#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<vector>#include<string>#include<queue>#include<list>#include<set>#include<iostream>#include<algorithm>using namespace std;template<class T> T cAbs(T x) { if(x < 0) return -x; return x; }class NetworkXOneTimePad{public:string calc_Key(string a, string b) {string c = "";for(int i = 0; i < (int)a.length(); ++i) {if( a[i] == b[i] ) c += '0';else c += '1';}return c;}int crack(vector <string> plaintexts, vector <string> ciphertexts) {int ans = 0;int nP = (int)plaintexts.size(); int nC = (int)ciphertexts.size();for(int j = 0; j < nP; ++j) {string key = calc_Key(ciphertexts[0], plaintexts[j]);int tot = 0;for(int r = 0; r < nC; ++r) {string tmp = calc_Key(key, ciphertexts[r]);for(int s = 0; s < nP; ++s) {if( tmp ==  plaintexts[s]) {++tot;break;}}}if( tot == nC ) ++ans;}return ans;}};


Score1000

#include<cstring>#include<cstdio>#include<string>#include<vector>#include<map>#include<iostream>#include<algorithm>using namespace std;class NetworkXMessageRecovery{public:string recover(vector <string> msg) {map<char, int> g; g.clear();for(int i = 'A'; i <= 'Z'; ++i) g[i] = i  - 'A';for(int i = 'a'; i <= 'z'; ++i) g[i] = i - 'a' + 26;map<int, char> _g; _g.clear();for(int i = 0; i < 26; ++i) _g[i] = i + 'A';for(int i = 26; i < 52; ++i) _g[i] = i - 26 + 'a';bool sgn[60]; memset(sgn, 0, sizeof(sgn));for(int i = 0; i < (int)msg.size(); ++i) {for(int j = 0; j < msg[i].length(); ++j) {sgn[ g[ msg[i][j] ] ] = 1;}}bool edg[60][60];memset(edg, 0, sizeof(edg));for(int i = 0; i < (int)msg.size(); ++i)for(int j = 0; j + 1 < (int)msg[i].length(); ++j)edg[ g[msg[i][j]] ][ g[msg[i][j + 1]] ] = 1;for(int k = 0; k < 52; ++k) for(int i = 0; i < 52; ++i)for(int j = 0; j < 52; ++j) if( edg[i][k] && edg[k][j] ) edg[i][j] = 1;string ans = "";for(int i = 0; i < 52; ++i) {for(int j = 0; j < 52; ++j) {if( !sgn[j] ) continue;int cnt = 0;for(int k = 0; k < 52; ++k) cnt += edg[k][j];if( cnt == 0 ) {ans += _g[j];for(int k = 0; k < 52; ++k) edg[k][j] = edg[j][k] = 0;sgn[j] = 0; break;}}}return ans;}};

// NOTEThe original message is a string consisting of distinct letters.


原创粉丝点击