标签:iostream amp ref lan 报告 ++ visit ons tar
1 /* 2 problem:yibentong10000 3 date:2019/4/21 4 author:Lonely. 5 */ 6 7 #include<iostream> 8 #include<cstdio> 9 #include<cstring> 10 #include<algorithm> 11 using namespace std; 12 const int maxn = 1e3+5; 13 struct node{ 14 int s,f,dif; 15 }; 16 node a[maxn]; 17 int n,ans; 18 inline void init(){ 19 cin>>n; 20 for(int i =1;i <= n;i++)scanf("%d%d",&a[i].s,&a[i].f); 21 } 22 inline bool cmp(node x,node y){ 23 return x.f < y.f; 24 } 25 int main(){ 26 init(); 27 sort(a+1,a+1+n,cmp); 28 ans = 1; 29 int tmp = a[1].f; 30 for(int i = 2;i <= n;i++) 31 if(a[i].s >= tmp){ 32 ans++; 33 tmp = a[i].f; 34 } 35 cout<<ans<<endl; 36 return 0; 37 }
T2
1 /* 2 problem:yibentong10001 3 date:2019.4.21 4 author:Lonely. 5 */ 6 7 #include<iostream> 8 #include<cstdio> 9 #include<cstring> 10 #include<algorithm> 11 using namespace std; 12 const int maxn = 3e4+5; 13 struct node{ 14 int b,e,t; 15 }a[maxn]; 16 int visit[maxn]; 17 int n,ans,h; 18 inline void init(){ 19 cin>>n; 20 cin>>h; 21 for(int i = 1;i <= h;i++) 22 scanf("%d%d%d",&a[i].b,&a[i].e,&a[i].t); 23 } 24 inline bool cmp(node x,node y){ 25 return x.e < y.e; 26 } 27 int main(){ 28 init(); 29 sort(a+1,a+1+h,cmp); 30 for(int i = 1;i <= h;i++){ 31 int cnt = 0; 32 for(int j = a[i].b;j <= a[i].e;j++) 33 cnt += visit[j]; 34 if(cnt >= a[i].t)continue; 35 for(int j = a[i].e;j >= a[i].b;j--) 36 if(!visit[j]){ 37 visit[j] = 1; 38 cnt++; 39 ans++; 40 if(cnt == a[i].t)break; 41 } 42 } 43 cout<<ans<<endl; 44 return 0; 45 }
标签:iostream amp ref lan 报告 ++ visit ons tar
原文地址:https://www.cnblogs.com/wangyifan124/p/10746540.html