第十届蓝桥杯大赛软件类决赛C/C++大学A组 试题 A: 三升序列
算出718207
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,b) for(ll i=a;i<=b;i++) #define per(i,a,b) for(ll i=a;i>=b;i--) #define V vector #define pb push_back char mp[55][55]; int main(){ ll n=30,m=50; rep(i,1,n){ rep(j,1,m){ cin>>mp[i][j]; } } ll ans=0; rep(i,1,n){ rep(j,1,m){ rep(k,j+1,m){ rep(l,k+1,m){ if(mp[i][j]<mp[i][k]&&mp[i][k]<mp[i][l])ans++;//,cout<<'!'<<i<<' '<<j<<endl; } } } } rep(j,1,m){ rep(i,1,n){ rep(k,i+1,n){ rep(l,k+1,n){ if(mp[i][j]<mp[k][j]&&mp[k][j]<mp[l][j])ans++;//,cout<<'@'<<i<<' '<<j<<endl; } } } } rep(it,1,n){ rep(itt,1,m){ for(ll i=it,j=itt;i<=n&&j>=1;i++,j--){ for(ll ii=i+1,jj=j-1;ii<=n&&jj>=1;ii++,jj--){ for(ll iii=ii+1,jjj=jj-1;iii<=n&&jjj>=1;iii++,jjj--){ if(mp[i][j]<mp[ii][jj]&&mp[ii][jj]<mp[iii][jjj])ans++;//,cout<<'a'<<' '<<i<<' '<<j<<endl; else if(mp[i][j]>mp[ii][jj]&&mp[ii][jj]>mp[iii][jjj])ans++;//,cout<<'b'<<' '<<i<<' '<<j<<endl; } } } } } rep(it,1,n){ rep(itt,1,m){ for(ll i=it,j=itt;i<=n&&j<=m;i++,j++){ for(ll ii=i+1,jj=j+1;ii<=n&&jj<=m;ii++,jj++){ for(ll iii=ii+1,jjj=jj+1;iii<=n&&jjj<=m;iii++,jjj++){ if(mp[i][j]<mp[ii][jj]&&mp[ii][jj]<mp[iii][jjj])ans++;//,cout<<'c'<<' '<<i<<' '<<j<<endl; else if(mp[i][j]>mp[ii][jj]&&mp[ii][jj]>mp[iii][jjj])ans++;//,cout<<'d'<<' '<<i<<' '<<j<<endl; } } } } } cout<<ans<<endl; }