class CyclesInPermutations {
public:
int maxCycle(vector <int> b) {
int r = 0;
for(int i=0; i<b.size(); ++i){
--b[i];
}
for(int i=0; i<b.size(); ++i){
int cnt = 1;
for(int j=b[i]; j != b[j] && i != j; j = b[j])++cnt;
r = max(r, cnt);
}
return r;
}
};
500class PrefixFreeSets {
public:
int maxElements(vector <string> w) {
sort(w.begin(), w.end());
for(int i=0; i+1<w.size(); ++i){
if(w[i] == w[i+1])w.erase(w.begin() + i-- + 1);
}
const int size = w.size();
bool outgo[size];
fill(outgo, outgo + size, false);
for(int i=0; i<w.size(); ++i){
for(int j=0; j<w.size(); ++j){
if(i == j)continue;
if(w[i].size() > w[j].size())continue;
bool tmp = w[i] == w[j].substr(0, w[i].size());
outgo[i] = outgo[i] || tmp;
}
}
return count(outgo, outgo + size, false);
}
};
1000なんかよく分からない。
0 件のコメント :
コメントを投稿