忍者ブログ
27 April

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

12 January

SRM604 div2 easy

問題文

http://community.topcoder.com/stat?c=problem_statement&pm=12953

空でない文字列がいくつか渡される。
文字列を二分割してそれを入れ替えた時同じものに
なるものをカウントして返せ。

例:"tokyo","kyoto"
tokyo = to + kyo → kyo + to = kyoto
このようなのをカウント。

解法

Constraintsは文字列の数、文字列の長さがそれぞれ50である。
よって全探索でも50^3程度にしかならない。


反省

今回が本番初参戦だった。
開催が遅かったので30分寝過ごしてしまった。
練習の時、早く解くことを意識はしていたものの、時間制限を設けず
やっていたので本番で焦ってしまった。
初チャレンジもよく確認せず突っ込み-25点と
いろいろと惨敗だった。

なんだかんだやっぱり本番は楽しかったのでまた頑張りたい。



#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

class FoxAndWord {

	public: int howManyPairs(vector<string> words) {
		int cnt=0;
		for(int i=0;i<words.size()-1;i++){
			for(int j=i+1;j<words.size();j++){

				if(words[i].size() == words[j].size()){
				for(int k=0;k<words[i].size();k++){
					if(words[i].substr(k+1) + words[i].substr(0,k+1) == words[j]){
						cnt++;
						break;
					}
				}}
			}
		}

		return cnt;
	}

};

PR