夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

Div.1Easy猫

MagicalSource

やるだけ

class MagicalSource {
public:
  long long calculate( long long x ) {
    ll res = x;
	ll n = 0;
	for (int i=0; i<=12; i++) {
		n += (ll)pow(10, (double)i);
		if (x % n == 0) {
			res = x / n;
		}
	}
    return res;
  }
};

ColorfulRabbits

やるだけ

class ColorfulRabbits {
public:
  int getMinimum( vector <int> replies ) {
    int res = 0;
	sort(replies.begin(), replies.end());
	for (int i=0; i<replies.size(); i++) {
		res += replies[i] + 1;
		int j;
		for (j=i+1; j<i+1+replies[i] && j<replies.size(); j++)
		   if (replies[i] != replies[j]) break;
		i = j - 1;
	}	
    return res;
  }
};

IsmorphicWords

残念ながら通したかどうかの記憶がございませんorz

struct mat {
	char c, m;
};

class IsomorphicWords {
public:
	mat search(vector<mat> w, mat x) {
		for (int i=0; i<w.size(); i++) {
			if (w[i].c==x.c) return w[i];
			else if (w[i].m==x.m) return w[i];
		}
		mat ng;
		ng.c = '0';
		ng.m = '0';
		return ng;
	}
  int countPairs( vector <string> words ) {
    int result = 0;
	int len = words[0].length();
	for (int i=0; i<words.size()-1; i++) {
		for (int j=i+1; j<words.size(); j++) {
			vector<mat> ism;
			bool flag = true;
			for (int k=0; k<len; k++) {
				mat x;
				x.c = words[i][k];
				x.m = words[j][k];
				mat tmp = search(ism, x);
				if (tmp.c=='0') {
					ism.push_back(x);
				} else if (x.c!=tmp.c||x.m!=tmp.m) {
					flag = false;
					break;
				}
			}
			if (flag) {
			//	cout << words[i] << " " << words[j] << endl;
				result++;
			}
		}
	}
    return result;
  }
};

IsHomomorphism

読解ゲー

class IsHomomorphism {
public:
  vector <string> numBad( vector <string> source, vector <string> target, vector <int> mapping ) {
    vector <string> result;
	int len = source[0].length(), sz = source.size();
	for (int i=0; i<sz; i++) {
		for (int j=0; j<len; j++) {
			if (mapping[source[i][j]-'0']+'0' != target[mapping[i]][mapping[j]]) {
				char str[32];
				sprintf(str,"(%d,%d)",i,j);
				result.push_back((string)str);
			}
		}
	}
	sort(result.begin(), result.end());
    return result;
  }
};
広告を非表示にする