uva 11039
水题 排序 判符号
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- struct pp
- {
- int a;
- bool b;
- void f(int n)
- {
- if(n >= 0)
- {
- b = true;
- a = n;
- }
- else
- {
- b = false;
- a = -n;
- }
- }
- bool operator<(const pp& p) const
- {
- return a < p.a;
- }
- };
- pp cc[500010];
- int main()
- {
- int T;
- scanf("%d",&T);
- while(T--)
- {
- int n;
- scanf("%d",&n);
- for(int i = 0; i < n; i++)
- {
- int x;
- scanf("%d",&x);
- cc[i].f(x);
- }
- sort(cc, cc+n);
- bool now = cc[0].b;
- int con = 1;
- for(int i = 1; i < n; i++)
- {
- if(now != cc[i].b)
- {
- now = cc[i].b;
- con++;
- }
- }
- printf("%d\n",con);
- }
- return 0;
- }
uva 11039的更多相关文章
- UVA 11039 Building designing 贪心
题目链接:UVA - 11039 题意描述:建筑师设计房子有两条要求:第一,每一层楼的大小一定比此层楼以上的房子尺寸要大:第二,用蓝色和红色为建筑染色,每相邻的两层楼不能染同一种颜色.现在给出楼层数量 ...
- 贪心水题。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 贪心,水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 11039 - Building designing(DP)
题目链接 本质上是DP,但是俩变量就搞定了. #include <cstdio> #include <cstring> #include <algorithm> u ...
- UVa 11039 - Building designing
题目大意:n个绝对值各不相同的非0整数,选出尽量多的数,排成一个序列,使得正负号交替且绝对值递增. 分析:按照绝对值大小排一次序,然后扫描一次,顺便做个标记即可. #include<cstdio ...
- UVa 11039 (排序+贪心) Building designing
白书上的例题比较难,认真理解样例代码有助于提高自己 后面的练习题相对简单,独立思考解决问题,增强信心 题意:n个绝对值各不相同的非0整数,选出尽量多的数排成序列,使得该序列正负交错且绝对值递增. 解法 ...
- Building designing UVA - 11039
先取正的和负的绝对值较小者为开头 .然后交替从正负数中取绝对值最小但比上一个大的. 证明: 1.开头选正负数中绝对值较小的:否则能再多放1个. 2.交替选的时候选最小的符合条件的:如果大的符合,换小的 ...
- UVa 11039 设计建筑物
https://vjudge.net/problem/UVA-11039 题意: 有n个绝对值各不相同的非0整数,选出尽量多的数,排成一个序列,使得正负号交替且绝对值递增. 思路:正数存一个数组,负数 ...
- UVa 11039 Building designing (贪心+排序+模拟)
题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计 ...
随机推荐
- C# 每天温习一点(IEnumerable<TSource>)
1, IEnumerable<TSource> 多数屌丝写成 IEnumerable<T> 无论TSource还是T都代表一个意思:要枚举的对象的类型 .IEnumerab ...
- 在win下面使用cdt+cygwin+cmake
在cygwin终端下面, cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug 当收获警告 Could ...
- mysql绿色版在windows系统中的启动
mysql绿色版在windows系统中的启动 1.下载mysql免安装版 例如:mysql-5.7.11-winx64 2.修改配置文件,my-default.ini名称改为:my.ini,文件里面的 ...
- krpano资料
- mysql安装启动教程(两种方法)
mysql安装启动: 方法一(简单版): cmd进入mysql安装的bin目录:mysqld.exe –install net start mysql 服务启动(或者选择计算机->(右键)管理 ...
- 关于AjaxPro的用法
1.添加引用AjaxPro.2.dll到项目中 2.添加webconfig iis6添加 在<system.web>中添加: <httpHandlers> <add ve ...
- C#编写记事本(高仿)
近一周写的关于记事本的代码,高仿记事本.本人C#入门不久,其中存在代码冗余,但懒得修改了. 经测试运行正常. 一.主窗体设计及代码 namespace BestEditor { public part ...
- php curl抓取远程页面内容的代码
使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...
- zhuan:ubuntu下安装Apache2+php+Mysql
from: http://www.cnblogs.com/lynch_world/archive/2012/01/06/2314717.html ubuntu下安装Apache+PHP+Mysql 转 ...
- spring mvc 初步接触学习笔记
1.使用maven导入spring mvc web 的jar 包 最新语句 <dependency> <groupId>org.springframework</grou ...