hdu 5073 2014鞍山现场赛题 物理题

http://acm.hdu.edu.cn/showproblem.php?pid=5073

推公式即可,质心公式segma(xi*wi)/segma(wi)

最终剩下的一定是连续n-k个星

然后枚举左边需要移除几个星即可

计算I的时候展开来算

比较坑的地方在于,星星的位置如果是int型,一定记得Double计算的时候 *1.0或者直接将位置数组声明为double  否则WA到死。。。

//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;

#define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double pi = acos(-1.0);
const int INF = 100000000;
const int MAXN = 50000+50;
const double EPS = 1e-14;/////

double pos[MAXN];
int n,k;
double  sum[MAXN],sumpos[MAXN];

double solve()
{
    double tmp=0.0;
    double ans=1000000000000000000.0;
    if(n==k)return 0.0;
    for(int left=0;left<=k;left++)
    {
        tmp=sum[n-k+left]-sum[left];
        double spp=sumpos[n-k+left]-sumpos[left];
        double d;
        d=spp/(1.0*n-k);
        double ret=tmp-2*spp*d+(n-k)*d*d;
        if(left)
        {
            ans=min(ans,ret);
        }
        else
            ans=ret;
    }
    return ans;
}

int main()
{
    //IN("hdu5073.txt");
    int ncase;
    scanf("%d",&ncase);
    while(ncase--)
    {
        scanf("%d%d",&n,&k);
        sum[0]=0.0;
        sumpos[0]=0.0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf",&pos[i]);
        }
        sort(pos+1,pos+n+1);
        for(int i=1;i<=n;i++)
        {
            sum[i]=sum[i-1]+pos[i]*pos[i];
            sumpos[i]=sumpos[i-1]+pos[i];
        }
        printf("%.14lf\n",solve());
    }
    return 0;
}
时间: 2024-10-04 03:59:29

hdu 5073 2014鞍山现场赛题 物理题的相关文章

hdu 5078 2014鞍山现场赛 水题

http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,因为说了ti<ti+1 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include &l

hdu 5078(2014鞍山现场赛 I题)

数据 表示每次到达某个位置的坐标和时间 计算出每对相邻点之间转移的速度(两点间距离距离/相隔时间) 输出最大值 Sample Input252 1 9//t x y3 7 25 9 06 6 37 6 01011 35 6723 2 2929 58 2230 67 6936 56 9362 42 1167 73 2968 19 2172 37 8482 24 98 Sample Output9.219544457354.5893762558 1 # include <iostream> 2 #

HDU 5073 Galaxy (2014鞍山现场赛D题)

题目链接:HDU 5073 Galaxy 题意:在一维的坐标系里,给出N个点坐标,转动K个点,使转动后这个星系的的惯性最小(根据题意惯性最小也就是 求所有星星到星系中心的距离最小,这个可以理解成方差最小).求最小的惯性. 思路: 先对序列排序,再求出算N-K个点惯性的递推式. 以三个为例: 预处理是 平均数和各项的平方和, 注意:n==k的特判 AC代码: #include <stdio.h> #include <algorithm> using namespace std; do

hdu 5074 DP 2014鞍山现场赛题

hdu 5074 http://acm.hdu.edu.cn/showproblem.php?pid=5074 挺水的DP,注意依a[i-1]和a[i]的正负区分状态转移,然后O(n^3)即可轻易解决,我DP挺弱的也能过,貌似也就CF C题水平 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algo

hdu 5073 Galaxy(2014 鞍山现场赛)

Galaxy                                                                   Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 577    Accepted Submission(s): 132 Special Judge Problem Description G

hdu5074 Hatsune Miku 2014鞍山现场赛E题 水dp

http://acm.hdu.edu.cn/showproblem.php?pid=5074 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 325    Accepted Submission(s): 243 Problem Description Hatsune Miku is a popular vi

hdu5072 Coprime 2014鞍山现场赛C题 计数+容斥

http://acm.hdu.edu.cn/showproblem.php?pid=5072 Coprime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 354    Accepted Submission(s): 154 Problem Description There are n people standing in a

hdu5073 2014鞍山现场赛D题

http://acm.hdu.edu.cn/showproblem.php?pid=5073 Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1421    Accepted Submission(s): 324 Special Judge Problem Description Good news for us: t

2014鞍山现场赛H题HDU5077(DFS减枝+打表)

NAND Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 65    Accepted Submission(s): 14 Problem Description Xiaoqiang entered the "shortest code" challenge organized by some self-claimed a