帽子
shaojwa · 共 6 篇文章
Sort<T>()小问题
Comparison 是一个delegate 几个常用的例子: <1> class Program { static void Main(string[] args) { int[] ia = new int[] { 1, 5, 2, 4, 3, 7, 6 }; Array.Sort(ia); foreach (int i in ia) Console.WriteLine(i); } } <2> class Program { static void Main(string[] args) { List<int> il = new List<int>(){1,3,4,2,6,7,5}; il…
2010-01-23 11:49 · 评论(0)
字串是否为某个类型的数值
有时候需要判断一个字串是不是一个int/double/float. C#没有直接的方法实现,可以自己用如下几个方法实现: <1>try-catch class Program { public static bool IsInt32(string s) { try { int n = Int32.Parse(s); return true; } catch { return false; } } static void Main(string[] args) { string str = "123456789101112"; Console.WriteLine("{0}!", str = (…
2010-01-23 11:48 · 评论(0)
和素数相关的两个小问题
1.判断一个数是不是素数,效率还行的一段小代码 #include <stdio.h> #include <math.h> int IsPrime(int x) { if (x == 1)return 0; else if (x == 2)return 1; else if (x % 2 == 0) return 0; else { int i,bound = sqrt((double)x) + 1; for( i = 3; i < bound; i += 2) { if (x % i == 0) return 0; } return 1; } } int main() { int n; pr…
2010-01-23 11:47 · 评论(0)
24点游戏的一个小代码
这段代码帮助你判断四个0-9 之间的数能不能通过加减乘除得到24点,要是可以,程序也会显示一种可行的计算方法,这其实是一个枚举,效率不高。 #include <stdio.h> double four[4], three[3]; char steps[3][100]; int judge2(double x, double y) { if (24 == x + y) { sprintf(steps[2],"%lf + %lf = %lf", x, y, x + y); return 24; } if (24 == x - y) { sprintf(steps[2],"%lf - %lf = …
2010-01-23 11:10 · 评论(0)
一段用来求组合数的递归代码
很久以前用来枚举组合数的,当时应该是C(4,11)。 class Program { static void Main(string[] args) { int sum = 0; int[] vs = new int[4]; int[] vars = new int[11]{1,2,3,4,5,6,7,8,9,10,11}; G(0, 0, 4, ref vars, ref vs, ref sum); Console.WriteLine(sum); } static void G(int startIndex, int count, int n, ref int[] vars, ref in…
2010-01-23 11:08 · 评论(0)
SE 中Z3的一点相关内容
Z3 used for Resolving PG Explore到了每一步,应该是都扔到Z3里面去确定到底下一步要做什么 主要是PG,你new了实例情况也算差不多吧 这个我觉得Dev不可能控制这么细节的东西 他不一定非要是PG 他把目前的状态信息扔进Z3 然后Z3返回一个序列 然后他就按照这个序列一个一个地issue action 比如他到了S17 然后Z3返回告诉他,S17后面有 A,B,C 这几个action A,B,C 的顺序是Z3告诉他的 他只管调 说不准哪天Z3返回个B,C,A 不可能有兴趣三天两头去改这个顺序 Z3是通过某个东西来做随机的 就像你Explore一个没有bound的…
2010-01-23 11:06 · 评论(0)