diff --git "a/C\350\257\255\350\250\200\345\255\246\344\271\240\347\254\224\350\256\260.md" "b/C\350\257\255\350\250\200\345\255\246\344\271\240\347\254\224\350\256\260.md" deleted file mode 100755 index 5f40c203..00000000 --- "a/C\350\257\255\350\250\200\345\255\246\344\271\240\347\254\224\350\256\260.md" +++ /dev/null @@ -1,5 +0,0 @@ -# C语言学习笔记 - -# 记录你学习过程中的所见所思!酸甜苦辣! - -# 看什么看! 赶紧填坑啊! \ No newline at end of file diff --git a/level1/p01_runningLetter/1-1 RunningL.cpp b/level1/p01_runningLetter/1-1 RunningL.cpp new file mode 100644 index 00000000..e69de29b diff --git a/level1/p02_isPrime/1-2 isP.cpp b/level1/p02_isPrime/1-2 isP.cpp new file mode 100644 index 00000000..292aafce --- /dev/null +++ b/level1/p02_isPrime/1-2 isP.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +int main(){ + int n; + bool pr=1; + cin>>n; + for(int i=2;i<=sqrt(double(n));i++){ + if(n%i==0){ + pr=0; + } + } + if ((pr)&&(n!=1)){ + cout<<"Yes"; + } + else{ + cout<<"No"; + } +} diff --git a/level1/p03_Diophantus/1-3 KonoDioda.cpp b/level1/p03_Diophantus/1-3 KonoDioda.cpp new file mode 100644 index 00000000..88ac9174 --- /dev/null +++ b/level1/p03_Diophantus/1-3 KonoDioda.cpp @@ -0,0 +1,17 @@ +#include +#include +#include +#include +#include +using namespace std; + +int main(){ + int fth,sn; + for(int i=28;i<=300;i+=28){ + fth=i; + sn=fth-fth*11/28-9; + if(fth==sn*2){ + cout< +#include +#include +#include +#include +using namespace std; + +int main(){ + int a,b,c; + for(int i=100;i<=999;i++){ + a=i/100; + b=(i/10)%10; + c=i%10; + if(pow(a,3)+pow(b,3)+pow(c,3)==i){ + cout< +#include +#include +#include +#include +#include +#include +using namespace std; + +int main(){ + int a[1000]={0}; + long op,ed; + op=clock(); + a[1]=1; + for(int i=2;i<=997;i++){ + if(a[i]==0){ + for(int j=i*i;j<=1000;j+=i){ + a[j]=1; + } + cout< +#include +#include +#include +#include +using namespace std; + +void encrypt(char *s){ + int len; + char chu; + chu=s[0]; + len=strlen(s); + for(int i=0;i=1;i--){ + s[i]=s[i-1]; + } + s[0]=mo; +} + +int main(){ + char st[1000]; + cin>>st; + encrypt(st); + cout< +#include +#include +#include +#include +using namespace std; + +void hano(int gs,int st,int fi,int be){ + if(gs==1){ + cout<>n; + hano(n,1,3,2); + return 0; +} diff --git "a/level1/p09_maze/\350\277\267\345\256\253(\345\215\212\346\210\220\345\223\201\357\274\211.cpp" "b/level1/p09_maze/\350\277\267\345\256\253(\345\215\212\346\210\220\345\223\201\357\274\211.cpp" new file mode 100644 index 00000000..96d76f9a --- /dev/null +++ "b/level1/p09_maze/\350\277\267\345\256\253(\345\215\212\346\210\220\345\223\201\357\274\211.cpp" @@ -0,0 +1,235 @@ +#include +#include +#include +#include +#include +using namespace std; + +bool maze[100][100]={0}; +bool road[100][100]={0}; +int n,finish,now_x,now_y; + +typedef struct squr{ + int x; + int y; + struct squr *next; + struct squr *former; +}; + +void make_maze(int n); +void go_through(struct squr **begi); +struct squr* go_back(struct squr **begi); +void go_up(); +void go_down(); +void go_right(); +void go_left(); +void maze_print(int x,int y); + + +int main(){ + char b; + bool end=0; + cin>>n; + unsigned seed; + seed = time(0); + srand(seed); + make_maze(n); + //maze_print(0,1); + now_x=0; + now_y=1; + while(scanf("%c",&b)&&!end){ + switch (b){ + case 'w': + go_up(); + break; + case 's': + go_down(); + break; + case 'd': + go_right(); + break; + case 'a': + go_left(); + break; + } + maze_print(now_x,now_y); + if(now_x==n-1&&now_y==n-2){ + break; + } + } + cout<<"Congratulation!!"; +} + +void go_up(){ + if(road[now_x-1][now_y]){ + now_x=now_x-1; + } +} + +void go_down(){ + if(road[now_x+1][now_y]){ + now_x=now_x+1; + } +} + +void go_left(){ + if(road[now_x][now_y-1]){ + now_y=now_y-1; + } +} + +void go_right(){ + if(road[now_x][now_y+1]){ + now_y=now_y+1; + } +} + +struct squr* go_back(struct squr **begi){ + bool up=(1-road[(*begi)->x][((*begi)->y)-2])&(((*begi)->y)-2>0); + bool down=(1-road[(*begi)->x][(*begi)->y+2])&(((*begi)->y)+2x)-2][(*begi)->y])&(((*begi)->x)-2>0); + bool right=(1-road[((*begi)->x)+2][(*begi)->y])&(((*begi)->x)+2former; + go_back(&p); + } + else{ + return *begi; + } +} + +void go_through(struct squr **begi){ + struct squr *go_to=(struct squr*)malloc(sizeof(struct squr)); + struct squr *p; + struct squr *again; + bool up=(1-road[(*begi)->x][((*begi)->y)-2])&(((*begi)->y)-2>0); + bool down=(1-road[(*begi)->x][(*begi)->y+2])&(((*begi)->y)+2x)-2][(*begi)->y])&(((*begi)->x)-2>0); + bool right=(1-road[((*begi)->x)+2][(*begi)->y])&(((*begi)->x)+20){ + ch=rand()%num+1; + while(1){ + if(up){ + ch--; + choose=1; + if(ch==0)break; + } + if(down){ + ch--; + choose=2; + if(ch==0)break; + } + if(left){ + ch--; + choose=3; + if(ch==0)break; + } + if(right){ + ch--; + choose=4; + if(ch==0)break; + } + } + switch(choose){ + case 1: + road[(*begi)->x][((*begi)->y)-2]=1; + road[(*begi)->x][((*begi)->y)-1]=1; + finish++; + go_to->former=*begi; + go_to->x=(*begi)->x; + go_to->y=(*begi)->y-2; + go_to->next=NULL; + (*begi)->next=go_to; + if(finishx][((*begi)->y)+2]=1; + road[(*begi)->x][((*begi)->y)+1]=1; + finish++; + go_to->former=*begi; + go_to->x=(*begi)->x; + go_to->y=(*begi)->y+2; + go_to->next=NULL; + (*begi)->next=go_to; + if(finishx)-2][(*begi)->y]=1; + road[((*begi)->x)-1][(*begi)->y]=1; + finish++; + go_to->former=*begi; + go_to->x=(*begi)->x-2; + go_to->y=(*begi)->y; + go_to->next=NULL; + (*begi)->next=go_to; + if(finishx)+2][(*begi)->y]=1; + road[((*begi)->x)+1][(*begi)->y]=1; + finish++; + go_to->former=*begi; + go_to->x=(*begi)->x+2; + go_to->y=(*begi)->y; + go_to->next=NULL; + (*begi)->next=go_to; + if(finishformer; + again=go_back(&p); + go_through(&again); + } + } +} + + +void make_maze(int n){ + struct squr *begin=(struct squr*)malloc(sizeof(struct squr)); + for(int i=0;ix=1; + begin->y=1; + finish=1; + go_through(&begin); + road[0][1]=1; + road[n-1][n-2]=1; +} + +void maze_print(int x,int y){ + for(int i=0;i +#include +#include +#include +#include +using namespace std; + +int maze[100][100]={0}; +bool box[100][100]={0}; +bool road[100][100]={0}; +bool goal[100][100]={0}; +int n,finish,now_x,now_y,step; + +void go_up(); +void go_down(); +void go_right(); +void go_left(); +void maze_print(int x,int y); + + +int main(){ + char b; + int m,read,x; + bool end=0; + FILE *fp; + char str[10000]={' '}; + read=0; + step=0; + m=0;x=0; + fp=fopen("C:\\Users\\Lenovo\\Desktop\\Cҵ\\c2021\\level1\\p10_pushBoxes\\map.txt","rt"); + while(fgets(str, 100, fp)!=NULL) { + if(read==0){ + n=int(str[0])-48; + } + printf("%s", str); + for(int i=0;i<=100;i++){ + if((str[i]>='0'&&str[i]<='9')&&(read!=0||i!=0)){ + maze[x][m]=int(str[i])-48; + road[x][m]=1; + switch (maze[x][m]){ + case 1: + road[x][m]=0; + break; + case 2: + now_x=x; + now_y=m; + break; + case 3: + box[x][m]=1; + break; + case 4: + goal[x][m]=1; + break; + } + m++; + } + if(m==n){ + m=0; + x++; + } + } + read++; + } + while(scanf("%c",&b)&&!end){ + switch (b){ + case 'w': + go_up(); + break; + case 's': + go_down(); + break; + case 'd': + go_right(); + break; + case 'a': + go_left(); + break; + } + maze_print(now_x,now_y); + finish=1; + for(int i=0;i +#include +#include +using namespace std; + +typedef struct node{ + int data; + struct node *next; +}node; + +void node_append(struct node *newnode,struct node **head); +void node_insert(struct node *newnode,struct node **head,int num); +struct node* node_alter(struct node *aimnode); +int node_search(struct node *aimnode,int n,int num); + +int main(){ + struct node *headmain=(struct node*)malloc(sizeof(struct node)); + struct node *c=(struct node*)malloc(sizeof(struct node)); + int a,numb; + headmain=NULL; + while(scanf("%d",&a)){ + struct node *c=(struct node*)malloc(sizeof(struct node)); + c->data =a; + c->next=NULL; + node_append(c,&headmain); + } + struct node *p=(struct node*)malloc(sizeof(struct node)); + struct node *con=(struct node*)malloc(sizeof(struct node)); + con=node_alter(headmain);//反序 + numb=0; + while(numb!=-1){ + numb=node_search(con,5,numb);//查找 + } +} + +void node_append(struct node *newnode,struct node **head){ + struct node *p; + p=(*head); + if(p==NULL){ + *head=newnode; + } + else if(p->next ==NULL){ + (*head)->next=newnode; + } + else{ + p=(*head)->next ; + node_append(newnode,&p); + } +} + +void node_insert(struct node *newnode,struct node **head,int num){ + struct node *p; + if(num==0){ + p=(*head)->next; + (*head)->next=newnode; + newnode->next=p; + } + else{ + node_insert(newnode, &((*head)->next),num-1); + } +} + +struct node* node_alter(struct node *aimnode){ + struct node *p,*after,*temp; + p=aimnode; + after=p->next; + temp=p; + while(after){ + p=after; + after=p->next; + p->next=(aimnode); + (aimnode)=p; + } + temp->next =NULL; + return p; +} + +int node_search(struct node *aimnode,int n,int num){ + int now=1; + bool find_node=1; + while(aimnode){ + if(aimnode->data==n&&now>num){ + find_node=0; + break; + } + now=now+1; + aimnode=aimnode->next; + } + if(find_node){ + return -1; + } + else{ + return now; + } +} \ No newline at end of file diff --git "a/level1/p12_warehouse/\345\244\247\346\246\202\346\230\257\350\277\231\346\240\267.cpp" "b/level1/p12_warehouse/\345\244\247\346\246\202\346\230\257\350\277\231\346\240\267.cpp" new file mode 100644 index 00000000..1e4b16ea --- /dev/null +++ "b/level1/p12_warehouse/\345\244\247\346\246\202\346\230\257\350\277\231\346\240\267.cpp" @@ -0,0 +1,93 @@ +#include +#include +#include +#include +using namespace std; + +int num=0; + +struct box{ + int m; + string name; +}box; + +struct box list[100]; + +void print_list(); +void into_list(string nam,int number); +void out_list(string nam,int number); + +int main(){ + int n,shu; + string str; + cout<<"ʾ1"<>str; + cin>>shu; + into_list(str,shu); + break; + case 3: + cout<<"Ʒƺ,ûس"<>str; + cin>>shu; + out_list(str,shu); + break; + case 4: + return 0; + } + } + return 0; +} + +void print_list(){ + for(int i=0;i=0){ + if(now[i][j-t]==k){ + value=value*20; + num=num+1; + } + else if(now[i][j-t]==-k){ + value=value/10; + head=t; + break; + } + } + else{ + value=value/10; + head=t; + break; + } + } + for(int t=1;t<=4;t++){ + if(j+t<15){ + if(now[i][j+t]==k){ + value=value*20; + num++; + } + else if(now[i][j+t]==-k){ + value=value/10; + tail=t; + //cout<<"-#"<=3){ + if(num==4){ + value=value*(5+k); + } + else{ + value=value*(3+k); + } + } + if(head+tail<6){ + value=0; + } + return value; +} + +int search_r(int now[15][15],int i,int j,int k){ + int head,tail,num; + int value=100; + head=5; tail=5; + num=1; + //cout<=0){ + if(now[i-t][j]==k){ + value=value*20; + num++; + } + else if(now[i-t][j]==-k){ + value=value/10; + head=t; + break; + } + } + else{ + value=value/10; + head=t; + break; + } + } + for(int t=1;t<=4;t++){ + if(i+t<15){ + if(now[i+t][j]==k){ + value=value*20; + num++; + } + else if(now[i+t][j]==-k){ + value=value/10; + tail=t; + //if(tail!=5) cout<=3){ + if(num==4){ + value=value*(5+k); + } + else{ + value=value*(3+k); + } + } + //cout<=0&&j+t<15){ + if(now[i-t][j+t]==k){ + value=value*20; + num++; + } + else if(now[i-t][j+t]==-k){ + value=value/10; + head=t; + break; + } + } + else{ + value=value/10; + head=t; + break; + } + } + for(int t=1;t<=4;t++){ + if(i+t<15&&j-t>=0){ + if(now[i+t][j-t]==k){ + value=value*20; + num++; + } + else if(now[i+t][j-t]==-k){ + value=value/10; + tail=t; + break; + } + } + else{ + value=value/10; + tail=t; + break; + } + } + if(num>=3){ + if(num==4){ + value=value*(5+k); + } + else{ + value=value*(3+k); + } + } + if(head+tail<6){ + value=0; + } + return value; +} + +int search_xsleft(int now[15][15],int i,int j,int k){ + int head,tail,num; + int value=100; + head=5; tail=5; + num=1; + for(int t=1;t<=4;t++){ + if(i-t>=0&&j-t>=0){ + if(now[i-t][j-t]==k){ + value=value*20; + num++; + } + else if(now[i-t][j-t]==-k){ + value=value/10; + head=t; + break; + } + } + else{ + value=value/10; + head=t; + break; + } + } + for(int t=1;t<=4;t++){ + if(i+t<15&&j+t<15){ + if(now[i+t][j+t]==k){ + value=value*20; + num++; + } + else if(now[i+t][j+t]==-k){ + value=value/10; + tail=t; + break; + } + } + else{ + value=value/10; + tail=t; + break; + } + } + if(num>=3){ + if(num==4){ + value=value*(5+k); + } + else{ + value=value*(3+k); + } + } + if(head+tail<6){ + value=0; + } + return value; +} + diff --git "a/\345\256\236\351\252\214/~$20080602030-\350\257\270\350\221\233\347\246\271\351\230\263.doc" "b/\345\256\236\351\252\214/~$20080602030-\350\257\270\350\221\233\347\246\271\351\230\263.doc" new file mode 100644 index 00000000..a6c74460 Binary files /dev/null and "b/\345\256\236\351\252\214/~$20080602030-\350\257\270\350\221\233\347\246\271\351\230\263.doc" differ diff --git "a/\345\256\236\351\252\214/\344\272\224\345\255\220\346\243\213\357\274\210\345\244\232\345\261\202\345\244\261\350\264\245\347\211\210\346\234\254\357\274\211.cpp" "b/\345\256\236\351\252\214/\344\272\224\345\255\220\346\243\213\357\274\210\345\244\232\345\261\202\345\244\261\350\264\245\347\211\210\346\234\254\357\274\211.cpp" new file mode 100644 index 00000000..7b64875e --- /dev/null +++ "b/\345\256\236\351\252\214/\344\272\224\345\255\220\346\243\213\357\274\210\345\244\232\345\261\202\345\244\261\350\264\245\347\211\210\346\234\254\357\274\211.cpp" @@ -0,0 +1,613 @@ +#include +#include +#include +#include +#include +using namespace std; +int qipan[15][15]={0}; +int fuzhi[15][15]; +int c_x,c_y; + +int value_player(int now[15][15],int k); +int value_com(int now[15][15],int k); +int win(int now[15][15]); +int play_depth(int now[15][15],int depth); +int search_l(int now[15][15],int k); +int search_r(int now[15][15],int k); +int search_xsright(int now[15][15],int p_c); +int search_xsleft(int now[15][15],int p_c); +void print_qipan(); +void com_play(int now[15][15]); +int nearb(int i,int j); + +int main(){ + int a,b; + print_qipan(); + while(scanf("%d %d/n",&a,&b)){ + qipan[a][b]=1; + print_qipan(); + cout<1){ + p_x=0;p_y=0;x=0;y=0; + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(now[i][j]==0){ + now[i][j]=1; + for(int t=0;t<15;t++){ + for(int k=0;k<15;k++){ + copy[t][k]=now[t][k]; + } + } + player=value_player(copy,1); + //if(now[6][10]==-1&&i==6&&j==8)cout<<"1 "<com1){ + p_x=i;p_y=j; + com1=player-computer; + //cout<com2){ + com2=computer-player; + x=i; y=j; + //cout<min){ + x=i;y=j; + min=computer-player; + //cout<max){ + max=comp; + c_x=i;c_y=j; + //cout<4){ + return 1; + } + } + else if(now[i][j]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int j=0;j<15;j++){ + for(int i=0;i<15;i++){ + if(now[i][j]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i][j]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int t=-14;t<15;t++){ + if(t<0){ + i=0;j=-t; + } + else{ + i=t;j=0; + } + for(int k=0;k<15-abs(t);k++){ + if(now[i+k][j+k]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i+k][j+k]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int t=0;t<29;t++){ + if(t<15){ + i=t;j=0; + } + else{ + i=14;j=t-14; + } + for(int k=0;k<15-abs(14-t);k++){ + if(now[i-k][j+k]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i-k][j+k]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + return 0; +} + +int value_player(int now[15][15],int k){ + int valuep=0; + valuep=valuep+search_l(now,1); + //cout<<"l: "<0&&now[i][j-1]==-k){ + value_i=value_i/10; + cl=j; + //cout<=10000)value_i=value_i*100; + value+=value_i; + j++; + } + } + return value; +} + +int search_r(int now[15][15],int k){ + int value=0; + int value_i,num; + int cl; + for(int j=0;j<=14;j++){ + int i=0; + while(i<=14){ + value_i=0; + if(now[i][j]==k){ + value_i=10; + cl=0; + if(i>0&&now[i-1][j]==-k){ + value_i=value_i/10; + cl=i; + //cout<=10000)value_i=value_i*100; + value+=value_i; + i++; + } + } + return value; +} + +int search_xsright(int now[15][15],int p_c){ + int value=0; + int value_i,num,i,j; + int cl; + for(int t=-14;t<15;t++){ + if(t<0){ + i=0;j=-t; + } + else{ + i=t;j=0; + } + int k=0; + while(k<15-abs(t)){ + value_i=0; + if(now[i+k][j+k]==p_c){ + value_i=10; + cl=0; + if(k>0&&now[i+k-1][j+k-1]==-p_c){ + value_i=value_i/10; + cl=k; + //cout<=10000)value_i=value_i*100; + value+=value_i; + k++; + } + } + return value; +} + +int search_xsleft(int now[15][15],int p_c){ + int value=0; + int value_i,num,i,j; + int cl; + for(int t=0;t<29;t++){ + if(t<15){ + i=t;j=0; + } + else{ + i=14;j=t-14; + } + int k=0; + while(k<15-abs(14-t)){ + value_i=0; + if(now[i-k][j+k]==p_c){ + value_i=10; + cl=0; + if(k>0&&now[i-k+1][j+k-1]==-p_c){ + value_i=value_i/10; + cl=k; + //cout<=10000)value_i=value_i*100; + value+=value_i; + k++; + } + } + return value; +} + +void print_qipan(){ + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(qipan[i][j]==0){ + cout<<"0 "; + } + if(qipan[i][j]==1){ + cout<<"P "; + } + if(qipan[i][j]==-1){ + cout<<"U "; + } + } + cout< +#include +#include +#include +#include +using namespace std; +int qipan[15][15]={0}; +int fuzhi[15][15]; +int c_x,c_y; +int maxmax=9999999; +int minmax=999999; + +int value_player(int now[15][15]); +int value_com(int now[15][15]); +int win(int now[15][15]); +int min_v(int now[15][15],int depth,int a,int b); +int max_v(int now[15][15],int depth,int a,int b); +int search_l(int now[15][15],int k); +int search_r(int now[15][15],int k); +int search_xsright(int now[15][15],int p_c); +int search_xsleft(int now[15][15],int p_c); +void print_qipan(); +void com_play(int now[15][15]); +int nearb(int i,int j); + +int main(){ + int a,b; + print_qipan(); + while(scanf("%d %d/n",&a,&b)){ + qipan[a][b]=1; + print_qipan(); + cout<=0&&i+t<15) return 1; + if(qipan[i][j+t]!=0&&j+t>=0&&j+t<15) return 1; + if(qipan[i+t][j+t]!=0&&i+t>=0&&i+t<15&&j+t>=0&&j+t<15) return 1; + if(qipan[i+t][j-t]!=0&&i+t>=0&&i+t<15&&j-t>=0&&j-t<15) return 1; + } + return 0; +} + +int max_v(int now[15][15],int depth,int a,int b){ + int v; + int vl[5],x[5],y[5]; + int copy[15][15]; + for(int t=0;t<15;t++){ + for(int k=0;k<15;k++){ + copy[t][k]=now[t][k]; + } + } + if(depth<=0||win(copy)!=0){ + int v_f; + if(win(copy)==1){ + v_f=-minmax; + } + else if(win(copy)==-1){ + v_f=minmax; + } + else{ + v_f=value_com(copy)-value_player(copy); + } + return v_f; + } + for(int i=0;i<5;i++){ + vl[i]=-maxmax; + x[i]=15; + y[i]=15; + } + int best=-maxmax; + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(now[i][j]==0&&nearb(i,j)==1){ + now[i][j]=-1; + for(int t=0;t<15;t++){ + for(int k=0;k<15;k++){ + copy[t][k]=now[t][k]; + } + } + v=value_com(copy)-value_player(copy); + for(int t=0;t<5;t++){ + if(vl[t]t;k--){ + vl[k]=vl[k-1]; + x[k]=x[k-1]; + y[k]=y[k-1]; + } + vl[t]=v; + x[t]=i; + y[t]=j; + } + } + now[i][j]=0; + } + } + } + for(int i=0;i<5;i++){ + if(x[i]<15){ + now[x[i]][y[i]]=-1; + for(int t=0;t<15;t++){ + for(int k=0;k<15;k++){ + copy[t][k]=now[t][k]; + } + } + vl[i]=min_v(copy,depth-1,a,b); + if(vl[i]best){ + best=vl[i]; + //cout<v||(vl[t]==v&&abs(i-7)+abs(j-7)t;k--){ + vl[k]=vl[k-1]; + x1[k]=x1[k-1]; + y1[k]=y1[k-1]; + } + vl[t]=v; + x1[t]=i; + y1[t]=j; + } + } + now[i][j]=0; + } + } + } + for(int i=0;i<5;i++){ + if(x1[i]<15){ + now[x1[i]][y1[i]]=1; + for(int t=0;t<15;t++){ + for(int k=0;k<15;k++){ + copy[t][k]=now[t][k]; + } + } + vl[i]=max_v(copy,depth-1,a,b); + if(vl[i]>b){ + b=vl[i]; + } + now[x1[i]][y1[i]]=0; + if(vl[i]t;k--){ + vl[k]=vl[k-1]; + x[k]=x[k-1]; + y[k]=y[k-1]; + } + vl[t]=v; + x[t]=i; + y[t]=j; + } + } + now[i][j]=0; + } + } + } + for(int i=0;i<5;i++){ + if(x[i]<15){ + now[x[i]][y[i]]=-1; + for(int t=0;t<15;t++){ + for(int k=0;k<15;k++){ + copy[t][k]=now[t][k]; + } + } + vl[i]=min_v(copy,6,maxmax,-maxmax); + //cout<max){ + max=vl[i]; + c_x=x[i]; + c_y=y[i]; + } + } + } +} + +int win(int now[15][15]){ + int w=0; + int i,j; + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(now[i][j]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i][j]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int j=0;j<15;j++){ + for(int i=0;i<15;i++){ + if(now[i][j]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i][j]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int t=-14;t<15;t++){ + if(t<0){ + i=0;j=-t; + } + else{ + i=t;j=0; + } + for(int k=0;k<15-abs(t);k++){ + if(now[i+k][j+k]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i+k][j+k]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int t=0;t<29;t++){ + if(t<15){ + i=t;j=0; + } + else{ + i=14;j=t-14; + } + for(int k=0;k<15-abs(14-t);k++){ + if(now[i-k][j+k]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i-k][j+k]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + return 0; +} + +int value_player(int now[15][15]){ + int valuep=0; + valuep=valuep+search_l(now,1); + //cout<<"l: "<0&&now[i][j-1]==-k){ + value_i=value_i/10; + cl=j; + //cout<=1000&&num==0)value_i=value_i*2; + value+=value_i; + j++; + } + } + return value; +} + +int search_r(int now[15][15],int k){ + int value=0; + int value_i,num; + int cl; + for(int j=0;j<=14;j++){ + int i=0; + while(i<=14){ + value_i=0; + if(now[i][j]==k){ + value_i=10; + cl=0; + if(i>0&&now[i-1][j]==-k){ + value_i=value_i/10; + cl=i; + //cout<=1000&&num==0)value_i=value_i*2; + value+=value_i; + i++; + } + } + return value; +} + +int search_xsright(int now[15][15],int p_c){ + int value=0; + int value_i,num,i,j; + int cl; + for(int t=-14;t<15;t++){ + if(t<0){ + i=0;j=-t; + } + else{ + i=t;j=0; + } + int k=0; + while(k<15-abs(t)){ + value_i=0; + if(now[i+k][j+k]==p_c){ + value_i=10; + cl=0; + if(k>0&&now[i+k-1][j+k-1]==-p_c){ + value_i=value_i/10; + cl=k; + //cout<=1000&&num==0)value_i=value_i*2; + value+=value_i; + k++; + } + } + return value; +} + +int search_xsleft(int now[15][15],int p_c){ + int value=0; + int value_i,num,i,j; + int cl; + for(int t=0;t<29;t++){ + if(t<15){ + i=t;j=0; + } + else{ + i=14;j=t-14; + } + int k=0; + while(k<15-abs(14-t)){ + value_i=0; + if(now[i-k][j+k]==p_c){ + value_i=10; + cl=0; + if(k>0&&now[i-k+1][j+k-1]==-p_c){ + value_i=value_i/10; + cl=k; + //cout<=1000&&num==0)value_i=value_i*2; + value+=value_i; + k++; + } + } + return value; +} + +void print_qipan(){ + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(qipan[i][j]==0){ + cout<<"0 "; + } + if(qipan[i][j]==1){ + cout<<"P "; + } + if(qipan[i][j]==-1){ + cout<<"U "; + } + } + cout< +#include +#include +#include +using namespace std; +int qipan[15][15]={0}; +int fuzhi[15][15]; +int c_x,c_y; + +int value_player(int now[15][15]); +int value_com(int now[15][15]); +int win(int now[15][15]); +int play_depth(int now[15][15],int depth); +int search_l(int now[15][15],int k); +int search_r(int now[15][15],int k); +int search_xsright(int now[15][15],int p_c); +int search_xsleft(int now[15][15],int p_c); +void print_qipan(); +void com_play(int now[15][15]); + +int main(){ + int a,b; + print_qipan(); + while(scanf("%d %d/n",&a,&b)){ + qipan[a][b]=1; + print_qipan(); + cout<com1){ + p_x=i;p_y=j; + com1=player-computer; + //cout<com2){ + com2=computer-player; + x=i; y=j; + //cout<min){ + x=i;y=j; + min=computer-player; + //cout<max){ + max=com; + c_x=i;c_y=j; + } + else if(com==max&&(abs(i-7)+abs(j-7))<(abs(x-7)+abs(y-7))){ + c_x=i;c_y=j; + } + now[i][j]=0; + } + } + } +} + +int win(int now[15][15]){ + int w=0; + int i,j; + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(now[i][j]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i][j]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int j=0;j<15;j++){ + for(int i=0;i<15;i++){ + if(now[i][j]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i][j]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int t=-14;t<15;t++){ + if(t<0){ + i=0;j=-t; + } + else{ + i=t;j=0; + } + for(int k=0;k<15-abs(t);k++){ + if(now[i+k][j+k]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i+k][j+k]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + for(int t=0;t<29;t++){ + if(t<15){ + i=t;j=0; + } + else{ + i=14;j=t-14; + } + for(int k=0;k<15-abs(14-t);k++){ + if(now[i-k][j+k]==1){ + if(w<0){ + w=0; + w++; + } + else{ + w++; + } + if(w>4){ + return 1; + } + } + else if(now[i-k][j+k]==-1){ + if(w>0){ + w=0; + w--; + } + else{ + w--; + } + if(w<-4){ + return -1; + } + } + } + w=0; + } + return 0; +} + +int value_player(int now[15][15]){ + int valuep=0; + valuep=valuep+search_l(now,1); + //cout<<"l: "<0&&now[i][j-1]==-k){ + value_i=value_i/10; + cl=j; + //cout<0&&now[i-1][j]==-k){ + value_i=value_i/10; + cl=i; + //cout<0&&now[i+k-1][j+k-1]==-p_c){ + value_i=value_i/10; + cl=k; + //cout<0&&now[i-k+1][j+k-1]==-p_c){ + value_i=value_i/10; + cl=k; + //cout<