Last active
December 16, 2015 15:49
-
-
Save zhangxigithub/5458182 to your computer and use it in GitHub Desktop.
A
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 括号里表示一开始输入几个0 | |
| 0:0(0) | |
| 1:1(1) | |
| 2:2(2) | |
| 3:3(3) | |
| 4:4(4) | |
| 5:5(5) | |
| 6:6(6) | |
| 7:9(3) | |
| 8:12(3) | |
| 9:16(4) | |
| 10:20(4) | |
| 11:25(5) | |
| 12:36(3) | |
| 13:48(3) | |
| 14:64(4) | |
| 15:80(4) | |
| 16:100(5) | |
| 17:144(3) | |
| 18:192(3) | |
| 19:256(4) | |
| 20:320(4) | |
| 21:400(5) | |
| 22:576(3) | |
| 23:768(3) | |
| 24:1024(4) | |
| 25:1280(4) | |
| 26:1600(5) | |
| 2304(3) | |
| 3072(3) | |
| 4096(4) | |
| */ | |
| -(int)keyboard:(int)n | |
| { | |
| int result = [self put:n index:1]; | |
| int tempIndex = n; | |
| for(int j=2;j<=5;j++) | |
| { | |
| int tempResult = [self put:n index:j]; | |
| if(result < tempResult) | |
| { | |
| result = tempResult; | |
| tempIndex = j; | |
| } | |
| } | |
| NSLog(@"%d:%d(%d)",n,result,tempIndex); | |
| return result; | |
| } | |
| -(int)put:(int)n index:(int)index | |
| { | |
| if(n<=6) return n; | |
| int clip = 0; | |
| int count = n; | |
| int result = 0; | |
| result = index; | |
| count -= index; | |
| while (count>0) { | |
| if(count >=5) | |
| { | |
| count -=5; | |
| clip = result; | |
| result *=4; | |
| }else | |
| { | |
| if(count ==4) | |
| { | |
| result*=3; | |
| clip = result; | |
| count -=4; | |
| }else if(count == 3) | |
| { | |
| result*=2; | |
| clip = result; | |
| count -=3; | |
| }else if(count == 2) | |
| { | |
| if(count >0) | |
| { | |
| result += clip*2; | |
| }else | |
| { | |
| result += 2; | |
| } | |
| count -= 2; | |
| }else if(count == 1) | |
| { | |
| if(clip >0) | |
| { | |
| result += clip; | |
| }else | |
| { | |
| result +=1; | |
| } | |
| count -=1; | |
| } | |
| } | |
| } | |
| return result; | |
| } | |
| /* | |
| for(int i =0;i<30;i++) | |
| { | |
| [self keyboard:i]; | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment