SRM 504

250pts

#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <string> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <algorithm> using namespace std; class MathContest { public: int countBlack(string ball, int rep) { string pat; int n=ball.length()*rep; int i; for(i=0;i<rep;i++) pat+=ball; int p=0,c=0; int ret=0; int p1=0,p2=n-1; for(i=0;i<n;i++){ if(p==0){ if(pat[p1]=='B'){ if(c==0){ ret++; p1++; c=(c+1)%2; } else{ p1++; p=(p+1)%2; } } else{ if(c==1){ ret++; p1++; c=(c+1)%2; } else{ p1++; p=(p+1)%2; } } } else{ if(pat[p2]=='B'){ if(c==0){ ret++; p2--; c=(c+1)%2; } else{ p2--; p=(p+1)%2; } } else{ if(c==1){ ret++; p2--; c=(c+1)%2; } else{ p2--; p=(p+1)%2; } } } } return ret; } }; 

500pts,仔细想想是个比较简单的题,为何比赛时做不出?

#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <string> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <algorithm> using namespace std; #define MAXN 52 #define MOD (1000000007) char mat[MAXN][MAXN]; int num[MAXN][MAXN]; char tmp[MAXN][MAXN]; class AlgridTwo { public: int makeProgram(vector <string> output) { memset(mat,0,sizeof(mat)); memset(num,0,sizeof(num)); memset(tmp,0,sizeof(tmp)); int n,m; n=output.size(); m=output[0].length(); int i,j; for(i=0;i<n;i++) for(j=0;j<m;j++) if(output[i][j]=='B') tmp[i][j]=mat[i][j]=1; char flag=1; int ret=0; for(i=0;i<=n-2&&flag;i++){ num[i+1][0]=1; tmp[i+1][0]=-1; for(j=0;j<=m-2&&flag;j++){ if(mat[i][j]==0&&mat[i][j+1]==0){ //WW if(tmp[i+1][j]==-1||tmp[i+1][j]==mat[i+1][j]) num[i+1][j+1]=1; else{flag=0;break;} } if(mat[i][j]==1&&mat[i][j+1]==1){ // BB num[i+1][j+1]=num[i+1][j]; num[i+1][j]=1; tmp[i+1][j+1]=tmp[i+1][j]; } if(mat[i][j]==1&&mat[i][j+1]==0){ //BW num[i+1][j]=num[i+1][j+1]=2; tmp[i+1][j+1]=1; if(mat[i+1][j]!=1){flag=0;break;} } if(mat[i][j]==0&&mat[i][j+1]==1){ //WB num[i+1][j+1]=num[i+1][j]=2; tmp[i+1][j+1]=0; if(mat[i+1][j]!=0){flag=0;break;} } } if(j==m-1){ if(tmp[i+1][j]!=-1&&tmp[i+1][j]!=mat[i+1][j]){ flag=0;break; } } } if(flag){ ret=1; for(i=1;i<n;i++) for(j=0;j<m;j++){ ret*=num[i][j]; if(ret>=MOD) ret-=MOD; } return (ret%MOD); } else return ret; } }; 

 

你可能感兴趣的:(c,vector,String,Class,ini,output)