I used both of JAVA and C++ in this contest.
Start and solve 250-score problem with JAVA. My source code is drag! I'm not good at JAVA and C++, so I write code very slow! Solve with score 176.96.
Next, I solve 500-score problem with C++. I enjoy this problem, however, system test not passed. Out of contest, I resolve this, I get system test passed. The source in this article is correct.
I explain my algorithm of 500-score(=div.1 250-score) problem.
We can get minute from hourHand. HourHand%30*2 means the time's minute. Then, we can get minute-hand degree from the mark means 12(=0). The differ of hourHand and minuteHand is added to mm*6. We can get hour!
Problems are here.
Score:176.96,Rank:694/1093,Rate:866->823.
I'm bad score recently. I need writing many C++/JAVA source code!
[Level-one (JAVA)]
public class FortunateNumbers{
public static int getFortunate(int[] a, int[] b, int[] c){
int sum=0;
int[][][] logs=new int[a.length][b.length][c.length];
for(int i=0;i<a.length;i++){
for(int j=0;j<b.length;j++){
for(int k=0;k<c.length;k++){
int tmp=a[i]+b[j]+c[k];
if(isFortunate(tmp)==1) logs[i][j][k]=tmp;
else logs[i][j][k]=0;
}
}
}
for(int i=0;i<a.length;i++){
for(int j=0;j<b.length;j++){
for(int k=0;k<c.length;k++){
if(logs[i][j][k]==0) continue;
for(int p=0;p<a.length;p++){
for(int q=0;q<b.length;q++){
for(int r=0;r<c.length;r++){
if(i==p&&j==q&&k==r) continue;
if(logs[i][j][k]==logs[p][q][r]) logs[p][q][r]=0;
}
}
}
sum++;
}
}
}
return sum;
}
public static int isFortunate(int n){
while(n>0){
if(n%10!=5 && n%10!=8) return 0;
n/=10;
}
return 1;
}
}
[Level-two (C++)]
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
using namespace std;
class RotatedClock{
public:
string getEarliest(int hourHand, int minuteHand){
int hh=-1,mm=hourHand%30*2;
int mdeg=mm*6;
int dif=hourHand-minuteHand;
if(dif<0) dif+=360;
int hdeg=(mdeg+dif)%360;
if(hdeg%30*2==mm) hh=hdeg/30;
char str[10];
if(hh>=0 && mm>=0){
sprintf(str,"%02d:%02d",hh,mm);
return string(str);
}else return "";
}
};
0 件のコメント:
コメントを投稿