POJ 2965 the pilots ' refrigerator

Source: Internet
Author: User
Tags switches

Topic links

Test Instructions: a refrigerator has 4*4 a total of 16 switches, changing the state of any switch (that is, turn on and off, turn on), the same line of this switch, the same column all the switches will automatically change the state. If you want to open the refrigerator, all the switches can be opened. input: A 4x4 matrix, + indicates off,-Indicates open, output: The minimum number of operations required to open the refrigerator, and the switching coordinates of the operation.

Key: The core is actually, the switch itself and its same row of the same column of switches (a total of 7) to perform one operation, the result is that the switch itself state changed 7 times, switch the same row, the same column of the switch state changed 4 times, the other switch status changed 2 times. This is equivalent to changing only the state of itself.

Code:

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<queue>using namespacestd;intMain () {CharC; inta[Ten][Ten]; Memset (A,0,sizeof(a));  for(intI=0;i<4; i++)     for(intj=0;j<4; j + +) {cin>>C; if(c=='+')        {             for(intk=0;k<4; k++) {A[i][k]++; A[K][J]++; } A[i][j]--; }    }    intsum=0;  for(intI=0;i<4; i++)     for(intj=0;j<4; j + +)    if(a[i][j]%2) sum++; printf ("%d\n", sum);  for(intI=0;i<4; i++)     for(intj=0;j<4; j + +)    if(a[i][j]%2) printf ("%d%d\n", i+1, j+1); return 0;}

POJ 2965 the pilots ' refrigerator

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.