33,008
社区成员
发帖
与我相关
我的任务
分享
#include<iostream.h>
#include<string.h>
int a[12];//记录设置好的点数
int b[12];//记录用过的点数
int dfs(int pos,int level)
{
if(level==10)
{
for(int i=0;i<12;i++)
cout<<a[i]<<" ";
cout<<endl;
return 1;
}
int num=0;
int d;
for(int i=2;i<12;i++)
{
d = (pos+i)%12;
if(b[i]==0 && a[d]==0)
{
b[i] = 1;
a[pos] = i;
num+=dfs(d, level+1);
b[i] = 0;
a[pos] = 0;
}
}
return num;
}
int main()
{
memset(a, 0, sizeof(int)*12);
memset(b, 0, sizeof(int)*12);
a[0] = 1;
//a[6] = 12;
cout<<dfs(1,0)<<endl;
return 0;
}
public static List<ulong> clocks()
{
List<ulong> value = new List<ulong>();
clocks(value, 0, 0x7ff, 40, 1 << 6);
return value;
}
private static void clocks(List<ulong> value, ulong currentValue, int freeValue, int shift, int errorValue)
{
for (int nextShift = shift - 4, nextValue = 1, nextFree = freeValue; nextFree != 0; nextValue++, nextFree >>= 1)
{
if ((nextFree & 1) != 0 && (errorValue & (1 << nextValue)) == 0)
{
if (nextShift == 0) value.Add(currentValue | (uint)nextValue);
else clocks(value, currentValue | (((ulong)nextValue) << nextShift), freeValue ^ (1 << (nextValue - 1)), nextShift, (errorValue >> nextValue) | (((errorValue | 1) << (12 - nextValue)) & 0xfff));
}
}
}
public static List<ulong> clocks()
{
List<ulong> value = new List<ulong>();
clocks(value, 0, 0x3ff, 36, (1 << 5) | (1 << 11));
return value;
}
private static void clocks(List<ulong> value, ulong currentValue, int freeValue, int shift, int errorValue)
{
for (int nextShift = shift - 4, nextValue = 2, nextFree = freeValue; nextFree != 0; nextValue++, nextFree >>= 1)
{
if ((nextFree & 1) != 0 && (errorValue & (1 << nextValue)) == 0)
{
if (nextShift == 0) value.Add(currentValue | (uint)nextValue);
else clocks(value, currentValue | (((ulong)nextValue) << shift), freeValue ^ (1 << (nextValue - 2)), nextShift, (errorValue >> nextValue) | (((errorValue | 1) << (12 - nextValue)) & 0xfff));
}
}
}
using System;
public class Example
{
private const int Length = 12;
private static bool[] NumFlag;
private static bool[] ModFlag;
private static int SolveCount = 0;
public static void Main()
{
NumFlag = new bool[Length];
ModFlag = new bool[Length];
Search(0, 0, 0, 0);
}
private static void Search(int index, int mod, long pValue, long pMod)
{
if (index == Length)
{
SolveCount++;
Console.WriteLine("{0} . {1:X} {2:X}", SolveCount, pValue, pMod);
return;
}
for (int i = 0; i < Length; i++)
{
if (!NumFlag[i])
{
int newMod = mod + i;
if (newMod >= Length)
newMod -= Length;
if (ModFlag[newMod])
continue;
ModFlag[newMod] = NumFlag[i] = true;
Search(index + 1, newMod, (pValue << 4) + i, (pMod << 4) + newMod);
ModFlag[newMod] = NumFlag[i] = false;
}
}
}
}
#include "stdio.h"
int position[12];
int used[13];
int oknum;
int totalcount;
void GetSequence(int prevpos,int curpos)
{
int i;
int temp;
if(oknum == 12)
{
for(i = 0;i < 12;i++)
{
// printf("%d ",position[i]);
}
// printf("\n");
totalcount++;
return;
}
for(i = 1;i <= 12;i++)
{
if(!used[i] && position[(curpos+i)%12] == 0)
{
position[curpos] = i;
used[i] = 1;
oknum++;
GetSequence(curpos,(curpos+i)%12);
position[curpos] = 0;
used[i] = 0;
oknum--;
}
}
}
int main()
{
used[1] = 1;
oknum = 1;
position[1] = 1;
GetSequence(1,2);
printf("totalcount = %d",totalcount);
while(1);
return 0;
}