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 ...
随机推荐
- oracle 手动 备份 恢复
手工备份, 我只考虑全备, 即 control file, redo log file, datafile, password file, spfile(pfile), listener.ora, t ...
- SQL2005 第一次配置没有服务器名称的问题
问题描述:第一次启动没有服务器名称 解决方法: 1.进入 我的电脑——属性——管理——服务 找到SQL Server 右键属性 弹出下图 找到可执行文件路径 鼠标左键拖到底部 看到 -s实例名,这里的 ...
- 2014-04-17-网易有道-研发类-笔试题&參考答案
一套卷子,共10道小题,3道编程大题 一.填空&选择 1.选择:给了一个递归求Fibonacci的代码,问算法复杂度 指数复杂度 2.选择:忘记了,应该不难 3.选择:给你52张除掉大小王的扑 ...
- db2 sql
import from empty.del of replace into table_name
- 用ChemDraw画3D图的方法
在绘制化学图形的时候,很多的用户都会发现很多的图形都是三维的,这个时候就需要找一款能够绘制3D图形的化学绘图软件.ChemOffice 15.1是最新的化学绘图工具套件,总共有三个组件,其中ChemD ...
- JUnit小记
一.参数测试 /** * 1.更改测试运行器为RunWith(Parameterized.class) * 2.声明变量用来存放预期值与结果值 * 3.为测试类声明一个带有参数的公共构造方法,并在其中 ...
- Linux下tomcat相关操作
tomcat安装: 直接到官网下载tar包解压即可. tomcat相关操作: 首先,进入Tomcat下的bin目录,例如:cd /usr/tomcat/bin 启动Tomcat:./startup.s ...
- python 的时间复杂度
Python内置方法的时间复杂度 本文翻译自Python Wiki 本文基于GPL v2协议,转载请保留此协议. 本页面涵盖了Python中若干方法的时间复杂度(或者叫“大欧”,“Big O”).该时 ...
- 搭建一个简单的基于web的网络流量监控可视化系统
本文转载于我的个人博客,转载请标明出处. 初衷 在腾讯云的学生认证申请提交上去n天之后,终于得到了审批,所以迫不及待的想玩玩腾讯云,作为一个搞网络的,自然有一些关于网络应用的小玩意,所以把以前部署过的 ...
- bootstrap-table固定表头固定列
1.引入 bootstrap依赖于jquery bootstrap-table依赖于bootstrap,所以都需要引入 2. bootstrap-table有两种方式,html.js <tabl ...