2011/09/11

Topcoder SRM 517(Div.2) Report

I had many successful challenge because I notice wrong answer of my source in intermission time.

Easy: I'm not good at JAVA, so I spent many time. Now I think, I should study C++'s vector and string. Then, I'll solve problem shorter time. Get 163.5 points.

Medium: I submitted at points=400.26, however I notice the miss. The miss is next:N=p^k and target=p^2 (p is prime number and k>2 is natural number). So, this source can't pass system test. However, I have three challenge successes and three challenge failures. So, I get 75 points from this problem.

Hard: I think it's greedy, however it's not right. I couldn't solve this.

Score=218.5,Rank(Div.2)=241/1462,Rate=823->900. Returned Green coder after long time...

[Easy (Java)]

public class MonochromaticBoard{
public static int theMin(String[] board){
int[][] state=new int[board.length][board[0].length()];
for(int i=0;i<board.length;i++){
for(int j=0;j<board[i].length();j++){
state[i][j]=board[i].charAt(j)=='B'?1:0;
}
}
int rowb=0,colb=0;
for(int i=0;i<board.length;i++){
int tmp=0;
for(int j=0;j<board[0].length();j++){
tmp+=state[i][j];
}
if(tmp==board[0].length()) rowb++;
}
for(int i=0;i<board[0].length();i++){
int tmp=0;
for(int j=0;j<board.length;j++){
tmp+=state[j][i];
}
if(tmp==board.length) colb++;
}
if(rowb==0 && colb==0) return 0;
if(rowb==board.length && colb==board[0].length()) return Math.min(rowb,colb);
return rowb+colb;
}
}


[Normal (C++,Wrong)]

#include<iostream>

using namespace std;

class CompositeSmash{
public:
string thePossible(int N, int target){
if(target==N) return "Yes";
if(N%target!=0) return "No";
if(prime(target)==1) return "Yes";
int count=0;
for(int i=2;i*i<N;i++) if(N%i==0) count++;
if(count==1) return "Yes";
if(count==0 && target*target==N) return "Yes";
return "No";
}
int prime(int p){
int i;
if(p%2==0) return 0;
for(i=3;i*i<=p;i++) if(p%i==0) return 0;
return 1;
}
};


[Hard (C++,Wrong)]

#include<iostream>
#include<vector>

using namespace std;

class CuttingGrass{
public:
int theMin(vector <int> init, vector <int> grow, int H){
int allgrow;
allgrow=sum(grow);
int count=0;
int nowsum;
nowsum=sum(init);
while(nowsum>H){
count++;
for(int i=0,n=init.size();i<n;i++) init[i]+=grow[i];
int num=maxsuf(init,grow);
nowsum+=allgrow-init[num];
if(allgrow-init[num]>0) return -1;
init[num]=0;
}
return count;

}
int sum(vector <int> vec){
int ret=0;
for(int i=0,n=vec.size();i<n;i++) ret+=vec[i];
return ret;
}
int maxsuf(vector <int> vec,vector <int> growth){
int ret=0;
for(int i=0,n=vec.size();i<n;i++){
if(vec[ret]<vec[i]) ret=i;
if(vec[ret]==vec[i] && growth[ret]<growth[i]) ret=i;
}
return ret;
}
};


0 件のコメント:

コメントを投稿