## Posts

Showing posts from December, 2014

### Topcoder SRM 643 div 2 250 Problem

my approch is
- find H and if there is H find right and find up

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45package srm643;publicclassTheKingsArmyDiv2{publicstaticvoidmain(String args[]){ String[] temp ={"SSSSS","SSHHS","SSSSS"}; TheKingsArmyDiv2 army =new TheKingsArmyDiv2(); System.out.println(army.getNumber(temp));}publicintgetNumber(String[] state){int len = state.length;int count =0;for(int i=0; i<len; i++){char[] emotions = state[i].toCharArray();int elen = emotions.length;for(int j=0; j<elen; j++){if(emotions[j]=='H'){ count++;if(j+1< elen && emotions[j+1]=='H'){return0;}if(i+1< len && state[i+1].charAt(j)=='H'){return0;}}}}if(count >0){return1;}else{return2;}}}

### Topcoder SRM 640 div2 250point

this question is very easy!!

start and ribons

if left and right is different counting ++

my code is below~

problem
http://community.topcoder.com/stat?c=problem_statement&pm=13556

1 2 3 4 5 6 7 8 9 10 11 12 13publicclassChristmasTreeDecorationDiv2{publicintsolve(int[] col,int[] x,int[] y){int len = x.length;int cnt =0;for(int i=0; i<len; i++){if(col[x[i]-1]!= col[y[i]-1]){ cnt++;}}return cnt;}}

### SRM 641 div 2 500

this is my source ..

point in triangle is somehow difficult to understand

find the algorithm point in triangle
and when calling pointInTriangle
point.set method called many times.

so later, I have to do refactoring my code to speed up

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61package srm641;publicclassTrianglesContainOriginEasy{publicintcount(int[] x,int[] y){int len = x.length;int count =0; Point v1 =new Point(); Point v2 =new Point(); Point v3 =new Point();for(int i=0; i<len; i++){for(int j=i+1; j<len; j++){for(int k=j+1; k<len; k++){if(pointInTriangle(new Point(0,0), v1.set(x[i], y[i]), v2.set(x[j], y[j]), v3.set(x[k], y[k]))){ count++;}}}}return count;}booleanpointInTriangle(Point pt, Point v1, Point v2, Point v3){ Boolean b1, b2, b3; b1 = sign(pt, v1, v2)<0; b2 = sign(pt, v2, v3)<0; b3 = sign(pt, v3, v1)&…

### Topcoder SRM 641 250point

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20publicclassBuyingTshirts{publicintmeet(int T,int[] Q,int[] P){int len = Q.length;int count =0;int sum =0;int sum2 =0;for(int i=0; i<len; i++){ sum += Q[i]; sum2 += P[i];if(sum-T >=0|| sum2 -T >0){ count++;} sum = sum - T; sum2 = sum2 - T ;}return count;}}

### Topcoder SRM 642 div2

This is my third time in attending topcoder

and I got 815 grad T_T.

I think my skill and score will be higher than now if I continuously attend and study

http://community.topcoder.com/stat?c=problem_statement&pm=13553&rd=16085&rm=324592&cr=23054155

explanation : first I tried to solve this problem Brute-force Search

It mean all posiible I would search

this is may take O(n) if str length is higer time.

but I tried if str.length is cardinal number ,  find only center and one before, one after

and if str.length . even number search 3point, half and before of half, after of half

ex ) cardinal number : 129298481 : 1292 + 98481,  12929 + 8481

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26publicclassForgetfulAddition{publicintminNumber(String str){int len= str.length();int start = len /2;int minNumber = Integer.MAX_VALUE;if(len %2==1){// 홀수int sum = Integer.parseInt(str.substring(0, start))+ Integer.parseInt(str.substring(start, len)); minNum…

### Math sqrt in java

sqrt is square root value

Math.sqrt(52) :  7.211102550927978
Math.sqrt(4) : 2
Math.sqrt(9) : 3

Math.floor(1001.56) :  1001
Math.ceil(1001.56) : 1002

### SRM 441 div 1 1000

Recently I solve the problem that was already compteted. and I found out that I'm not skillfull at understanding english. I want to understand problem written in english but it is very difficult to get the point of problem,
this is somehow eaiser than others because it show pictures and sample. I try to solve this problem
next time I hope write answer aticle of this question ~!!!

TopCoder problem "PaperAndPaint" used in SRM 441 (Division I Level Three)

Problem StatementOnise likes to play with paper and paint. He has a piece of paper with dimensions width x height. He performs K operations, one for each i between 0 and K-1, inclusive. Each operation consists of the following steps:Fold the paper along the line x = xfold[i] (the left side of the paper is folded over the right side).Divide the paper vertically into cnt[i]+1 equal sections. Then, cnt[i] times, take the topmost section and fold it over the section below it.Paint a rectangle with the lower-left corner at (