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 ...
随机推荐
- sqlserver更新表脚本
--增加项目字段,门店信息,所在省份,所在市,所在区县,提供服务ALTER TABLE [dbo].[school_base_info]ADD [store_information] varchar( ...
- 【转】【CTO俱乐部走进支付宝】探索支付宝背后的那些技术 部分
怎么避免研发环节当中引入漏洞?“我们有一套比较成熟的安全研发开发框架.首先我们用统一的框架,框架本身是经过我们安全工程师去做过非常好的认证的,同时在研发过程当中我们对这些问题也有些规范.一旦发现风险我 ...
- C++ STL标准模板库(stack)
//stack的使用 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<stack> using name ...
- 组件(Conponent)是图形用户界面最基本的部分
组件(Conponent)是图形用户界面最基本的部分,也称为构件 ,是可以以图形化的方式显示在屏幕上,并能与用户进行交互的对象,例如一个按钮,一个标签等. 组件不能独立地显示出来,必须将其放在一定的容 ...
- Codeforces Round #268 (Div. 2) (被屠记)
c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题 ...
- 安装tomcat出现failed to install tomcat6 service错误及解决方法(转载)
安装安装版tomcat会出现failed to install tomcat6 service ,check your setting and permissio的概率是非常低的,但是最近楼主就老出现 ...
- openldap+php-ldap操作
一.基础知识首先,如果您对LDAP 不认识,建议先看看[原]LDAP服务介绍一文.本文以Linux 下常用的OpenLDAP为例说明.LDAP 以数方式存放数据,每个节点可存放属性或作为下面节点的父节 ...
- PHP和JS判断手机还是电脑访问
当用户使用手机等移动终端访问网站时,我们可以通过程序检测用户终端类型,如果是手机用户,则引导用户访问适配手机屏幕的移动站点.本文将介绍分别使用PHP和JAVASCRIPT代码判断用户终端类型. PHP ...
- JS encodeURI和encodeURIComponent
一.最常用的encodeURI和encodeURIComponent 对URL编码是常见的事,所以这两个方法应该是实际中要特别注意的.它们都是编码URL,唯一区别就是编码的字符范围,其中encodeU ...
- Linux下android开发环境配置
1.安装jdk 1.到sun官网下载jdk(附jdk6下载地址),根据自己的ubuntu版本选择合适的jdk版本.如你用的是ubuntu 32位系统则选择下载jdk-6u41-linux-i586.b ...