标签:
题意:有n(n <= 100)行,每行有2*i-1个可显字符‘#‘与‘-‘,组成一个倒三角形,问由‘-‘组成的最大三角形的‘-‘的个数为多少?
思路:顶点为倒三角,即行列奇偶相同;对于一个顶点可以扩展的最大边长首先需要上面三角为‘-‘,这样只需建立在顶点上一行的左右两个点的最大边长即可;
三角形个数就是边长的平方;
ps:开始我想的是从列的角度看轴线的左右两边的min,然后模拟行。真是醉了。
#include<iostream> #include<cstdio> #include<cstring> #include<string.h> #include<algorithm> #include<vector> #include<cmath> #include<stdlib.h> #include<time.h> #include<stack> #include<set> #include<map> #include<queue> using namespace std; #define rep0(i,l,r) for(int i = (l);i < (r);i++) #define rep1(i,l,r) for(int i = (l);i <= (r);i++) #define rep_0(i,r,l) for(int i = (r);i > (l);i--) #define rep_1(i,r,l) for(int i = (r);i >= (l);i--) #define MS0(a) memset(a,0,sizeof(a)) #define MS1(a) memset(a,-1,sizeof(a)) #define MSi(a) memset(a,0x3f,sizeof(a)) #define inf 0x3f3f3f3f #define lson l, m, rt << 1 #define rson m+1, r, rt << 1|1 typedef pair<int,int> PII; #define A first #define B second #define MK make_pair typedef __int64 ll; template<typename T> void read1(T &m) { T x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} m = x*f; } template<typename T> void read2(T &a,T &b){read1(a);read1(b);} template<typename T> void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);} template<typename T> void out(T a) { if(a>9) out(a/10); putchar(a%10+‘0‘); } char c[110][210]; int d[110][220]; int main() { int n; read1(n); rep1(i,1,n) gets(c[i]+1); int len = 2*n,ans = 0; rep0(i,1,len){ if(c[1][i] == ‘-‘){ d[1][i] = 1;ans = 1;} } rep1(i,2,n){ rep1(j,i,len-i) if(c[i][j] == ‘-‘){ d[i][j] = 1; if((i&1) == (j&1) && c[i-1][j] == ‘-‘ && c[i-1][j-1] == ‘-‘ && c[i-1][j+1] == ‘-‘) d[i][j] = min(d[i-1][j+1]+1,d[i-1][j-1]+1); ans = max(ans,d[i][j]); } } printf("%d\n",ans*ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/hxer/p/5294810.html