## Sunday, December 28, 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 45``` ```package srm643; public class TheKingsArmyDiv2 { public static void main(String args[]){ String[] temp = {"SSSSS", "SSHHS", "SSSSS"}; TheKingsArmyDiv2 army = new TheKingsArmyDiv2(); System.out.println(army.getNumber(temp)); } public int getNumber(String[] state){ int len = state.length; int count =0; for(int i=0; i 0){ return 1; }else{ return 2; } } } ```

## Tuesday, December 23, 2014

### 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 13``` ```public class ChristmasTreeDecorationDiv2 { public int solve(int[] col, int[] x, int[] y){ int len = x.length; int cnt =0; for(int i=0; i

## Monday, December 22, 2014

### 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 61``` ```package srm641; public class TrianglesContainOriginEasy { public int count(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

## Sunday, December 21, 2014

### Topcoder SRM 641 250point

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

## Wednesday, December 17, 2014

### 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 26``` ```public class ForgetfulAddition { public int minNumber(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)); minNumber = Math.min(sum, minNumber); sum = Integer.parseInt(str.substring(0, start+1)) + Integer.parseInt(str.substring(start+1, len)); minNumber = Math.min(sum, minNumber); }else{ // 짝수 int sum = Integer.parseInt(str.substring(0, start)) + Integer.parseInt(str.substring(start, len)); minNumber = Math.min(sum, minNumber); if(len >2){ sum = Integer.parseInt(str.substring(0, start+1)) + Integer.parseInt(str.substring(start+1, len)); minNumber = Math.min(sum, minNumber); sum = Integer.parseInt(str.substring(0, start-1)) + Integer.parseInt(str.substring(start-1, len)); minNumber = Math.min(sum, minNumber); } } return minNumber; } } ```

 ``` 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``` ```public class LightSwitchingPuzzle { public int minFlips(String str){ char[] array = str.toCharArray(); int count =0; for(int i=0; i

## Tuesday, December 16, 2014

### 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

## Wednesday, December 3, 2014

### 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 ~!!!

### Problem Statement

Onise 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:
1. Fold the paper along the line x = xfold[i] (the left side of the paper is folded over the right side).
2. 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.
3. Paint a rectangle with the lower-left corner at (x1[i], y1[i]) and the upper-right corner at (x2[i], y2[i]). Note that (0, 0) is now the lower-left corner of the paper in its current folded state, not its original state. The paint will seep through all the layers of the folded paper. See the image below for clarification.
4. Unfold the paper.
For example, let's say Onise has a piece of paper that is 5 x 6. He performs one operation where xfold is 2, cnt is 2, and the coordinates of the painted rectangle's corners are (1, 1) and (3, 2). The following will happen (note that the paper starts out blue in the images and gets painted white):

You are given ints width and height, and int[]s xfoldcntx1y1x2 and y2, each containing exactly K elements. Return the total area of of the paper that is not covered in paint after Onise is done.

### Definition

 Class: PaperAndPaint Method: computeArea Parameters: int, int, int[], int[], int[], int[], int[], int[] Returns: long Method signature: long computeArea(int width, int height, int[] xfold, int[] cnt, int[] x1, int[] y1, int[] x2, int[] y2) (be sure your method is public)

### Constraints

-width and height will be between 1 and 10^9, inclusive.
-xfoldcntx1y1x2 and y2 will all contain the same number of elements, between 1 and 50, inclusive.
-Every element of xfold will be between 0 and width, inclusive.
-Every element of cnt will be between 0 and 1000, inclusive.
-For every i, cnt[i]+1 will be a divisor of height.
-For every i, 0 <= x1[i] < x2[i] <= max(xfold[i], width-xfold[i]) and 0 <= y1[i] < y2[i] <= height/(cnt[i]+1).

### Examples

0)

 `5` `6` `{2}` `{2}` `{1}` `{1}` `{3}` `{2}`
`Returns: 21`
 The example from the problem statement.
1)

 `2` `4` `{0, 0}` `{1, 0}` `{0, 0}` `{1, 1}` `{2, 1}` `{2, 4}`
`Returns: 3`
 Onise will get the following result:
2)

 `6` `6` `{2, 5}` `{1, 2}` `{1, 2}` `{2, 0}` `{3, 4}` `{3, 2}`
`Returns: 18`
3)

 `21` `30` `{3,21,7,11,13}` `{4,14,9,5,4}` `{4,0,2,5,9}` `{2,0,1,2,3}` `{7,19,6,11,12}` `{5,2,2,4,5}`
`Returns: 27`
4)

 `30` `42` `{16, 24, 25, 21, 4}` `{5, 1, 6, 13, 20}` `{3, 1, 5, 8, 9}` `{0, 1, 0, 0, 1}` `{14, 22, 12, 18, 13}` `{2, 15, 1, 1, 2}`
`Returns: 336`
5)

 `26` `60` `{17, 17, 24, 4, 21}` `{4, 1, 11, 0, 2}` `{9, 1, 20, 18, 7}` `{1, 3, 0, 45, 12}` `{13, 4, 23, 19, 13}` `{3, 14, 1, 46, 14}`
`Returns: 1319`
6)

 `17` `3` `{17, 2, 10, 2, 10, 13}` `{2, 0, 0, 2, 0, 0}` `{7, 6, 4, 11, 0, 5}` `{0, 0, 1, 0, 1, 1}` `{12, 10, 6, 12, 4, 12}` `{1, 3, 2, 1, 2, 2}`
`Returns: 20`

`reference by Topcorder`

## Tuesday, November 25, 2014

### SRM 635 div 2 500

This is somehow easy comparing to other 500 point problem.

this is about a square root.

public long getTime(long time){
long number  = (long)Math.floor(Math.sqrt(time));
for(long i=number; i>0; i--){
if((i * i) + i <=  time){
return i;
}
}
return 0l;
}
}

### SRM 635 DIV 2 250 problem in topcoder

This is somehow easy comparing to other 500 point problem.

this is about a square root.

public long getTime(long time){
long number  = (long)Math.floor(Math.sqrt(time));
for(long i=number; i>0; i--){
if((i * i) + i <=  time){
return i;
}
}
return 0l;
}
}

## Thursday, November 20, 2014

### dp to px in Anroid

http://labs.rampinteractive.co.uk/android_dp_px_calculator/

### 하늘을 날다~ 쿼드콥터 (1)

갑자기 하늘을 날아보고 싶다는 생각이 들었다. 과거 라이트형제은 날아보고 싶다는 생각에 비행기를 만들었을것이다. 나는 아두노이로 쿼드콥터를 만들어봐야겠다. 아두노이도 없고 부품도 없고 아무것도 없다. 부품도 사고 이것저것 사야할것 같다. 오늘부터 쿼드콥터를 만드는거 도전한다. 제발 만들다가 그만두지 말기를...

## Wednesday, November 19, 2014

### CustomComparator in java

```import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class SecondArray {
public static ArrayList list = new ArrayList();
public static void main(String args[]){
CustomString cs= new CustomString("123744444");
cs= new CustomString("421212345");
cs= new CustomString("758312948");
cs= new CustomString("134129302");
cs= new CustomString("123755555");

System.out.println(list);

Collections.sort(list, new CustomComparator());

System.out.println(list);

}

}
class CustomString {

String [] devidedValues = new String[2];

CustomString(String value){
devidedValues[0] = value.substring(0, 4);
devidedValues[1] = value.substring(4, value.length());

}

/**
* @return the devidedValues
*/
public String[] getDevidedValues() {
return devidedValues;
}

/**
* @param devidedValues the devidedValues to set
*/
public void setDevidedValues(String[] devidedValues) {
this.devidedValues = devidedValues;
}

* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return devidedValues[0] + devidedValues[1];
}

}

class CustomComparator implements Comparator {

@Override
public int compare(CustomString arg0, CustomString arg1) {
String[] first = arg0.getDevidedValues();
String[] second = arg1.getDevidedValues();

int firstCompareVal = first[0].compareTo(second[0]) ;

if(first[0].compareTo(second[0]) == 0){
return first[1].compareTo(second[1]) * -1;
}else{
return firstCompareVal;
}
}

}

```

## Tuesday, November 18, 2014

### Bucket List ~ Success and TODO

Success

1. Getting the score over 900point in TOEIC
2. Going to america and Lasvegas~!
3. For honemoon, having good time in maldives

TODO

1. going to Europe .
2. Making bucket list application.
3. building a library

## Monday, November 17, 2014

### The difference between find('li:first') and find('li :fist') in jquery

Today I knew big difference between find \$('ul').find('li:first') and find('li :first')

find('li:first') this will Return first li tag

find('li :fist') this will Return firlst tag of first li tag

## Wednesday, November 12, 2014

In these days, people want to spend their more time with mobile than Pc.
Pc resolution is very high. so it is very readable in short time.
Mobile resolution size is smaller than PC. so paradigm of design is simple.
It seems that people like if something is so simple.
what I want to say is multi reply system is not many used in these days.

but I have to know how to think and make table for multi reply in board.

one way :

column : id
subcolumn : parent id, title

Id is unique value
and parent id indicate Id
and more and more

this architecture can make limitless depth replies.

query can express by using oracle grammer connect by

In my opinion

disadvantage : many article, connect by spend much time to query

the other recommendable way :

column : id
subcolumn : order_id, title, root_comment_id, depth

I want to show you ex)..

id                                   title,        depth  depth_order     root_comment_id
00000000001               root title            0     1                   00000000001
00000000002                title                1       1                   00000000001
00000000003                title               2        1                   00000000001
00000000004                title               2        2                   00000000001
00000000005                root title         0        1                  00000000002

select * from table order by root_comment_id desc, depth asc, depth_order desc

Anyway there are lots of way you can make.

what kind of way to choose is up to you~!

### angular infinite \$digest loop error solution

I used ui.router and someday i found out
error console show me this error

```10 \$digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: \$locationWatch; newVal: 32; oldVal: 31"],["fn: \$locationWatch; newVal: 33; oldVal: 32"],["fn: \$locationWatch; newVal: 34; oldVal: 33"],["fn: \$locationWatch; newVal: 35; oldVal: 34"],["fn: \$locationWatch; newVal: 36; oldVal: 35"]]```

and I debug for whole day and gave up.

after debugging, I seached on internet and many people face with this problem.

and I finally fix the error

Before if I used location.href='#/xxxxxx'
and changed is \$location.path(realpath);

## Tuesday, November 11, 2014

### mobile Html page box-sizing

if you want to muliline ellipsis effect

1. overflowhidden;
2. text-overflowellipsis;
3. display-webkit-box;
4. -webkit-line-clamp3;
5. -webkit-box-orientvertical;
6. word-wrapbreak-word;

this would be a solution for you

## Thursday, November 6, 2014

### Iscroll 4.2.5 in iput, textarea, select focus issue

I used I scroll and It was very good.

and I can't complete mobile web project because in Iscroll div I can't touch and input, textarea, select never clicked.

I find some article that somebody shared..

and all the things that I saw internet was not working.
and tried to find more and more

this is my solution

onBeforeScrollStart: function (e) {
var nodeType = e.explicitOriginalTarget ? e.explicitOriginalTarget.nodeName.toLowerCase():(e.target ? e.target.nodeName.toLowerCase():'');
if(nodeType !='select' && nodeType !='option' && nodeType !='input' && nodeType!='textarea') e.preventDefault();
},

### Iscroll 4.2.5 scroll has some how issue during scrolling

Today I tried to using I Scroll 4.2.5 for pullup to morelist and pulldown to refresh
But I was in trouble because if you scroll when it is already scrolling
page will refresh and you can see the position of scroll will be strange..

anyway I had to fix it

What i Changed code is

_start : .....

if (x != that.x || y != that.y) {
/**
* hanwha 주석 2014-11-06 더블 스크롤시 화면이 튕기는 현상 제거
*
* david
*/
//if (that.options.useTransition) that._unbind(TRNEND_EV);
//else cancelFrame(that.aniTime);
// that.steps = [];
// that._pos(x, y);
if (that.options.onScrollEnd) that.options.onScrollEnd.call(that);
}

this source is called when you are willing to scroll during scrolling.
in other word. double scrolling..

I hope to remever these things so

If you guys are faced with this problem.
remove that source.

## Thursday, October 23, 2014

I wanted to try get ajax data from other site..
and Chorme and WebBrowser told me that cross domain security so I can't access
this url...
there is good solution when you develope different site and test it

changed apache conf.htttp ~!!!

ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
SetEnv proxy-initial-not-pooled 1

</Proxy>

ProxyPass /neo http://192.168.123.171:8080/neo
ProxyPassReverse /neo http://192.168.123.171:8080/neo

## Wednesday, October 22, 2014

### Jquery extend function

This is somehow good when extend data and overwrite

```

`var object1 = {`

`  apple: 0,`

`  banana: { weight: 52, price: 100 },`

`  cherry: 97`

`};`

`var object2 = {`

`  banana: { price: 200 },`

`  durian: 100`

`};`

` `

`// Merge object2 into object1`

`\$.extend( object1, object2 );````
````object1 data````
````{"apple":0,"banana":{"price":200},"cherry":97,"durian":100}`

```