23
December
[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
class EmoticonsDiv2 {
public:
int printSmiles(int smiles) {
int ans;
ans = dfs(1,2,smiles);
return ans+2;
}
int dfs(int clip,int now,int goal){
int ret = INF;
if(now == goal)return 0;
if(now > goal)return INF;
for(int i=0;i<2;i++){
if(i==1)ret = min(ret,dfs(clip,now+clip,goal)+1);
if(i==0)ret = min(ret,dfs(now,now+now,goal)+2);
}
return ret;
}
};
#include<iostream>
#include<string>
using namespace std;
class AlienAndPassword{
public:
int getNumber(string S){
int cnt=0;
for(int i=1;i<S.size();i++){
if(S[i-1] != S[i]) cnt++;
}
return cnt+1;
}
};
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
class AlienAndGame{
public:
int getNumber(vector<string> board){
int MAX;
int ans=1;
MAX = min(board[0].size(),board.size());
for(int length=1;length<=MAX;length++){
for(int i=0;i<board.size()-length+1;i++){
for(int j=0;j<board[0].size()-length+1;j++){
int fuga=0;
for(int k=0;k<length;k++){
int hoge=0;
for(int l=0;l<length-1;l++){
if(board[i+k][j+l] == board[i+k][j+l+1])
hoge++;
}
if(hoge+1==length)fuga++;
}
if(fuga==length)ans=length;
}
}}
return ans*ans;
}
};
#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 PowerOfThreeEasy {
public: string ableToGet(int x, int y) {
while(1){
if((x%3==0&&y%3==1)||(x%3==1&&y%3==0)){
x/=3;
y/=3;
}
else{
if(x==0&&y==0)return "Possible";
return "Impossible";
}
}
}
};
#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;
}
};