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 ...
随机推荐
- easyui- grid前台分页
function pagerFilter(data) { if (typeof data.length == 'number' && typeof data.splice == 'fu ...
- css3 一个简单的静态立方体
<meta charset="utf8"> <style> .cube { position: absolute; left: 50%; top: 250p ...
- Tensorflow之合并tensor
https://www.tensorflow.org/versions/r0.12/api_docs/python/array_ops.html#concat 例子: t1 = [[1, 2, 3], ...
- js事件循环机制(Event Loop)
javascript从诞生之日起就是一门 单线程的 非阻塞的 脚本语言,单线程意味着,javascript代码在执行的任何时候,都只有一个主线程来处理所有的任务,非阻塞靠的就是 event lo ...
- shell基础(二)
echo命令 Shell 的 echo 指令是用于字符串的输出. #!/bin/sh read name #读取标准输入的行 echo "$name It is a test" e ...
- 第七篇:两个经典的文件IO程序示例
前言 本文分析两个经典的C++文件IO程序,提炼出其中文件IO的基本套路,留待日后查阅. 程序功能 程序一打印用户指定的所有文本文件,程序二向用户指定的所有文本文件中写入数据. 程序一代码及其注释 # ...
- IOS控件:计算文字长度(UITextField,UILabel对象 和 IBAction)
#import <UIKit/UIKit.h> // UIViewController类为程序提供了基本的视图管理模块 @interface NavControllerViewContro ...
- 浅述python中range()函数的用法
函数用法说明: 用法一:range(m) 输出: [0,1,...,m-1](从0到m-1的一个list,不包括m) 示例: 用法二:range(m,n),m<n 输出:[m,m+1,..,n- ...
- window下搭建python开发环境
搭建一个python开发环境比较简单,所以就稍微记录一下. 1.下载python然后安装 2.配置环境变量 3.在eclipse添加PyDev插件 1.下载python 官网:https://www. ...
- MonogoDB----Date()
以字符串或日期对象的形式返回日期. 使用new Date(),插入的是一个isodate类型:而使用Date()插入的是一个字符串类型. 那isodate是什么日期类型的?我们看这2个值,它比字符串大 ...