POJ2965 - The Pilots Brothers' refrigerator - 暴力+列舉
阿新 • • 發佈:2020-09-16
題意
給出4行4列,最後要使它們都變成 - ,每次翻轉一個字元,
該字元所在行和列都會翻轉,
最後輸出都變成 - 的最少變換次數和變換路徑。
思路
主要就是把 + 都找出來,然後對其行和列進行book++,其本身book--,具體看程式碼。
AC程式碼
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> #include<cmath> #include<list> #include<stdlib.h> #include<map> #include<stack> #include<stdio.h> #include<queue> using namespace std; typedef long long ll; #define sc(T) scanf("%d",&T) #define scc(x,y) scanf("%d %d",&x,&y) #define pr(T) printf("%d\n",T) #define f(a,b,c) for (int a=b;a<c;a++) #define ff(a,b,c) for (int a=b;a>c;a--) #define inf 0x3f3f3f3f #define mem(a,b) memset(a,b,sizeof(a)) #define eps 1e-9 #define PI acos(-1) char s[5][5]; int book[5][5]; int main() { f(i,0,4) { f(j,0,4) { cin>>s[i][j]; if(s[i][j]=='+') { f(k,0,4) book[i][k]++,book[k][j]--; book[i][j]--; } } } int ans=0; f(i,0,4) { f(j,0,4) { if(book[i][j]%2) ans++; } } cout<<ans<<endl; f(i,0,4) { f(j,0,4) { if(book[i][j]%2) cout<<i+1<<" "<<j+1<<endl; } } return 0; }