51nod 1337 翻转游戏
2017-05-05 23:43
176 查看
这个题的关键在于那些?的要求,因为是?所以不用一下子满足,这就是这个题的玄机了。
于是我们可以“顺便”把这些 “对于当前关是?,但是对于以后的关不是?” 的灯给进行操作。
这样就可以减少次数了。
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stdio.h>
#define LL long long int
using namespace std;
char mp[60][60];
char now[60];
int n,m;
int work()
{
int cnt = 0;
for(int i = 0;i<m;i++) now[i] = '-';
for(int rd = 0;rd < n;rd++)
{
//看看有没有必须变成+的
bool hsp = false;//have to become plus;
for(int j = 0;j<m;j++)
{
if(mp[rd][j] == '+' && now[j] == '-')
{
hsp = true;
now[j] = '+';
}
}
if(hsp == true)//看看可不可以顺便变掉
{
cnt ++;
for(int j = 0;j<m;j++)
{
for(int k = rd;k<n;k++)
{
if(mp[k][j] == '-') break;
if(mp[k][j] == '+')
{
now[j] = '+';
break;
}
}
}
}
bool hsm = false;
for(int j = 0;j<m;j++)
{
if(mp[rd][j] == '-' && now[j] == '+')
{
hsm = true;
now[j] = '-';
}
}
if(hsm == true)//看看可不可以顺便变掉
{
cnt ++;
for(int j = 0;j<m;j++)
{
for(int k = rd;k<n;k++)
{
if(mp[k][j] == '+') break;
if(mp[k][j] == '-')
{
now[j] = '-';
break;
}
}
}
}
cnt ++;
}
return cnt;
}
int main()
{
int TT;
cin>>TT;
while(TT--)
{
//init();
cin>>n>>m;
for(int i = 0;i<n;i++) scanf("%s",mp[i]);
int ans = work();
cout<<ans<<endl;
}
return 0;
}
于是我们可以“顺便”把这些 “对于当前关是?,但是对于以后的关不是?” 的灯给进行操作。
这样就可以减少次数了。
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stdio.h>
#define LL long long int
using namespace std;
char mp[60][60];
char now[60];
int n,m;
int work()
{
int cnt = 0;
for(int i = 0;i<m;i++) now[i] = '-';
for(int rd = 0;rd < n;rd++)
{
//看看有没有必须变成+的
bool hsp = false;//have to become plus;
for(int j = 0;j<m;j++)
{
if(mp[rd][j] == '+' && now[j] == '-')
{
hsp = true;
now[j] = '+';
}
}
if(hsp == true)//看看可不可以顺便变掉
{
cnt ++;
for(int j = 0;j<m;j++)
{
for(int k = rd;k<n;k++)
{
if(mp[k][j] == '-') break;
if(mp[k][j] == '+')
{
now[j] = '+';
break;
}
}
}
}
bool hsm = false;
for(int j = 0;j<m;j++)
{
if(mp[rd][j] == '-' && now[j] == '+')
{
hsm = true;
now[j] = '-';
}
}
if(hsm == true)//看看可不可以顺便变掉
{
cnt ++;
for(int j = 0;j<m;j++)
{
for(int k = rd;k<n;k++)
{
if(mp[k][j] == '+') break;
if(mp[k][j] == '-')
{
now[j] = '-';
break;
}
}
}
}
cnt ++;
}
return cnt;
}
int main()
{
int TT;
cin>>TT;
while(TT--)
{
//init();
cin>>n>>m;
for(int i = 0;i<n;i++) scanf("%s",mp[i]);
int ans = work();
cout<<ans<<endl;
}
return 0;
}
相关文章推荐
- 51Nod-1337-翻转游戏
- 51nod-1337:翻转游戏
- 51nod 1337 翻转游戏
- 51nod 1381 硬币游戏
- qduoj 79 翻转游戏 经典牛翻地问题 思维
- 51Nod-1536-不一样的猜数游戏
- 51nod 1714:B君的游戏(博弈 sg打表)
- 51nod 1067 Bash游戏 V2 (博弈论_找规律)
- 51Nod 1417 天堂里的游戏
- 51nod 1069 Nim游戏
- 51nod 1066 bash游戏
- 51nod 1459 迷宫游戏 dijkstra变形
- 51nod 1068 Bash游戏 V3
- FZU - 1928 硬币翻转游戏(2维nim游戏)
- 51nod 1441 士兵的数字游戏 (模拟线性筛)
- 51Nod-棋子游戏(博弈问题)
- 51nod 1459 迷宫游戏(最短路)
- 51Nod 1068 Bash游戏 V3 找规律
- 51Nod-1417-天堂里的游戏
- 51nod-1714 B君的游戏