hdu5319 Painter

来源:互联网 发布:js 特殊字符校验 编辑:程序博客网 时间:2024/06/05 08:04

直接模拟  要非常细心。。。。

代码:

#include <algorithm>#include <iostream>#include <sstream>#include <cstdlib>#include <cstring>#include <iomanip>#include <cstdio>#include <string>#include <bitset>#include <vector>#include <queue>#include <stack>#include <cmath>#include <list>#include <map>#include <set>#define sss(a,b,c) scanf("%d%d%d",&a,&b,&c)#define mem1(a) memset(a,-1,sizeof(a))#define mem(a) memset(a,0,sizeof(a))#define ss(a,b) scanf("%d%d",&a,&b)#define s(a) scanf("%d",&a)#define p(a) printf("%d\n", a)#define INF 0x3f3f3f3f#define w(a) while(a)#define PI acos(-1.0)#define LL long long#define eps 10E-9#define N 100000#define mod 100000000using namespace std;void mys(int& res){    int flag=0;    char ch;    while(!(((ch=getchar())>='0'&&ch<='9')||ch=='-'))        if(ch==EOF)  res=INF;    if(ch=='-')  flag=1;    else if(ch>='0'&&ch<='9')  res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')  res=res*10+ch-'0';    res=flag?-res:res;}void myp(int a){    if(a>9)        myp(a/10);    putchar(a%10+'0');}/*************************THE END OF TEMPLATE************************/char str[55][55];int  solve(int n, int len){    int i, j, k;    bool f;    int ans1 = 0;    /**************求'\R'方式*****************/    for(i = n; i>0; i--){            f = true;            for(j = i, k = 1; j<=n && k<= len; j++, k++ ){                if(str[j][k] == 'R' || str[j][k] == 'G'){                    f = false ;                }                if(!f && (str[j][k]!='R' && str[j][k] != 'G')){                    ans1 ++;                    f = true;                }            }           if(!f) ans1++;    }    for(int j=2; j<=len; j++){            f = true;            for(i  = 1, k = j; i<=n && k<= len; i++, k++ ){                if(str[i][k] == 'R' || str[i][k] == 'G'){                        f = false ;                }                if(!f && (str[i][k]!='R' && str[i][k] != 'G')){                    ans1 ++;                    f = true;                }            }           if(!f) ans1++;    }    /**************求'/B'方式*****************/    int ans2 = 0;    for(int i= 1; i<=len; i++){        f = true;        for(int j = i, k =1; j>0 && k<=n; k++, j--){            if(str[k][j] == 'B' || str[k][j] == 'G'){                f = false;            }            if(!f && (str[k][j]!='B' && str[k][j] != 'G')){                ans2 ++;                f = true;            }        }        if(!f) ans2++;    }    for(int i= 2; i<=n; i++){        f = true;        for(int j = i, k =len; j<=n && k>0; k--, j++){            if(str[j][k] == 'B' || str[j][k] =='G'){                f = false;            }           if(!f && (str[j][k]!='B' && str[j][k] != 'G')){                ans2 ++;                f = true;            }        }        if(!f) ans2++;    }    return ans1 + ans2;}int main(){    int t, n;    s(t);    w(t--){        s(n);        for(int i=1; i<=n; i++){              scanf("%s", str[i] + 1);        }        int len = strlen(str[1] + 1);        int ans = solve(n, len);        cout<<ans<<endl;    }    return 0;}


1 0
原创粉丝点击