为防止广告,目前nocow只有登录用户能够创建新页面。如要创建页面请先登录/注册(新用户需要等待1个小时才能正常使用该功能)。
Sgu/133
来自NOCOW
< Sgu
排序+扫描
#include <stdio.h> #include <algorithm> using namespace std; struct range { int x, y; } P[16000]; int n, j, cnt = 1; bool cmp(const range& a, const range& b) { return (a.x < b.x || a.x == b.x && a.y < b.y); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d %d", &P[i].x, &P[i].y); sort(P, P + n, cmp); j = 0; for (int i = 1; i < n; ++i) if (P[i].x == P[j].x || P[i].y >= P[j].y) { j = i; cnt++; } printf("%d", n - cnt); return 0; } // From FingerSed
//by hza #include<cstdio> const int MAX=16000+10; int n,answer; int a[MAX],b[MAX]; int num[MAX*2],belong[MAX*2],lable[MAX*2],top=0; void swap(int &a,int &b) { int t=a;a=b;b=t; } void qsort(int l,int r) { int i=l,j=r; a[0]=a[(l+r)/2];b[0]=b[(l+r)/2]; while(i<=j) { while(a[i]<a[0]||(a[i]==a[0]&&b[i]>b[0]))++i; while(a[0]<a[j]||(a[0]==a[j]&&b[0]>b[j]))--j; if(i<=j) { swap(a[i],a[j]); swap(b[i],b[j]); ++i;--j; } } if(i<r)qsort(i,r); if(l<j)qsort(l,j); } int main() { freopen("133.in","r",stdin); freopen("133.out","w",stdout); int i; scanf("%d\n",&n); for(i=1;i<=n;++i) scanf("%d %d",&a[i],&b[i]); qsort(1,n); a[0]=-1; int max=-1,last_max=-1; for(i=1;i<=n;++i) { if(a[i]!=a[i-1]) { if(last_max>max)max=last_max; last_max=0; } if(b[i]<max)++answer; if(b[i]>last_max)last_max=b[i]; } printf("%d\n",answer); }
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int size = 16666; struct Node { int a, b; bool friend operator< (Node x, Node y) { return x.a < y.a; } }node[size]; int main() { int n, ans = 0, maxn = -1; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d", &node[i].a, &node[i].b); sort(node, node + n); for (int i = 0; i < n; i++) { if (node[i].b < maxn) ans++; else maxn = node[i].b; } printf("%d\n", ans); return 0; } //by phonism
//by a710128 #include<iostream> #include<algorithm> using namespace std; struct Pair { int l,r; bool operator < (const Pair &b) const {if(l!=b.l) return l<b.l;return r>b.r;} }sz[16005]; int n; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>sz[i].l>>sz[i].r; sort(sz+1,sz+n+1); int maxl=sz[1].r,out=1; for(int i=2;i<=n;i++) if(sz[i].r>=maxl) { out++; maxl=sz[i].r; } cout<<n-out; return 0; }