POJ1166 The Clocks [enumeration]

Source: Internet
Author: User

This question is quite interesting. I don't know how to classify it into Gaussian. It should be an enumeration.

The idea is very good, not to mention, look at the code

C, which array is prone to initialization errors?

The final output is a bit confusing, but you may not need to pay special attention to the last space.

#include <cstdio>#include <cstring>#include <iostream>#include <cstdlib>using namespace std;int c[10][10]={{0,0,0,0,0,0,0,0,0,0},{0,1,1,0,1,1,0,0,0,0},{0,1,1,1,0,0,0,0,0,0},{0,0,1,1,0,1,1,0,0,0},{0,1,0,0,1,0,0,1,0,0},{0,0,1,0,1,1,1,0,1,0},{0,0,0,1,0,0,1,0,0,1},{0,0,0,0,1,1,0,1,1,0},{0,0,0,0,0,0,0,1,1,1},{0,0,0,0,0,1,1,0,1,1}};void copy(int* tmp,int* num){for(int i=1;i<=9;i++)tmp[i]=num[i];}void add(int* tmp,int i,int ti){for(int ii=1;ii<=9;ii++){tmp[ii]+=c[i][ii]*ti;tmp[ii]%=4;}}bool check(int* tmp){for(int i=1;i<=9;i++){if(tmp[i]!=0)return false;}return true;}int sum(int* t){int s=0;for(int i=1;i<=9;i++)s+=t[i];return s;}int num[10];int tmp[10];int t[10];int ans[10];int minn=9999999;int main(){for(int i=1;i<=9;i++)cin>>num[i];for(t[1]=0;t[1]<=3;t[1]++)for(t[2]=0;t[2]<=3;t[2]++)for(t[3]=0;t[3]<=3;t[3]++)for(t[4]=0;t[4]<=3;t[4]++)for(t[5]=0;t[5]<=3;t[5]++)for(t[6]=0;t[6]<=3;t[6]++)for(t[7]=0;t[7]<=3;t[7]++)for(t[8]=0;t[8]<=3;t[8]++)for(t[9]=0;t[9]<=3;t[9]++){copy(tmp,num);for(int i=1;i<=9;i++)add(tmp,i,t[i]);if(!check(tmp))continue;else if(sum(t)<minn){minn=sum(tmp);copy(ans,t);}}int last=0;for(int i=1;i<=9;i++){if(ans[i])last=i;}for(int i=1;i<last;i++){for(int k=1;k<=ans[i];k++){cout<<i<<' ';}}for(int k=1;k<ans[last];k++)cout<<last<<' ';cout<<last<<'\n';return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.