SRM 575 250 DIV2
2013-06-28 23:14
363 查看
菜鸟的代码:
大神的代码:
分析:
算法:
对比:
1.方法差别不大。
总结:
出于能少点时间就少点的考虑,可以把sequence.length取出来,免得多做n^2次操作。
import java.util.*; import java.util.regex.*; import java.text.*; import java.math.*; public class TheSwapsDivTwo { public int find(int[] sequence) { int i,j,count; boolean tag=false; count=0; for(i=0;i<sequence.length;i++){ for(j=i+1;j<sequence.length;j++){ if(sequence[i]!=sequence[j]) count++; else tag=true; } } if(tag) count++; return count; } } //Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!
大神的代码:
public class TheSwapsDivTwo { public int find(int[] sequence) { int n = sequence.length; int c =0; int have =0; for(int i =0 ; i < n;i++) for(int j = i+1;j < n;j++) if(sequence[i] != sequence[j])c++; else have++; have = Math.min(have, 1); c+=have; return c; } } // Powered by FileEdit // Powered by moj 4.17 [modified TZTester] // Powered by CodeProcessor
分析:
算法:
对比:
1.方法差别不大。
总结:
出于能少点时间就少点的考虑,可以把sequence.length取出来,免得多做n^2次操作。
相关文章推荐
- 【topcoder SRM 702 DIV 2 250】TestTaking
- TopCoder 250 points 12-SRM 149 DIV 2 103.92/250 41.57%
- SRM 578 250 DIV2
- SRM 670 DIV 2 Cdgame 250-point
- SRM 576 250 DIV2
- TopCoder 250 points 28-SRM 157 DIV 2 185.60/250 74.24%
- tc-SRM-626-DIV1-250
- Topcoder SRM 661 (Div.1) 250 MissingLCM - 数论
- TopCoder SRM 612 DIV1 250 EmoticonsDiv1
- TopCoder 250 points 17-SRM 152 DIV 1 106.51/250 42.60%
- SRM 577 250 DIV2
- SRM 544 DIV 2 250
- SRM 594 DIV1 250
- TopCoder算法竞赛题1:SRM 144 DIV 2, 250-point
- TopCoder算法竞赛题5:SRM 149 DIV 2, 250-point
- topcoder SRM 548 DIV2 250
- TopCoder 250 points 18-SRM 152 DIV 2 167.05/250 66.82%
- Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索
- TopCoder算法竞赛题2:SRM 146 DIV 2, 250-point
- TopCoder算法竞赛题6:SRM 150 DIV 2, 250-point