汽车加油问题
#include <iostream>
#include <map>using namespace std;int a[100010],b[100010],c[100010],d[100010],n,now,sum,Max;map<int,int>e;int main(){ freopen("sche.in","r",stdin); freopen("sche.out","w",stdout); cin>>n; for(int i=1;i<=n;i++){ scanf("%d%d",&a[i],&b[i]); c[2*i-1]=a[i]; c[2*i]=b[i]; } sort(c+1,c+2*n+1); for(int i=1;i<=2*n;i++) if(!e[c[i]]) e[c[i]]=++now; for(int i=1;i<=n;i++) d[e[a[i]]]++, d[e[b[i]]]--; for(int i=1;i<=now+1;i++) sum+=d[i], Max=max(Max,sum); cout<<Max; fclose(stdin); fclose(stdout); //system("pause"); return 0;}
会场安排问题
#include <iostream>
#include <map>using namespace std;int a[100010],b[100010],c[100010],d[100010],n,now,sum,Max;map<int,int>e;int main(){ freopen("sche.in","r",stdin); freopen("sche.out","w",stdout); cin>>n; for(int i=1;i<=n;i++){ scanf("%d%d",&a[i],&b[i]); c[2*i-1]=a[i]; c[2*i]=b[i]; } sort(c+1,c+2*n+1); for(int i=1;i<=2*n;i++) if(!e[c[i]]) e[c[i]]=++now; for(int i=1;i<=n;i++) d[e[a[i]]]++, d[e[b[i]]]--; for(int i=1;i<=now+1;i++) sum+=d[i], Max=max(Max,sum); cout<<Max; fclose(stdin); fclose(stdout); //system("pause"); return 0;}