2011/10/15

Topcoder SRM 521 (Div.2) Report

I  was late about 10 minutes this SRM, because I have a school experiment.


Easy: It's easy for me. I solved it with 208.13.

Medium: I've solve similar problem at UTPC2011. I often check my sources parenthesis, and I can use the algorithm. Score=462.62.

Challenge: I have a success and a failure. My test case is ")(" on Medium. I don't challenge Easy or Hard.

Score=695.75,Rank(Div.2)=102/1273,Rate=907->1004.

[Easy(C++)]

#include<iostream>
#include<string>
using namespace std;

class RedAndGreen{
public:
int minPaints(string row){
char *data=(char *)row.c_str();
int l=strlen(data);
int mins=l;
int i,j,tmp;

for(i=0;i<l;i++){
tmp=0;
for(j=0;j<i;j++) if(data[j]=='G') tmp++;
for(j=i+1;j<l;j++) if(data[j]=='R') tmp++;
if(mins>tmp) mins=tmp;
}
return mins;
}
};


[Medium(C++)]

#include<iostream>
#include<string>


using namespace std;


class MissingParentheses{
public:
int countCorrections(string par){
char *test=(char *)par.c_str();
int ret=0,count=0;
for(int i=0;i<strlen(test);i++){
if(test[i]=='(') count++;
else if(test[i]==')'){
if(count<=0) ret++;
else count--;
}
}
ret+=count;
return ret;
}
};

0 件のコメント:

コメントを投稿