1.
Good 30% int main() { string s; while(cin>>s) { vector<char>v; for(int i=0;i<s.size();i++) { if(s[i]=='G' || s[i]=='o' || s[i]=='d') v.push_back(s[i]); } if(v.size()<=3) cout<<0<<endl; else { vector<int>visited(v.size(),0); int count=0; for(int i=0;i<v.size();i++) if(visited[i]==0&&v[i]=='G') { for(int j=i+1;j<v.size();j++) if(visited[j]==0 && v[j]=='o' ) { for(int k=j+1;k<v.size();k++) if(visited[k]==0 && v[k]=='o') { for(int p=k+1;p<v.size();p++) { if( visited[p]==0 && v[p]=='d') { count++; visited[i]=1; visited[j]=1; visited[k]=1; visited[p]=1; } } } } } cout<<count<<endl; } } }2.AC
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> #define fir first #define se second #define ll long long #define pb push_back #define mp make_pair #define ull unsigned long long #define cl(a, b) memset(a, b, sizeof(a)) #define quickio(a) ios::sync_with_stdio(a) #define datatest() freopen("data.in", "r", stdin) #define makeans() freopen("data.out", "w", stdout) #define makedata() freopen("data.in", "w", stdout) #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<double, double> using namespace std; const int maxn = 1000 + 10; const int maxm = 1e6 + 10; const int inf = 0x3f3f3f3f; const ll mod = 1e9 + 7; const int maxblock = sqrt(maxn) + 10; const double eps = 1e-7; const ll INF = 1e16; struct Edge { int u, v, next; } edge[maxn * maxn * 4]; int head[maxn * maxn]; int tot = 0; int in[maxn * maxn]; void init() { cl(head, -1); cl(in, 0); tot = 0; } void addedge(int u, int v) { edge[tot] = Edge{u, v, head[u]}; head[u] = tot++; in[v]++; } int n, m; int a[maxn][maxn]; int id[maxn][maxn]; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int legal(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); } int dp[maxn * maxn]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]); } int now_id = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) id[i][j] = ++now_id; } init(); for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { for (int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if (legal(xx, yy) && a[x][y] < a[xx][yy]) { addedge(id[x][y], id[xx][yy]); } } } } std::queue<int> q; cl(dp, 0); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (!in[id[i][j]]) { q.push(id[i][j]); dp[id[i][j]] = 1; } } } int Max = 0; while (!q.empty()) { int u = q.front(); q.pop(); Max = std::max(Max, dp[u]); for (int i = head[u]; ~i; i = edge[i].next) { int v = edge[i].v; dp[v] = std::max(dp[v], dp[u] + 1); in[v]--; if (!in[v]) { q.push(v); } } } printf("%d\n", Max); return 0; }
全部评论
(0) 回帖