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 ...
随机推荐
- Ubuntu 追加组,用户,设置免sudo密码输入
1,以root权限执行groupadd命令创建dev组. sudo groupadd dev 2,用adduser命令创建bpuser用户,--ingroup指定用户加入dev组. sud ...
- LRU缓存机制
运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制.它应该支持以下操作: 获取数据 get 和 写入数据 put . 获取数据 get(key) - 如果密钥 (key) 存 ...
- 大数据 - spark-sql 常用命令
--spark启动 spark-sql --退出 spark-sql> quit; --退出spark-sql or spark-sql> exit; 1.查看已有的database sh ...
- HTML 第九章总结
前言 这一章节主要讲了关于 HTML 中关于留白的知识:在这一章节中,从大到小,有: margin border padding context 这四个部分. 关于margin和padding mar ...
- 雷林鹏分享:C# 判断
C# 判断 判断结构要求程序员指定一个或多个要评估或测试的条件,以及条件为真时要执行的语句(必需的)和条件为假时要执行的语句(可选的). 下面是大多数编程语言中典型的判断结构的一般形式: 判断语句 C ...
- Lab 3-4
Analyze the malware found in the file Lab03-04.exe using basic dynamic analysis tools. (This program ...
- 20181013xlVba计算优秀率及合格率
Sub 计算高一优秀合格率() Dim Wb As Workbook Dim Sht As Worksheet Dim oSht As Worksheet Dim dOs As Object 'Out ...
- uWSGI和Gunicorn
因为nginx等优秀的开源项目,有不少本来不是做服务器的同学也可以写很多服务器端的程序了.但是在聊天中会发现,大家虽然写了不少代码,但是对wsgi是什么,gunicorn是什么,反向代理又是什么并不了 ...
- Kali安装nessus
下载 在官方网站下载对应的 Nessus 版本:http://www.tenable.com/products/nessus/select-your-operating-system 这里选择 Kal ...
- php &符的写法
foreach ($expert as &$value) { $value['z_thumbs'] = $_W['attachurl'].$value['z_thumbs']; } forea ...