URAL - 1901 Space Elevators
题目:
Input
Output
Example
| input | output |
|---|---|
6 6 |
5 |
思路:先排序,然后贪心的选人获得最大运行次数。
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,mx,v[],vis[],ans[];
int main(void)
{
scanf("%d%d",&n,&mx);
for(int i=;i<=n;i++)
scanf("%d",&v[i]);
sort(v+,v++n);
int sum=,l=,r=n;
while(l<r)
{
while(l<r && v[l]+v[r]<=mx) l++;
if(l>=r)break;
ans[sum++]=v[l],vis[l++]=;
ans[sum++]=v[r],vis[r--]=;
}
for(int i=n;i;i--)if(!vis[i])
ans[sum++]=v[i];
sum=;
for(int i=;i<=n;i++)
if(ans[i]+ans[i+]>mx)sum++;
else sum++,i++;
printf("%d\n",sum);
for(int i=;i<=n;i++)
printf("%d ",ans[i]);
return ;
}
URAL - 1901 Space Elevators的更多相关文章
- URAL 2099 Space Invader题解 (计算几何)
啥也不说了,直接看图吧…… 代码如下: #include<stdio.h> #include<iostream> #include<math.h> using na ...
- ural 1075. Thread in a Space
1075. Thread in a Space Time limit: 1.0 secondMemory limit: 64 MB There are three points in a 3-dime ...
- URAL 1775 B - Space Bowling 计算几何
B - Space BowlingTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2065. Different Sums
2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...
- ural 1249. Ancient Necropolis
1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bit ...
- ural 1072. Routing
1072. Routing Time limit: 1.0 secondMemory limit: 64 MB There is a TCP/IP net of several computers. ...
- ural 1071. Nikifor 2
1071. Nikifor 2 Time limit: 1.0 secondMemory limit: 64 MB Nikifor has a number x. He doesn't need it ...
随机推荐
- servlet里面拿到common.property的属性
---------------------common.property文件----------------------- kongxc_wx_dinghuo_orderSendMusic=http: ...
- PAT002 Reversing Linked List
题目: Given a constant K and a singly linked list L, you are supposed to reverse the links of every K ...
- 目标跟踪之卡尔曼滤波---理解Kalman滤波的使用
http://www.cnblogs.com/jcchen1987/p/4371439.html
- 使用html替代excel导出数据的优势和技巧
之前一直使用NPOI或者微软office官方组件导出excel,但是多多少少会有写小问题,不是数据量不能过大(xls的问题,用xlsx就可以更大了),就是速度慢,或者文件体积太大 中途采用过csv(逗 ...
- ACM 博弈(难)题练习 (第一弹)
第二弹: 套路&&经验总结: 1. N堆***的游戏,一般可以打表找SG函数的规律.比如CodeForces 603C 2.看起来是单轮的游戏,实际上可能拆分成一些独立的子游戏.比如C ...
- 面试题思考:Stack和Heap的区别
堆栈的概念: 堆栈是两种数据结构.堆栈都是一种数据项按序排列的数据结构,只能在一端(称为栈顶(top))对数据项进行插入和删除.在单片机应用中,堆栈是个特殊的存储区,主要功能是暂时存放数据和地址,通常 ...
- JZOJ.5257【NOIP2017模拟8.11】小X的佛光
Description
- java pdf 导出方案
java代码 import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.BaseFont; import org ...
- Windows(7)上那些好用的软件及优化技巧(原创)
*本文为原创内容,转载请注明作者和出处:www.cnblogs.com/wang1024 软件篇 注:以下软件在百度直接搜索软件名均可找到官网,直接官网下载即可 大众的软件哪个好: 杀毒软件专题 基于 ...
- JAVA 集合相关整理和学习
一.Set接口实现类 二.List接口实现类 三.Queue接口实现类 四.Map接口实现类 五.上面的图片截自附件: 附件列表