UVa 11039 - Building designing 贪心,水题 难度: 0
题目
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1980
题意
n个数,要求正负相间,绝对值增长,问n个数能组成的这样数列最长多长
思路
明显,分成正负两组,挨个在两组内取最小,直到不能取就行
代码
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair;
const int MAXN = 5e5 + ;
int a[MAXN];
int b[MAXN]; int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int n;
int T;
scanf("%d", &T);
for (int ti = ; ti <= T && scanf("%d", &n) == ; ti++) {
int acnt = ;
int bcnt = ;
for (int i = ; i < n; i++) {
int tmp;
scanf("%d", &tmp);
if (tmp > )a[acnt++] = tmp;
else b[bcnt++] = -tmp;
}
sort(a, a + acnt);
sort(b, b + bcnt);
int ans = ;
int start = ;
int astart = ;
int bstart = ;
if (astart < acnt && bstart < bcnt && b[bstart] < a[astart]) {
ans = ;
bstart++;
}
while (true) {
while (bstart && astart < acnt && a[astart] < b[bstart - ]) {
astart++;
}
if (astart < acnt) {
ans++;
astart++;
}
else {
break;
}
while (astart && bstart < bcnt && a[astart - ] > b[bstart]) {
bstart++;
}
if (bstart < bcnt) {
ans++;
bstart++;
}
else {
break;
}
}
printf("%d\n", ans);
} return ;
}
UVa 11039 - Building designing 贪心,水题 难度: 0的更多相关文章
- UVA 11039 Building designing 贪心
题目链接:UVA - 11039 题意描述:建筑师设计房子有两条要求:第一,每一层楼的大小一定比此层楼以上的房子尺寸要大:第二,用蓝色和红色为建筑染色,每相邻的两层楼不能染同一种颜色.现在给出楼层数量 ...
- UVa 10340 - All in All 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa LA 3213 - Ancient Cipher 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing
UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r ...
- UVA 11039 - Building designing 水题哇~
水题一题,按绝对值排序后扫描一片数组(判断是否异号,我是直接相乘注意中间值越界)即可. 感觉是让我练习sort自定义比较函数的. #include<cstdio> #include< ...
- UVa 11039 Building designing (贪心+排序+模拟)
题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计 ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11636 - Hello World! 二分,水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
随机推荐
- 《剑指offer》第四十四题(数字序列中某一位的数字)
// 面试题44:数字序列中某一位的数字 // 题目:数字以0123456789101112131415…的格式序列化到一个字符序列中.在这 // 个序列中,第5位(从0开始计数)是5,第13位是1, ...
- 学习笔记33—graphPad画图集
1.如何去掉如下图所示的基准线(baseline): 解决办法:鼠标左键双击基准线 --->出现下图对话框,勾选Hide baseline即可. 2.画柱状图时,如何将正常人和病人的信息画在 ...
- CC2 条理分明-----独立思考
独立思考 前几天啊,在吃饭的时候,听到同事们在讨论某幼儿园事件,因为没有人愿意出来作证,所以很可能是造谣.前几天他们还咬牙切齿的指责这个幼儿园,现在怎么就变了.我发现人们的思维变化的太快,我自己也是的 ...
- Solaris 10 disable ipv6
亲测有效:) http://thegeekdiary.com/how-to-remove-ipv6-in-solaris-11/
- 雷林鹏分享:C# 运算符
C# 运算符 运算符是一种告诉编译器执行特定的数学或逻辑操作的符号.C# 有丰富的内置运算符,分类如下: 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 杂项运算符 本教程将逐一讲解算术运算 ...
- Sparksql的内置函数的使用以及案例
开发环境:spark:2.2.0 工具:IDEA OS:Windows 数据文件: 001E8CB5AB11,ASUSTek,2018-07-12 14:00:57,2018-07-12 14:00: ...
- (转)解决windows10下无法安装.net framework 3.5,错误代码0x800F081F
1.下载 NET Framework 3.5的安装包netfx3.cab 将下载的文件复制到复制到 C 盘的 Windows 文件夹 后请在“命令提示符(管理员)”中执行下面的命令: dism /on ...
- python记录_day08
今日内容:文件操作 一.文件基本操作 f = open("文件路径和文件名", mode=" r", encoding="utf-8" ) ...
- 4月12 php练习
php中输出 <?php echo'hello'; php中打印多个div <?php for($i=1;$i<=100;$i++) { ?> <div style=&q ...
- Centos7.3安装和配置jre1.8转
在正式环境里 我们可以不安装jdk ,仅仅安装Java运行环境 jre即可: 第一步:下载jre 我们去oracle官方下载下jre http://www.oracle.com/technetwo ...