1、2.int main(void)int n=2;int i;i=row;j=col;while(i!=-1&j!=-1)if(chessi-j-=Q)=8)if(chessi-j+=8&if(chessi+j-=if(chessi+j+=return 1;int queen(int row,int col,int n)int i,j;int result=0;if(n=8)elseif(is_safe(row,col)chessrowcol=;8;i+)j+)result+=queen(i,j,n+1);if(result0)break;X6.for(i=1;=33;for(j=1;=50;k
2、=100-i-j;if(k%2=0)if(3*i+2*j+k/2=100)大马%dn中马%dn小马%dnnn,i,j,k);7.=10000;if(i%2=1&i%3=2&i%5=4&i%6=5&i%7=0)%dn,i);8.int sum;int a1,a2,a3,a4;for(i=1000;=9999;a1=i%10;a2=i/10%10;if(a1!=a2)a3=i/100%10;=a3&a2!=a3)a4=i/1000;=a4&a3!=a4)sum=(a1+a2+a3+a4)*(a1+a2+a3+a4);if(i%sum=0)9.#define N 10 void max_min(in
3、t *a,int m,int n,int *min1,int *min2,int *max1,int *max2);int aN=2,3,4,5,34,7,9,6,43,21;int min1,min2;int max1,max2;max_min(a,0,N-1,&min1,&min2,&max1,&max2);min1=%dnmin2=%dnmax1=%dnmax2=%dn,min1,min2,max1,max2);void max_min(int *a,int m,int n,int *min1,int *min2,int *max1,int *max2) int lmin1,lmin2,
4、lmax1,lmax2;int rmin1,rmin2,rmax1,rmax2;int mid;if(m=n) *min1=*min2=*max1=*max2=am;else if(m=n-1) if(aman) *min1=am;*min2=an;*max1=an;*max2=am;*min1=an;*min2=am;*max1=am;*max2=an;mid=(m+n)/2;max_min(a,m,mid,&lmin1,&lmin2,&lmax1,&lmax2);max_min(a,mid+1,n,&rmin1,&rmin2,&rmax1,&rmax2);if(lmin1rmin1) if
5、(lmin2*min1=lmin1;*min2=lmin2;*min2=rmin1;if(rmin2rmax1) if(lmax2*max1=lmax1;*max2=lmax2;*max2=rmax1;if(rmax2lmax1) *max1=rmax1;*max2=rmax2;*max2=lmax1;10.int add(int *a,int flag,int right);int a10=1,2,3,4,5,6,7,8,9,10;int sum=add(a,0,9);,sum);int add(int *a,int flag,int right) if(flag=right) return
6、 aflag;if(flag=right-1) return aflag+aright;mid=(flag+right)/2;return add(a,flag,mid)+add(a,mid+1,right);11.int a53=-50,17,-42,-47,-19,-3,36,-34,-43,-30,-43,34,-23,-8,-45;int max,n;int sum=0;5;max=ai0;n=0;3;if(aijmax)max=aij;n=j;sum+=max;a%d%d=%dn,i,n,max);12./* * File: newmain.c* Author: nirnava* C
7、reated on 2010年4月22日, 下午5:21*/stdlib.h#define N 4void matrix_mul(int *mul1,int *mul2,int *mul3,int length);void matrix_add_sub(int * A,int * B,int * C,int m,char ch);void update_half_value(int * A,int * B,int m);void get_half_value(int * A,int * B,int m);int mul1N*N=1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6;
8、int mul2N*N=7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2;int mul3N*N;matrix_mul(mul1,mul2,mul3,N);N*N;%5d,mul3i);if(i+1)%N=0)void matrix_add_sub(int * A,int * B,int * C,int m,char ch)m*m;if(ch=+Ci=Ai+Bi;Ci=Ai-Bi;void update_half_value(int * A,int * B,int m)m/2;Bi*m+j=Ai*m/2+j;void get_half_value(int * A,int *
9、B,int m)Ai*m/2+j=Bi*m+j;void matrix_mul(int *A,int *B,int *C,int m)if(m=2)int D,E,F,G,H,I,J;D=A0*(B1-B3);E=A3*(B2-B0);F=(A2+A3)*B0;G=(A0+A1)*B3;H=(A2-A0)*(B0+B1);I=(A1-A3)*(B2+B3);J=(A0+A3)*(B0+B3);C0=E+I+J-G;C1=D+G;C2=E+F;C3=D+H+J-F;return ;int A1m*m/4,A2m*m/4,A3m*m/4,A4m*m/4;int B1m*m/4,B2m*m/4,B3
10、m*m/4,B4m*m/4;int C1m*m/4,C2m*m/4,C3m*m/4,C4m*m/4;int Dm*m/4,Em*m/4,Fm*m/4,Gm*m/4,Hm*m/4,Im*m/4,Jm*m/4;int temp1m*m/4,temp2m*m/4;get_half_value(A1,&A0,m);get_half_value(A2,&Am/2,m);get_half_value(A3,&Am*m/2,m);get_half_value(A4,&Am*m/2+m/2,m);get_half_value(B1,&B0,m);get_half_value(B2,&Bm/2,m);get_h
11、alf_value(B3,&Bm*m/2,m);get_half_value(B4,&Bm*m/2+m/2,m);matrix_add_sub(B2,B4,temp1,m/2,-matrix_mul(A1,temp1,D,m/2);matrix_add_sub(B3,B1,temp1,m/2,matrix_mul(A4,temp1,E,m/2);matrix_add_sub(A3,A4,temp1,m/2,matrix_mul(temp1,B1,F,m/2);matrix_add_sub(A1,A2,temp1,m/2,matrix_mul(temp1,B4,G,m/2);matrix_add
12、_sub(A3,A1,temp1,m/2,matrix_add_sub(B1,B2,temp2,m/2,matrix_mul(temp1,temp2,H,m/2);matrix_add_sub(A2,A4,temp1,m/2,matrix_add_sub(B3,B4,temp2,m/2,matrix_mul(temp1,temp2,I,m/2);matrix_add_sub(A1,A4,temp1,m/2,matrix_add_sub(B1,B4,temp2,m/2,matrix_mul(temp1,temp2,J,m/2);matrix_add_sub(E,I,temp1,m/2,matri
13、x_add_sub(J,G,temp2,m/2,matrix_add_sub(temp1,temp2,C1,m/2,matrix_add_sub(D,G,C2,m/2,matrix_add_sub(E,F,C3,m/2,matrix_add_sub(D,H,temp1,m/2,matrix_add_sub(J,F,temp2,m/2,matrix_add_sub(temp1,temp2,C4,m/2,update_half_value(C1,&C0,m);update_half_value(C2,&Cm/2,m);update_half_value(C3,&Cm*m/2,m);update_h
14、alf_value(C4,&Cm*m/2+m/2,m);13.int a67=16,4,3,12,6,0,3,4,-5,6,7,0,0,2,6,0,-1,-2,3,6,8,5,3,4,0,0,-2,7,-1,7,4,0,7,-5,6,0,-1,3,4,12,4,2int b67,c67;int max;int flag;int temp;6;7;bij=aij;cij=-1;max=0;for(k=j-2;k=j+2;k+)if(k6)if(bij+bi-1kmax=bij+bi-1k;flag=k;bij=max;cij=flag;=5;if(bijmax=bij;flag=j;,max);
15、temp=ciflag;,aitemp);for(j=i;j0;j-)temp=cjtemp;,aj-1temp);14.int A6=0,3,7,9,12,13;int B6=0,5,10,11,11,11;int C6=0,4,6,11,12,12;int AB66;int temp6;int abc6;=i;ABij=Ai-j+Bj;if(ABijmax=ABij;tempi=max;abci=tempi+C5-i;if(abcimax=abci;flag=i;max=%dnc=%dn,5-flag);max=max-C5-flag;=flag;if(ABflagi=max)b=%dna
16、=%dn,flag-i);16.#define N 100int search(int *a,int left,int right);int sum_buf(int *a,int left,int right);int aN;int s;N;ai=1;a24=2;s=search(a,0,N-1);,s);int sum_buf(int *a,int left,int right)for(i=left;=right;sum+=ai;return sum;int search(int *a,int left,int right)int mid=(left+right)/2;if(left=rig
17、ht-1)if(aleftsum_buf(a,mid+1,right)return search(a,left,mid-1);if(sum_buf(a,left,mid-1)return search(a,left,mid);17.int job62=3,8,12,10,5,9,2,6,9.3,11,1int x6,bestx6,f1=0,bestf,f27=0;void try(int i);void swap(int a,int b);bestf=32767;xi=i;try(0);%d ,bestxi);nbestf=%dn,bestf);void try(int i)int j;if(i=6)bestxj=xj;bestf=f2i;f1=f1+jobxj0;if(f2if1)f2i+1=f2i+jobxj1;f2i+1=f1+jobxj1;if(f2i+1bestf)swap(i,j);try(i+1);swap(i