博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3392 Pie
阅读量:7047 次
发布时间:2019-06-28

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

Pie

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 683    Accepted Submission(s): 188

Problem Description
A lot of boys and girls come to our company to pie friends. After we get their information, we need give each of them an advice for help. We know everyone’s height, and we believe that the less difference of a girl and a boy has, the better it is. We need to find as more matches as possible, but the total difference of the matches must be minimum.
 

 

Input
The input consists of multiple test cases. The first line of each test case contains two integers, n, m (0 < n, m <= 10000), which are the number of boys and the number of girls. The next line contains n float numbers, indicating the height of each boy. The last line of each test case contains m float numbers, indicating the height of each girl. You can assume that |n – m| <= 100 because we believe that there is no need to do with that if |n – m| > 100. All of the values of the height are between 1.5 and 2.0. The last case is followed by a single line containing two zeros, which means the end of the input.
 

 

Output
Output the minimum total difference of the height. Please take it with six fractional digits.
 

 

Sample Input
2 3
1.5 2.0
1.5 1.7 2.0
0 0
 

 

Sample Output
0.000000
 

 

Author
momodi@whu
 

 

Source
 

 

Recommend
notonlysuccess
 
 
 
1 #include
2 #include
3 #include
4 #include
5 #include
6 7 using namespace std; 8 9 int n,m;10 double a[10010],b[10010];11 double dp[2][120];12 13 int main(){14 15 //freopen("input.txt","r",stdin);16 17 while(~scanf("%d%d",&n,&m)){18 if(n==0 && m==0)19 break;20 int i,j,k;21 if(n<=m){22 for(i=1;i<=n;i++)23 scanf("%lf",&a[i]);24 for(i=1;i<=m;i++)25 scanf("%lf",&b[i]);26 }else{27 for(i=1;i<=n;i++)28 scanf("%lf",&b[i]);29 for(i=1;i<=m;i++)30 scanf("%lf",&a[i]);31 int tmp=n;32 n=m;33 m=tmp;34 }35 sort(a+1,a+n+1);36 sort(b+1,b+m+1);37 memset(dp,0,sizeof(dp));38 int len=m-n+1;39 for(i=1;i<=n;i++){40 dp[i%2][1]=dp[(i-1)%2][1]+fabs(a[i]-b[i]);41 for(k=2;k<=len;k++){42 j=i+k-1;43 dp[i%2][k]=min(dp[(i-1)%2][k]+fabs(a[i]-b[j]),dp[i%2][k-1]);44 }45 }46 printf("%.6lf\n",dp[n%2][len]);47 }48 return 0;49 }

 

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

你可能感兴趣的文章
[转]World Wind学习总结一
查看>>
算法题一道
查看>>
滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(4月14日)...
查看>>
iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
查看>>
C# Struct结构体里数组长度的指定
查看>>
感知机原理小结
查看>>
Java动态代理与Cglib库
查看>>
系统性能不够原因可能是cpu不够,内存不够等等
查看>>
让div在另一个div中居中
查看>>
Linux indent
查看>>
dir for RequestHandler and request
查看>>
CoreCLR文档翻译 - GC的设计
查看>>
js-ES6学习笔记-Proxy(2)
查看>>
Spring Boot下Druid连接池+mybatis
查看>>
Session与Cookie解析
查看>>
Java实现二叉排序树的插入、查找、删除
查看>>
Delphi线程定时器TThreadedTimer及用法--还有TThreadList用法可以locklist
查看>>
UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)
查看>>
EventBus In eShop -- 解析微软微服务架构Demo(四)
查看>>
使用Python写的第一个网络爬虫程序
查看>>