HDOJ 1050 Moving Tables(经典贪心)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了HDOJ 1050 Moving Tables(经典贪心),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3156字,纯文字阅读大概需要5分钟。
内容图文
![HDOJ 1050 Moving Tables(经典贪心)](/upload/InfoBanner/zyjiaocheng/1109/97eaf209ff43402b8ab6f0d987cfa863.jpg)
Moving Tables
![技术分享](http://acm.hdu.edu.cn/data/images/1050-1.gif)
The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
![技术分享](http://acm.hdu.edu.cn/data/images/1050-2.gif)
For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
10 20 30
<span style="font-size:14px;">#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int t,n,count[410],i,start,end,k; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(count,0,sizeof(count)); while(n--) { scanf("%d%d",&start,&end); if(start>end)//可能出发位置比目的地房间大。 { //无论大小,我们都可以看做从小的房间移动到大的房间 k=start; start=end; end=k; } if(start%2==0)//考虑实际情况,出发房间为偶数是减一,可参照题中给出的图一 start-=1; if(end%2==1)//目的地房间为奇数时加一 end+=1; for(i=start;i<=end;++i) count[i]+=10; } printf("%d\n",*max_element(count,count+400));//STL中寻找数列最大值函数 } return 0; } </span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/zwj1452267376/article/details/47763589
内容总结
以上是互联网集市为您收集整理的HDOJ 1050 Moving Tables(经典贪心)全部内容,希望文章能够帮你解决HDOJ 1050 Moving Tables(经典贪心)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。