zoukankan      html  css  js  c++  java
  • sgu114Telecasting station

    题意:在X轴上有N个城市,每个城市的坐标为Xi,每个城市的人有pi个,每个城市的不满意度为发射塔到这个城市的距离乘以这个城市的人数,求发射塔在那个位置才能使所有城市的不满意度之和最小.

    分析:我们可知若每个城市的人数都是一个,则中间位置是最佳位置,但这题xi城市有pi人,我们可以把他们看成有pi个城市xi,每个城市1人...故我们就可以很好求解了.所以我们将城市按位置排序,然后从左到右累加城市的人数的和S,直到S大于等于总人数的一半,即这个城市是最佳位置放置发射塔.

    // File Name: 114.cpp
    // Author: Zlbing
    // Created Time: 2013/3/27 14:30:09
    
    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<cstdlib>
    #include<cstdio>
    #include<set>
    #include<map>
    #include<vector>
    #include<cstring>
    #include<stack>
    #include<cmath>
    #include<queue>
    using namespace std;
    #define CL(x,v); memset(x,v,sizeof(x));
    #define INF 0x3f3f3f3f
    #define LL long long
    #define REP(i,r,n) for(int i=r;i<=n;i++)
    #define RREP(i,n,r) for(int i=n;i>=r;i--)
    const int MAXN=2e4;
    struct node{
        double x,p;
        bool operator <(const node& a)const{
            return x<a.x;
        }
    }point[MAXN];
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            double a,b;
            double sum=0;
            REP(i,1,n)
            {
                scanf("%lf%lf",&a,&b);
                point[i].x=a;
                point[i].p=b;
                sum+=b;
            }
            sort(point+1,point+n+1);
            double c=0;
            REP(i,1,n)
            {
                c+=point[i].p;
                if(c*2-sum>1e-9){
                    printf("%lf\n",point[i].x);
                    return 0;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    C#实现京东登录密码加密POST
    查询SQL Server数据库所有表字段备注
    DataGridView数值列和日期列
    (转)Android 系统 root 破解原理分析
    Dynamics AX 中重点数据源方法
    .NET中Debug模式与Release模式
    DotNetBar的初步使用
    省市区联动小功能
    多余的Using Namespaces或引用会影响程序的执行效率么?
    MSIL指令集
  • 原文地址:https://www.cnblogs.com/arbitrary/p/2984647.html
Copyright © 2011-2022 走看看