标签:tps c代码 有一个 const code problem vector point algo
题意:平面坐标上有n个怪物,每个怪物有一个rank值,代表x坐标和y坐标都不大于它本身的怪物数(不包括本身)
思路:对x y坐标从小到大排序,x优先排序,用数状数组计算y坐标小于它的数量
AC代码:
#include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #define ll long long #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a) memset(a,0,sizeof(a)) #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8; const int N=1e5+100; const ll mod=1e9+7; struct Point{ int x, y; bool friend operator< (Point a, Point b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x; } }; Point P[N]; int n,ma,Y[N],ans[N]; int lowbit(int x){ return (-x)&x; } void add(int y, int num){ while(y<=ma){ Y[y]+=num; y+=lowbit(y); } } int sum(int y){ int ret=0; while(y>0){ ret+=Y[y]; y-=lowbit(y); } return ret; } int main(){ //ios::sync_with_stdio(false),cin.tie(0);cout.tie(0); cin>>n; for(int i=1; i<=n; ++i){ cin>>P[i].x>>P[i].y; ma=max(ma,P[i].y), ma=max(ma,P[i].y); } sort(P+1,P+1+n); for(int i=1; i<=n; ++i){ int cnt=sum(P[i].y); ans[cnt]++; add(P[i].y,1); } for(int i=0; i<n; ++i){ cout<<ans[i]<<"\n"; } return 0; }
标签:tps c代码 有一个 const code problem vector point algo
原文地址:http://www.cnblogs.com/max88888888/p/7223172.html