JZOJ 3845. 简单题(simple)
题目
分析
- 我们易得美丽仙人掌一定是一条链 并且上面很多的环
- 对于一条边 我们需要纪录几个信息
- x+1==y 如果不是那么他的环指向哪里
- 然后我们枚举每个点作为起点
- 找一条链 每次往里面找环每次把环变得尽量小
代码
1 #include <cmath> 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #define ll long long 7 using namespace std; 8 int last[100010],nxt[100010]; 9 struct sb 10 { 11 int x,y; 12 }a[100010]; 13 bool cmp(sb a,sb b){return a.x<b.x;} 14 int main() 15 { 16 int n,m; 17 scanf("%d%d",&n,&m); 18 memset(last,0x7f,sizeof(last)) ; 19 for (int i=1,x,y;i<=m;i++) 20 { 21 scanf("%d%d",&x,&y); 22 if (x>y) swap(x,y); 23 if (y==x+1&&nxt[x]==1) last[x]=y; 24 if (y==x+1) nxt[x]=1; 25 if (y<last[x]&&y!=x+1) last[x]=y; 26 } 27 int ans=0; 28 for (int i=1;i<=n;i++) 29 { 30 int j=i,cnt=0,x=i,tot=0,l=0; 31 for (;nxt[j];j++) 32 { 33 a[++tot].x=last[j]; 34 a[tot].y=j; 35 } 36 sort(a+1,a+1+tot,cmp); 37 for (int k=1;k<=tot;k++) 38 { 39 if (a[k].y>=l&&a[k].x<=999999999) 40 { 41 l=a[k].x; 42 cnt++; 43 } 44 } 45 ans=max(ans,j-i+cnt); 46 i=j; 47 } 48 cout<<ans; 49 return 0; 50 }
为何要逼自己长大,去闯不该闯的荒唐