URAL 1901 Space Elevators (苦逼水题,2级)
来源:互联网 发布:淘宝客哪个软件好 编辑:程序博客网 时间:2024/06/08 19:05
B - Space Elevators
Crawling in process...Crawling failedTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
Nowadays spaceships are never launched from the Earth's surface. There is a huge spaceport placed in the geostationary orbit and connected to the Earth with carbon nanotube cables. People and cargo are delivered to the orbit by elevators moving along these cables. It turned out that the space elevator is much more comfortable and cheaper than a spaceship.
Tomorrow a group of key employees of the “Akross” corporation will go to the spaceport with a secret mission. The spaceport management has reserved a special double elevator for the group. The Head of “Akross” demanded that at any given time the total importance of staff in the elevator must not exceed some fixed value. Under this condition, even in case of fatal accident the corporation will be able to recover. Employees enter the elevator in turns. The elevator is sent up if two people entered, or if only one person entered and the following person behind him is so significant for the corporation that it is impossible to send them together in one elevator.
The spaceport management wants to know the maximum number of elevator runs required to deliver all employees, so the right amount of oxygen cylinders and charged batteries can be prepared in advance.
Input
The first line contains integers n and s that are the amount of employees of “Akross” assigned to the mission, and the maximum total importance of two employees which can go together in the elevator (1 ≤n ≤ 10 5; 1 ≤ s ≤ 10 9). The second line contains integersv1, …, vn that are the importance of the employees (1 ≤vi ≤ s).
Output
In the first line output the maximum amount of trips of the elevator. In the second line output the importance of staff in order from the first employee in the line to the last, for which the elevator will do this amount of trips. If there are several possible answers, output any of them.
Sample Input
6 61 2 3 3 4 5
52 5 1 3 4 3
好吧:这就是昨晚死扣了两个多小时的题。算法很快就想到了,写程序速度也还行,可惜WA了,
各种找错,最后也没找出来,然后向别人要了个正确的源程序对拍,终于对拍出了一个错误,2e9+2居然会爆,哎我就无语了,改成long long 之后还WA,之后就各种对拍
其实是对拍出问题浪费近一个小时,不知道为什么原先的对拍程序没结束,导致后来的运行都跑原先的程序,哎。。。。。
找出问题后,手动删除,重新对拍,半天没拍出问题,然后,就没有然后了。。。。。。
程序还是WA,不知道思路哪有问题,居然也没拍出来。。。。
第一种思路:先选最小x,找到最小的y,使x+y>s 没有则选择次小,依次找完 无数的WA+苦逼的对拍,没找出问题,但还是WA
第二种思路:先选最小x,找最大y,若x+y<=s则换次小值,依次找完 今天轻松1Y
#include<iostream>#include<cstring>#include<cstdio>#include<map>#include<algorithm>#define FOR(i,a,b) for(int i=a;i<=b;++i)#define LL long longusing namespace std;const int mm=4e5+9;const int oo=3e9+2;map<int,int>mp;map<int,int>::iterator it;int f[mm],n,s,ans[mm],pos;int main(){ while(~scanf("%d%d",&n,&s)) { ans[0]=oo; mp.clear(); mp[oo]=-1; mp[-oo]=-1; FOR(i,1,n) { scanf("%d",&f[i]);//mp[ f[i] ]++; // printf("tt=%d ",i); } sort(f+1,f+n+1); /*pos=1;int z; bool yes=0; while(1) { if(yes) z=s-ans[pos-1]; else z=-1; it=mp.upper_bound(z); // printf("tt=%d %d\n",it->first,it->second); if(it->second<0) { it=mp.upper_bound(-1); if(it->second<0)break; } if(yes&&ans[pos-1]+it->second<=s)yes=0; else yes=1; ans[pos++]=it->first; if(it->second==1)mp.erase(it); else it->second--; } pos--;*/ int l=1,r=n;pos=1; while(l<r) { if(f[l]+f[r]>s)ans[pos++]=f[l++],ans[pos++]=f[r--]; else ans[pos++]=f[l++],ans[pos++]=f[l++]; } //cout<<f[2]<<endl; if(l==r)ans[pos]=f[l]; else pos--; int num=0; int zz=1; while(zz<=pos) { //printf("zz=%d %d\n",ans[zz],ans[zz-1]); LL zs=(LL)ans[zz]+(LL)ans[zz-1]; if(zs>s)++zz,++num; else {++zz;//puts("++"); if(zz>pos)break;++zz;++num; } } printf("%d\n",num); FOR(i,1,pos) printf("%d%c",ans[i],i==pos?'\n':' '); } return 0;}
- URAL 1901 Space Elevators (苦逼水题,2级)
- URAL 1901 Space Elevators(贪心)
- BNUOJ26429 Space Elevators(贪心)
- URAL 1775 Space Bowling
- Google top 10 crazy projects: from Driverless Cars to Elevators to Space (Picture)
- Elevators UVALive
- Elevators UVALive
- URAL 1075. Thread in a Space
- 最短路 hnu13430 Elevators
- URAL 2099 Space Invader 计算几何、卡精度、好题
- URAL 1639 Chocolate 2 (博弈论)
- URAL 1820 Ural Steaks (贪心)
- URAL - 1820 Ural Steaks(小学生题)
- URAL Genie Bomber 2
- ural 1752 Tree 2
- Ural 1362 Classmates 2
- ural 1362Classmates 2
- URAL 1362. Classmates 2
- ubantu 下 php 的安装和配置
- MFC 中 Tooltip 实现的几种方式
- android源码下载新办法
- UIImage转为灰度图
- Alpha值
- URAL 1901 Space Elevators (苦逼水题,2级)
- u-boot nand 驱动
- OpenCV 2 学习笔记(18): 反向投影
- Java NIO系列教程(一) Java NIO 概述
- Flex 4 皮肤功能介绍
- c++ 递归1
- hdu2487(枚举)
- 在MAC下调试运行暗黑世界客户端及部分代码注解(基于Firefly)
- 敏捷测试需注意的五种危险行为