若干城市在一条线上,在这条线上建个转播站,定义城市的不高兴值为城市到转播站的距离*城市人数
给定城市坐标和人数,求最小的不高兴值
如果去掉城市人口就是个很裸很裸的求中位数
因为人口 当时卡了一会儿,实际上可以把它当做若干点是同一坐标,那么也就是一样的求中位数
sort一下就可以了
//Lib #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<ctime> #include<iostream> #include<algorithm> #include<vector> #include<string> #include<queue> using namespace std; //Macro #define rep(i,a,b) for(int i=a,tt=b;i<=tt;++i) #define rrep(i,a,b) for(int i=a,tt=b;i>=tt;--i) #define erep(i,e,x) for(int i=x;i;i=e[i].next) #define irep(i,x) for(__typedef(x.begin()) i=x.begin();i!=x.end();i++) #define read() (strtol(ipos,&ipos,10)) #define sqr(x) ((x)*(x)) #define pb push_back #define PS system("pause"); typedef long long ll; typedef pair<int,int> pii; const int oo=~0U>>1; const double inf=1e20; const double eps=1e-6; string name="",in=".in",out=".out"; //Var pair<double,int> node[15008]; int n,p,tot,pos; double k; void Work() { scanf("%d",&n); rep(i,1,n) { scanf("%lf%d",&k,&p); node[i].first=k;node[i].second=p;tot+=p; } sort(node+1,node+1+n); tot=tot+1>>1; pos=1; while(tot>0&&pos<=n) tot-=node[pos].second,pos++; printf("%.5lf\n",node[pos-1].first); } int main() { // freopen((name+in).c_str(),"r",stdin); // freopen((name+out).c_str(),"w",stdout); // Init(); Work(); return 0; }