poj 1166 The Clocks 暴力枚举
来源:互联网 发布:计算机病毒 知乎 编辑:程序博客网 时间:2024/06/05 03:32
poj1166 the clock 链接
关于这个~~
9个钟表的指针0-4的数,
9个状态进行for循环
遍历每个状态
每个操作不会超过四次,四次之后就重头开始了
贴代码~~
post code:
#include<stdio.h>#include<string.h>int clock[10];int original[10];int rec[10];char ch[10][20]={"ABDE","ABC","BCEF","ADG","BDEFH","CFI","DEGH","GHI","EFHI"};void change(int k,int num){ int i,j,len; k=k-1; len=strlen(ch[k]); for(i=1;i<=num;i++){ for(j=0;j<len;j++) clock[ch[k][j]-'A'+1]=(clock[ch[k][j]-'A'+1]+1)%4; }}void ori(){ int i; for(i=1;i<=9;i++) clock[i]=original[i];}int fun(int a,int b,int c,int d,int e,int f,int g,int h,int i){ int k; change(1,a); change(2,b); change(3,c); change(4,d); change(5,e); change(6,f); change(7,g); change(8,h); change(9,i); int sum=0; for(k=1;k<=9;k++) sum+=clock[k]; if(sum==0)return 1; else return 0; }int main(){ while(scanf("%d",&clock[1])!=EOF){ int a,b,c,d,e,f,g,h,i,sum=0,min=999999; original[1]=clock[1]; for(i=2;i<=9;i++){ scanf("%d",&clock[i]); original[i]=clock[i]; }// for(i=1;i<=9;i++)// printf("%d ",clock[i]);// printf("\n"); for(a=0;a<4;a++){ //9重for循环 枚举每种操作的次数 for(b=0;b<4;b++){ for(c=0;c<4;c++){ for(d=0;d<4;d++){ for(e=0;e<4;e++){ for(f=0;f<4;f++){ for(g=0;g<4;g++){ for(h=0;h<4;h++){ for(i=0;i<4;i++){ sum=a+b+c+d+e+f+g+h+i; if(min<sum)continue; ori(); if(fun(a,b,c,d,e,f,g,h,i)==1){ if(min>sum){ min=sum; rec[1]=a; rec[2]=b; rec[3]=c; rec[4]=d; rec[5]=e; rec[6]=f; rec[7]=g; rec[8]=h; rec[9]=i; } } } } } } } } } } } int x; for(x=1;x<=9;x++) if(rec[x]!=0){ rec[x]--; printf("%d",x); break; } x=1; while(x!=10){ while(rec[x]!=0){ printf(" %d",x); rec[x]--; } x++; } printf("\n"); } }
- poj 1166 The Clocks 暴力枚举
- Poj-1166-The Clocks-枚举
- POJ 1166 The Clocks(暴力搜索)
- poj 1166 The Clocks 暴力搜索
- poj 1166 The Clocks (暴力|| dfs)
- POJ 1166 The Clocks(搜索枚举)
- USACO 1.4 The Clocks (暴力枚举)
- POJ 1166 The clocks
- POJ 1166 The Clocks
- POJ 1166 The Clocks
- POJ 1166 The Clocks
- poj 1166 The Clocks
- POJ 1166 The Clocks
- poj 1166 The Clocks
- poj 1166 The Clocks
- poj 1166 The Clocks
- poj The Clocks 1166
- POJ 1166 The Clocks
- 关于ES、PES、PS以及TS码流
- 0026算法笔记——【贪心算法】多机调度问题
- 简单的分页
- 关于信息查询和相关的数据库操作语句的写法
- 在PHP中使用MySQL扩展库操作数据库
- poj 1166 The Clocks 暴力枚举
- 配置cisco pix防火墙的syslog
- 在PHP中使用MySQL扩展库处理结果集
- 三小时快速打造百度百科四级核心帐号
- 三种排序方法
- 求多边形或轮廓的凸包(Hull)
- HttpContext.Cache和HttpRuntime.Cache
- 如何将一个已有的vdi文件attach到一个虚拟机上
- predicates (from functional.h)