[Codeforces]1015E1. Stars Drawing (Easy Edition)
題目URL:http://codeforces.com/contest/1015/problem/E1
淹水淹水淹水法啦~~~~
其實可以建四個方向前綴,取size的min,再O(n^2)比較,但O(n^3)可以過的話有何不可呢??(只可惜E2的hard edition就QQ了~)
淹水淹水淹水法啦~~~~
其實可以建四個方向前綴,取size的min,再O(n^2)比較,但O(n^3)可以過的話有何不可呢??(只可惜E2的hard edition就QQ了~)
#include<bits/stdc++.h> using namespace std; char m[1005][1005]; int sor[4],a,b,total=0,tot=0,cou=0,flag=0,f=0;
int ans[10005],ansi[10005],ansj[10005],stri[10005],strj[10005]; signed main() { cin >> a >> b; for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) { cin >> m[i][j];
if(m[i][j]=='*')
{
stri[flag]=i;
strj[flag]=j;
flag++;
}
} int aa=0,bb=0,cc=0,dd=0; for(int i=0;i<flag;i++) { aa=0;
tot=1;
while((m[stri[i]][strj[i]-tot]=='*' || m[stri[i]][strj[i]-tot]=='#')&& \
(m[stri[i]][strj[i]+tot]=='*' || m[stri[i]][strj[i]+tot]=='#')&& \
(m[stri[i]+tot][strj[i]]=='*' || m[stri[i]+tot][strj[i]]=='#')&& \
(m[stri[i]-tot][strj[i]]=='*' || m[stri[i]-tot][strj[i]]=='#'))
{
m[stri[i]+tot][strj[i]]='#';
m[stri[i]-tot][strj[i]]='#';
m[stri[i]][strj[i]+tot]='#';
m[stri[i]][strj[i]-tot]='#';
m[stri[i]][strj[i]]='#';
tot++;
aa++;
}
ansi[f]=stri[i];
ansj[f]=strj[i];
ans[f]=aa;
f++;
} int deter=0; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++)
{
//cout << m[i][j];
if(m[i][j]=='*')
{
deter=1;
}
}
//cout << endl;
} int co=0; if(deter) return cout << -1 ,0; for(int i=0;i<f;i++) { if(ans[i]!=0)
co++;
}
cout << co << endl; for(int i=0;i<f;i++) { if(ans[i]!=0)
cout << ansi[i] << " " << ansj[i] << " " << ans[i] << endl;
} return 0; }
留言
張貼留言