这题是NOI 2013 被虐残以后 做的第一次Div 1,马上就掉回蓝了轻囧
这题一开始以为DLX各种弱。。。。。
印度尼西亚的人怎么都出这种游戏题目、、、、
进入正解模式:
我们发现出现‘十‘E 是无解的
否则必然存在n次Purification(净化)的解.
反证:
假设最优解为n+1
那么必然有一行/一列净化了2次,删掉那次不影响结果
假设存在答案为n的净化方案:
因为只做了n遍,必然每行取一个(%号表示净化点)
%E
%E
或每列:
%%
EE
所以考虑这2种情况,随便取即可,反之无解
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (1000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,a[MAXN]={0},d[MAXN]={0};
bool b[MAXN][MAXN]={0};
int main()
{
// freopen("Purification.in","r",stdin);
cin>>n;
For(i,n) For(j,n)
{
char c;
while (cin>>c)
{
if (c=='.') b[i][j]=1,a[i]=j,d[j]=i;
else if (c=='E') b[i][j]=0;
else continue;
break;
}
}
/*
For(i,n)
{
bool bo=0;
For(j,n) if (b[i][j]) bo=1;
if (!bo) {puts("-1");return 0;}
bo=0;
For(j,n) if (b[j][i]) bo=1;
if (!bo) {puts("-1");return 0;}
}*/
//For(i,n) cout<<a[i]<<' ';cout<<endl;
//For(i,n) cout<<d[i]<<' ';cout<<endl;
bool bo=0;
For(i,n) if (!a[i]) bo=1;
if (!bo)
{
For(i,n) cout<<i<<' '<<a[i]<<endl;
return 0;
}
bo=0;
For(i,n) if (!d[i]) bo=1;
if (!bo)
{
For(i,n) cout<<d[i]<<' '<<i<<endl;
return 0;
}
puts("-1");
return 0;
}