题目

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的更多相关文章

  1. UVA 11039 Building designing 贪心

    题目链接:UVA - 11039 题意描述:建筑师设计房子有两条要求:第一,每一层楼的大小一定比此层楼以上的房子尺寸要大:第二,用蓝色和红色为建筑染色,每相邻的两层楼不能染同一种颜色.现在给出楼层数量 ...

  2. UVa 10340 - All in All 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  4. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  5. 贪心水题。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 ...

  6. UVA 11039 - Building designing 水题哇~

    水题一题,按绝对值排序后扫描一片数组(判断是否异号,我是直接相乘注意中间值越界)即可. 感觉是让我练习sort自定义比较函数的. #include<cstdio> #include< ...

  7. UVa 11039 Building designing (贪心+排序+模拟)

    题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计 ...

  8. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. UVa 11636 - Hello World! 二分,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

随机推荐

  1. anaconda3 安装opencv3.4.2 cuda9.2 mint19(ubuntu 18.04)

    从opencv1的时代,编译这玩意就不是太轻松.之前都是在win下.2.x时代,开始用cmake GUI,选vs版本,x86 x64 各种依赖库选项,debug release,... 现在3.4了, ...

  2. 了解java中垃圾回收机制

    Java的垃圾回收机制是Java环境自带有的,它不像c语言的malloc申请空间后需要Free()函数来释放,而Java中的代码块中所申请的空间可在程序执行完成后自动释放,但是是有局限性的,代码块所占 ...

  3. Unity --- 如何降低UI的填充率

    1.首先简单介绍一下什么叫填充率: Fill Rate(填充率)是指显卡每帧或者说每秒能够渲染的像素数.在每帧绘制中,如果一个像素被反复绘制的次数越多,那么它占用的资源也必然更多.目前在移动设备上,F ...

  4. sublime text---注释

    Sublime在进行前端开发时非常棒,当然也少不了众多的插件支持,DocBlocker是在Sublime平台上开发一款自动补全代码插件,支持JavaScript (including ES6), PH ...

  5. 数据结构(C语言版)-第2章 线性表

    #define MAXSIZE 100 //最大长度 typedef struct { ElemType *elem; //指向数据元素的基地址 int length; //线性表的当前长度 }SqL ...

  6. Getting started with Processing 第十三章——延伸(2)

    与 Arduino 联动 在 Processing 中,可以通过:import processing.serial.* Serial port; //声明串口对象port = new Serial(t ...

  7. 协方差分析 | ANCOVA (Analysis of Covariance)

    If you are worried about leaving out covariates you could regress out them first and analyse the res ...

  8. 20171205xlVBA往返航班组合

    'ClassPlan Public Org As String Public Des As String Public FlyNo As String Public StartDate As Vari ...

  9. hdu-6035 Colorful Tree

    题目意思是计算所有路径(n*(n-1)/2)经过的不同颜色的数目和. 这个数目和可以转化为每种颜色经过的路径数目的求和,而这个求和又等价于颜色总数*n*(n-1)/2-没有经过某种颜色的边的数量的求和 ...

  10. 电脑用U盘启动

    除了根据提示按DEL或者F2进入到BIOS界面更改设置之外. 还可以在开机时按F8或F12进入到引导界面,可直接选择USB. 当把登录用户登录,其他用户都被禁用时,电脑登不进去.要制作启动U盘,进入到 ...