日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj2965 【枚举】

發布時間:2024/4/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj2965 【枚举】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator.

There are 16 handles on the refrigerator door. Every handle can be in one of two states: open or closed. The refrigerator is open only when all handles are open. The handles are represented as a matrix 4х4. You can change the state of a handle in any location?[i, j]?(1 ≤ i, j ≤ 4). However, this also changes states of all handles in row?i?and all handles in column?j.

The task is to determine the minimum number of handle switching necessary to open the refrigerator.

Input

The input contains four lines. Each of the four lines contains four characters describing the initial state of appropriate handles. A symbol “+” means that the handle is in closed state, whereas the symbol “?” means “open”. At least one of the handles is initially closed.

Output

The first line of the input contains N – the minimum number of switching. The rest N lines describe switching sequence. Each of the lines contains a row number and a column number of the matrix separated by one or more spaces. If there are several solutions, you may give any one of them.

Sample Input

-+-- ---- ---- -+--

Sample Output

6 1 1 1 3 1 4 4 1 4 3 4 4
思路:dfs,加個數組保存路徑
實現代碼: #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<stack> #include<set> #include<list> using namespace std; #define ll long long #define sd(x) scanf("%d",&x) #define sdd(x,y) scanf("%d%d",&x,&y) #define sddd(x,y,z) scanf("%d%d%d",&x,&y,&z) #define sf(x) scanf("%s",x) #define ff(i,x,y) for(int i = x;i <= y;i ++) #define fj(i,x,y) for(int i = x;i >= y;i --) #define mem(s,x) memset(s,x,sizeof(s)); #define pr(x) printf("%d",x); const int Mod = 1e9+7; const int inf = 1e9; const int Max = 1e5+10; void exgcd(ll a,ll b,ll& d,ll& x,ll& y){if(!b){d=a;x=1;y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}} ll inv(ll a,ll n){ll d, x, y;exgcd(a,n,d,x,y);return (x+n)%n;} int gcd(int a,int b) { return (b>0)?gcd(b,a%b):a; } int lcm(int a, int b) { return a*b/gcd(a, b); } //int mod(int x,int y) {return x-x/y*y;} char s[10]; int mp[10][10]; int ans = inf,i,j; int rankx[100],ranky[100],fx[100],fy[100]; int check() {for(i=0;i<4;i++){for(j=0;j<4;j++){if(mp[i][j]!=1)return 0;}}return 1; }void fan(int x,int y){for(i=0;i<4;i++){mp[x][i] = !mp[x][i];mp[i][y] = !mp[i][y];}mp[x][y] = !mp[x][y]; }int dfs(int x,int y,int t) {if(check()){if(ans>t){ans = t;for(i=0;i<t;i++){rankx[i] = fx[i];ranky[i] = fy[i];}}return 0;}if(x>=4||y>=4)return 0;int nx = (x+1)%4;int ny = y+(x+1)/4;dfs(nx,ny,t);fan(x,y);fx[t] = x+1;fy[t] = y+1;dfs(nx,ny,t+1);fan(x,y);return 0; } int main() {for(i=0;i<4;i++){cin>>s;for(j=0;j<4;j++){if(s[j]=='+')mp[i][j] = 0;elsemp[i][j] = 1;}}dfs(0,0,0);cout<<ans<<endl;for(i=0;i<ans;i++){cout<<rankx[i]<<" "<<ranky[i]<<endl;}return 0; }

?

轉載于:https://www.cnblogs.com/kls123/p/7358733.html

總結

以上是生活随笔為你收集整理的poj2965 【枚举】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。