The Clocks
来源:互联网 发布:飞利浦x830软件 编辑:程序博客网 时间:2024/05/20 14:16
Description
|-------| |-------| |-------|| | | | | | ||---O | |---O | | O || | | | | ||-------| |-------| |-------| A B C |-------| |-------| |-------|| | | | | || O | | O | | O || | | | | | | | ||-------| |-------| |-------| D E F |-------| |-------| |-------|| | | | | || O | | O---| | O || | | | | | | ||-------| |-------| |-------| G H I (Figure 1)
There are nine clocks in a 3*3 array (figure 1). The goal is to return all the dials to 12 o'clock with as few moves as possible. There are nine different allowed ways to turn the dials on the clocks. Each such way is called a move. Select for each move a number 1 to 9. That number will turn the dials 90' (degrees) clockwise on those clocks which are affected according to figure 2 below.
Move Affected clocks 1 ABDE 2 ABC 3 BCEF 4 ADG 5 BDEFH 6 CFI 7 DEGH 8 GHI 9 EFHI (Figure 2)
Input
Your program is to read from standard input. Nine numbers give the start positions of the dials. 0=12 o'clock, 1=3 o'clock, 2=6 o'clock, 3=9 o'clock.
Output
Your program is to write to standard output. Output a shortest sorted sequence of moves (numbers), which returns all the dials to 12 o'clock. You are convinced that the answer is unique.
Sample Input
3 3 02 2 22 1 2
Sample Output
4 5 8 9
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[9][10];int main(){int t;memset(a,0,sizeof(a));a[0][0]=a[0][1]=a[0][3]=1;a[1][0]=a[1][1]=a[1][2]=a[1][4]=1;a[2][1]=a[2][2]=a[2][5]=1;a[3][0]=a[3][3]=a[3][4]=a[3][6]=1;a[4][0]=a[4][2]=a[4][4]=a[4][6]=a[4][8]=1;a[5][2]=a[5][4]=a[5][5]=a[5][8]=1;a[6][3]=a[6][6]=a[6][7]=1;a[7][4]=a[7][6]=a[7][7]=a[7][8]=1;a[8][5]=a[8][7]=a[8][8]=1;while(scanf("%d",&t)!=EOF){a[0][9]=(4-t)%4;for(int i=1;i<9;i++) {scanf("%d",&t);a[i][9]=(4-t)%4;}int res=0,r=0,l[9]={0}; // !!!for(int i=0;i<9;i++) {for(int j=r;j<9;j++) {if(a[j][i]) {if(j!=r)for(int k=i;k<10;k++) swap(a[r][k],a[j][k]);break;}}if(a[r][i]==0) {res++;continue;}for(int j=0;j<9;j++) {if(a[j][i]!=0&&j!=r) {int x=a[r][i],y=a[j][i]; // !!!for(int k=0;k<10;k++) // !!!a[j][k]=a[j][k]*x-a[r][k]*y;}}r++; l[i]=1;}int first=1;for(int i=0;i<9;i++) if(l[i]) {for(int j=0;j<9;j++) if(a[j][i]!=0) {while(a[j][9]%a[j][i]) a[j][9]+=4;for(int k=0;k<(a[j][9]/a[j][i]%4+4)%4;k++) {if(first) first=0,printf("%d",i+1);else printf(" %d",i+1);}}}printf("\n");}return 0;}
2 0
- The Clocks
- The Clocks
- The Clocks
- The Clocks
- The clocks
- The Clocks
- The Clocks
- USACO 1.4 The Clocks (clocks)
- USACO6.5.4 The Clocks(clocks)
- USACO Section 1.4 The Clocks (clocks)
- 1166 The Clocks
- POJ 1166 The clocks
- USACO 1.4-The Clocks
- POJ 1166 The Clocks
- the clocks(usaco)
- pku 1166 The Clocks
- Section 1.4 The Clocks
- USACO The clocks, ariprog
- ubuntu的环境变量设置错误怎么办(/etc/enviroment)
- Linux awk
- 网络请求和JSON解析
- Unity3D基础篇-Transform
- UNITY3D shader学习心得<四> 贴图Fiter mode过滤器模式
- The Clocks
- Activiti 基础总结二
- ubuntu 14.04 telnet 服务配置
- 只允许用来代理上网的SSH账号的方法
- 循环右移
- 表单提交单选框
- MongoDB 初识(一)
- iOS中倒计时实现效果
- 使用Button特效 selector+shape