|
[题目][第一阶段 第三题]『深圳腾讯2010安全技术竞赛』
第二题写算法。这题到分析算法了。 |
|
终于知道了Kx币的命名原因,为你解答为什么叫做Kx币
我有多少了?? |
|
[题目][第一阶段 第二题]『深圳腾讯2010安全技术竞赛』
从CSDN上面找的,只能计算出一组,速度还真快. 把代码整理了一下。。看不懂哇。。。 #include <iostream> #include <list> using namespace std; #define MSIZE 100 int temp1[MSIZE+1][MSIZE+1]; int temp2[MSIZE+1][MSIZE+1]; int temp3[MSIZE+1][MSIZE+1]; int temp4[MSIZE+1][MSIZE+1]; int Magic[MSIZE+1][MSIZE+1]; //**************************** int mmod(int a,int b) { if(a>=0) return a%b; else return b-(-a%b); } void Swap(int& a,int& b) { int t=a; a=b; b=t; } void SetMagic(int size) { int i,j; if(size%2==1) { for(i=1;i <=size;i++) for(j=1;j <=size;j++) { temp1[i][j]=i; temp2[i][j]=j; // printf("temp1[%d][%d]=%d,temp2[%d][%d]=%d\n",i,j,temp1[i][j],i,j,temp2[i][j]); } for(i=1;i <=size;i++) for(j=1;j <=size;j++) { temp3[i][j]=mmod(temp1[i][j]+temp2[i][j]-(size+3)/2,size); temp4[i][j]=mmod(temp1[i][j]+2*temp2[i][j]-2,size); } for(i=1;i <=size;i++) for(j=1;j <=size;j++) Magic[i][j]=size*temp3[i][j]+temp4[i][j]+1; } else if(size%4==0) { for(i=1;i <=size;i++) for(j=1;j <=size;j++) { temp1[i][j]=i; temp2[i][j]=j; } for(i=1;i <=size;i++) for(j=1;j <=size;j++) temp3[i][j]=(temp1[i][j]%4)/2==(temp2[i][j]%4)/2?1:0; for(i=1;i <=size;i++) for(j=1;j <=size;j++) temp4[i][j]=size*(i-1)+j; for(i=1;i<=size;i++) for(j=1;j<=size;j++) if(temp3[i][j]==1) Magic[i][j]=size*size+1-temp4[i][j]; else Magic[i][j]=temp4[i][j]; } else { int p=size/2; SetMagic(p); for(i=1;i <=size;i++) for(j=1;j <=size;j++) if(i <=p&&j <=p) temp1[i][j]=Magic[i][j]; else if(i <=p&&j> p) temp1[i][j]=Magic[i][j-p]+2*p*p; else if(i> p&&j <=p) temp1[i][j]=Magic[i-p][j]+3*p*p; else temp1[i][j]=Magic[i-p][j-p]+p*p; int k=(size-2)/4; list <int> lj; for(i=1;i <=k;i++) lj.push_back(i); if(k==2) { lj.push_back(size); } else if(k> 2) { lj.push_back(size-k+2); lj.push_back(size); } else {//do nothing } for(list <int> ::iterator itrj=lj.begin();itrj!=lj.end();itrj++) for(i=1;i <=p;i++) Swap(temp1[i][*itrj],temp1[p+i][*itrj]); lj.clear(); lj.push_back(1); lj.push_back(k+1); for(itrj=lj.begin();itrj!=lj.end();itrj++) Swap(temp1[k+1][*itrj],temp1[k+1+p][*itrj]); memcpy(Magic,temp1,(MSIZE+1)*(MSIZE+1)*sizeof(int)); } } //*********************************** //void prin() //{ //printf( "func: %sn ",__FUNC__); //} void main(void) { int n; cout << "Please input a integer: "; cin>> n; if(n==2||n <1) { cout << "The magic square of size " <<n << " does not exist. " <<endl; return; } SetMagic(n); for(int i=1;i <=n;i++) { for(int j=1;j <=n;j++) { cout.width(4); cout <<Magic[i][j] << " "; } cout <<endl; } return; } |
|
[题目][第一阶段 第二题]『深圳腾讯2010安全技术竞赛』
http://topic.csdn.net/t/20060209/09/4546626.html |
|
|
|
[转帖]Мега коллекция Анпакеров и Анализаторов. COM/EXE/DLL
lin版是怎么打出 удобно если нужно часто распаковывать файлы, или сразу много. 这些字的呀??我有些好奇,,lin版是中国人吗? |
|
[原创]TMD/WL 代码修复讲解
难道只有苦力这条路可以走吗?? |
|
|
|
[十周年]“看雪十年 相伴你我”现场直播[照片]
又看了一遍,很激动. |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值