您的位置:首页 > 其它

智能手机屏幕解锁图案研究

2012-11-27 18:21 459 查看
1 2 3

4 5 6

7 8 9

智能手机屏幕上的9个点依次记为1~9

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Test
{
class Program
{
static private int[] One = new int[] { 2, 4, 5, 6, 8 };
static private int[] Two = new int[] { 1, 3, 4, 5, 6, 7, 9 };
static private int[] Three = new int[] { 2, 4, 5, 6, 8 };
static private int[] Four = new int[] { 1, 2, 3, 5, 7, 8, 9 };
static private int[] Five = new int[] { 1, 2, 3, 4, 6, 7, 8, 9 };
static private int[] Six = new int[] { 1, 2, 3, 5, 7, 8, 9 };
static private int[] Seven = new int[] { 2, 4, 5, 6, 8 };
static private int[] Eight = new int[] { 1, 3, 4, 5, 6, 7, 9 };
static private int[] Nine = new int[] { 2, 4, 5, 6, 8 };

static private int[] Count = new int[9];

static void Main(string[] args)
{
int[] buf = new int[9];
int sum = 0;
for (int i = 1; i <= 9; ++i) PushNum(buf, 0, i);
for (int i = 3; i < 9; ++i)
{
sum += Count[i];
Console.WriteLine("{0}={1}", i + 1, Count[i]);
}
Console.WriteLine("Sum:{0}", sum);
Console.ReadLine();
}

static void PushNum(int[] buf, int index, int num)
{
if (index >= buf.Length) return;
for (int i = 0; i < index; ++i) if (buf[i] == num) return;
buf[index] = num;
if (index >= 3)
{
Count[index] += 1;
for (int i = 0; i < index; ++i) Console.Write("{0} ", buf[i]);
Console.WriteLine();
}
foreach (int v in GetNeighbor(num)) PushNum(buf, index + 1, v);
}

static int[] GetNeighbor(int value)
{
switch (value)
{
case 1: return One;
case 2: return Two;
case 3: return Three;
case 4: return Four;
case 5: return Five;
case 6: return Six;
case 7: return Seven;
case 8: return Eight;
case 9: return Nine;
default: return null;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: