博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5073 Galaxy(2014acm鞍山亚洲分部 C)
阅读量:6082 次
发布时间:2019-06-20

本文共 3393 字,大约阅读时间需要 11 分钟。

主题链接: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): 768    Accepted Submission(s): 179
Special Judge


Problem Description
Good news for us: to release the financial pressure, the government started selling galaxies and we can buy them from now on! The first one who bought a galaxy was Tianming Yun and he gave it to Xin Cheng as a present.
To be fashionable, DRD also bought himself a galaxy. He named it Rho Galaxy. There are n stars in Rho Galaxy, and they have the same weight, namely one unit weight, and a negligible volume. They initially lie in a line rotating around their center of mass.
Everything runs well except one thing. DRD thinks that the galaxy rotates too slow. As we know, to increase the angular speed with the same angular momentum, we have to decrease the moment of inertia.
The moment of inertia I of a set of n stars can be calculated with the formula
where w
i is the weight of star i, d
i is the distance form star i to the mass of center.
As DRD’s friend, ATM, who bought M78 Galaxy, wants to help him. ATM creates some black holes and white holes so that he can transport stars in a negligible time. After transportation, the n stars will also rotate around their new center of mass. Due to financial pressure, ATM can only transport at most k stars. Since volumes of the stars are negligible, two or more stars can be transported to the same position.
Now, you are supposed to calculate the minimum moment of inertia after transportation.
 

Input
The first line contains an integer T (T ≤ 10), denoting the number of the test cases.
For each test case, the first line contains two integers, n(1 ≤ n ≤ 50000) and k(0 ≤ k ≤ n), as mentioned above. The next line contains n integers representing the positions of the stars. The absolute values of positions will be no more than 50000.
 

Output
For each test case, output one real number in one line representing the minimum moment of inertia. Your answer will be considered correct if and only if its absolute or relative error is less than 1e-9.
 

Sample Input
 
2 3 2 -1 0 1 4 2 -2 -1 1 2
 

Sample Output
 
0 0.5
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:            
 

 |   |   | 

#include
#include
#include
#include
#include
#define MAXN 50100using namespace std;int T,N,K;int pos[MAXN],sum[MAXN],x[MAXN],First,Last;double DL,DR,mass;int PL,PR,need;double ans,NowI;double GetNext(){ double ret=NowI; double pmass=mass; mass=(sum[Last+1]-sum[First]+0.0)/need; NowI+=-(pmass-pos[First])*(pmass-pos[First])+(mass-pos[Last+1])*(mass-pos[Last+1]); NowI+=(mass-pmass)*(mass-pmass)*(need-1); DL-=(pmass-pos[First]); Last++;First++; int t=PL-First+1; NowI+=2*DL*(mass-pmass); DL+=(mass-pmass)*t; PL++; while(PL<=N && pos[PL]<=mass){ DL+=fabs(mass-pos[PL]); DR-=fabs(pmass-pos[PL]); NowI+=(mass-pos[PL])*(mass-pos[PL]); NowI-=(pmass-pos[PL])*(pmass-pos[PL]); NowI-=(mass-pmass)*(mass-pmass); PL++; } NowI+=2*(pmass-mass)*DR; DR+=(pos[Last]-mass); PL--; DR-=(mass-pmass)*(Last-(PL+1)); return NowI;}int main(){// freopen("in.txt","r",stdin); scanf("%d",&T); while(T--){ scanf("%d%d",&N,&K); for(int i=0;i

转载地址:http://urzwa.baihongyu.com/

你可能感兴趣的文章
javafx for android or ios ?
查看>>
微软职位内部推荐-Senior Software Engineer II-Sharepoint
查看>>
sql 字符串操作
查看>>
【转】Android布局优化之ViewStub
查看>>
网络安全管理技术作业-SNMP实验报告
查看>>
根据Uri获取文件的绝对路径
查看>>
Flutter 插件开发:以微信SDK为例
查看>>
.NET[C#]中NullReferenceException(未将对象引用到实例)是什么问题?如何修复处理?...
查看>>
边缘控制平面Ambassador全解读
查看>>
Windows Phone 7 利用计时器DispatcherTimer创建时钟
查看>>
程序员最喜爱的12个Android应用开发框架二(转)
查看>>
vim学习与理解
查看>>
DIRECTSHOW在VS2005中PVOID64问题和配置问题
查看>>
MapReduce的模式,算法以及用例
查看>>
《Advanced Linux Programming》读书笔记(1)
查看>>
zabbix agent item
查看>>
一步一步学习SignalR进行实时通信_7_非代理
查看>>
AOL重组为两大业务部门 全球裁员500人
查看>>
字符设备与块设备的区别
查看>>
为什么我弃用GNOME转向KDE(2)
查看>>