上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 21 下一页
在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。Sample Input1 8 5 0Sample Output1 92 101 #include 2 main()3 {4 int n,a[13]={0,1,0,0,2,10,4,40,92,352,724,2680,14200};5 ... Read More
posted @ 2013-06-21 18:06 瓶哥 Views(246) Comments(0) Diggs(0) Edit
用数组模拟的位运算,虽然模拟的很拙劣。。但是至少比普通搜索快1倍。 1 #include <cstdio> 2 #include <cstring> 3 #include <ctime> 4 #include <cstdlib> 5 const int SIZE = 12; 6 int sum=0,row[SIZE]={0},ld[SIZE]={0},rd[SIZE]={0}; 7 void L_m(int *a) 8 { 9 for(int i=0;i<SIZE-1;i++)10 a[i]=a[i+1];11 a[SIZE-1]=0;12 Read More
posted @ 2013-06-21 11:20 瓶哥 Views(161) Comments(0) Diggs(0) Edit
目前世界最快的N皇后算法,12皇后解25MS左右 1 #include <iostream> 2 #include <ctime> 3 using namespace std; 4 //sum用来记录皇后放置成功的不同布局数;upperlim用来标记所有列都已经放置好了皇后。 5 long sum, upperlim; 6 7 //试探算法从最右边的列开始。 8 void test(long row, long ld, long rd) 9 { 10 if (row != upperlim) 11 ... Read More
posted @ 2013-06-20 15:58 瓶哥 Views(295) Comments(0) Diggs(0) Edit
1 #include 2 #include 3 #include 4 #include 5 int ans,N; 6 int map[16][16]; 7 bool isCorrect(int row,int col) 8 { 9 for(int i=0;i=0&&j>=0;i--,j--)16 if(map[i][j]==1)17 return false; 18 for(int i=row+1,j=col-1;i=0;i++,j--)19 if(map[i][j]==1)20 r... Read More
posted @ 2013-06-20 15:56 瓶哥 Views(104) Comments(0) Diggs(0) Edit
Problem Description求A^B的最后三位数表示的整数。说明:A^B的含义是“A的B次方”Input输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1 2 int main() 3 { 4 int a,b,ans; 5 while(~scanf("%d%d",&a,&b) && a && b) 6 { 7 ans=a%1000; 8 for(int i=1;i<b;i++) 9 {10 ans=(a*ans)%1... Read More
posted @ 2013-06-19 10:19 瓶哥 Views(423) Comments(0) Diggs(0) Edit
Problem Description参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法运算。(当然,大家都知道集合的定义,就是同一个集合中不会有两个相同的元素,这里还是提醒大家一下)呵呵,很简单吧?Input每组输入数据占1行,每行数据的开始是2个整数n(0 2 #include 3 using namespace std; 4 int main() 5 { 6 int n,m,i,j,k; 7 while(~scanf("%d%d",&n,&m) Read More
posted @ 2013-06-19 10:16 瓶哥 Views(408) Comments(0) Diggs(0) Edit
Problem DescriptionHDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱。这个题目的A和B不是简单的整数,而是两个时间,A和B 都是由3个整数组成,分别表示时分秒,比如,假设A为34 45 56,就表示A所表示的时间是34小时 45分钟 56秒。Input输入数据有多行组成,首先是一个整数N,表示测试实例的个数,然后是N行数据,每行有6个整数AH,AM,AS,BH,BM,BS,分别表示时间A和B所对应的时分秒。题目保证所有的数据合法。Output对于每个测试实例,输出A+B,每 Read More
posted @ 2013-06-19 10:15 瓶哥 Views(252) Comments(0) Diggs(0) Edit
Problem Description还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1Input输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。Output对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。Sample Input2 3Sample Output1 1 1 1 1 1 1 2 1 1 #include "stdio.h" Read More
posted @ 2013-06-19 10:14 瓶哥 Views(315) Comments(0) Diggs(0) Edit
Problem Description输入一个十进制数N,将它转换成R进制数输出。Input输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(210)。Output为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。Sample Input7 2 23 12 -4 3Sample Output111 1B -11 1 #include 2 int main() 3 { 4 int n,r,i; 5 const char str[18]="0123456789ABCDEF"; 6 cha Read More
posted @ 2013-06-19 10:11 瓶哥 Views(582) Comments(0) Diggs(0) Edit
Problem Description“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。Input输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。Output如果一个字符串是回文串,则输出"yes",否则输出"no".Sample Input4 level abcde noon hahaSample Outputyes no yes no 1 #include 2 #include 3 int main() 4 { 5 Read More
posted @ 2013-06-18 18:05 瓶哥 Views(648) Comments(0) Diggs(0) Edit
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 21 下一页