当前位置: 代码迷 >> 综合 >> Canada Cup 2016 A.Jumping Ball并查集 .
  详细解决方案

Canada Cup 2016 A.Jumping Ball并查集 .

热度:73   发布时间:2023-09-23 05:15:36.0
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(b);++i)
#define REPD(i,a,b) for(int i=a;i>=(b);--i)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
int p[200000+5];
int find(int x){return x==p[x]?x:p[x]=find(p[x]);
}
char s[200000+5];
int main(int argc, char const *argv[])
{int n; scanf("%d",&n);scanf("%s",s+1);REP(i,0,n+1) p[i]=i;for(int i=1;s[i];++i){if(s[i]=='<') p[i]=p[i-1];else p[i]=p[i+1];}int cnt=0;for(int i=1;s[i];++i){int f=find(i);if(f<=0||f>n) cnt++;}printf("%d\n", cnt);return 0;
}