水题  排序 判符号

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct pp
  7. {
  8. int a;
  9. bool b;
  10. void f(int n)
  11. {
  12. if(n >= 0)
  13. {
  14. b = true;
  15. a = n;
  16. }
  17. else
  18. {
  19. b = false;
  20. a = -n;
  21. }
  22. }
  23. bool operator<(const pp& p) const
  24. {
  25. return a < p.a;
  26. }
  27. };
  28. pp cc[500010];
  29. int main()
  30. {
  31. int T;
  32. scanf("%d",&T);
  33. while(T--)
  34. {
  35. int n;
  36. scanf("%d",&n);
  37. for(int i = 0; i < n; i++)
  38. {
  39. int x;
  40. scanf("%d",&x);
  41. cc[i].f(x);
  42. }
  43. sort(cc, cc+n);
  44. bool now = cc[0].b;
  45. int con = 1;
  46. for(int i = 1; i < n; i++)
  47. {
  48. if(now != cc[i].b)
  49. {
  50. now = cc[i].b;
  51. con++;
  52. }
  53. }
  54. printf("%d\n",con);
  55. }
  56. return 0;
  57. }

uva 11039的更多相关文章

  1. UVA 11039 Building designing 贪心

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

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

  3. UVa 11039 - Building designing 贪心,水题 难度: 0

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

  4. UVA 11039 - Building designing(DP)

    题目链接 本质上是DP,但是俩变量就搞定了. #include <cstdio> #include <cstring> #include <algorithm> u ...

  5. UVa 11039 - Building designing

    题目大意:n个绝对值各不相同的非0整数,选出尽量多的数,排成一个序列,使得正负号交替且绝对值递增. 分析:按照绝对值大小排一次序,然后扫描一次,顺便做个标记即可. #include<cstdio ...

  6. UVa 11039 (排序+贪心) Building designing

    白书上的例题比较难,认真理解样例代码有助于提高自己 后面的练习题相对简单,独立思考解决问题,增强信心 题意:n个绝对值各不相同的非0整数,选出尽量多的数排成序列,使得该序列正负交错且绝对值递增. 解法 ...

  7. Building designing UVA - 11039

    先取正的和负的绝对值较小者为开头 .然后交替从正负数中取绝对值最小但比上一个大的. 证明: 1.开头选正负数中绝对值较小的:否则能再多放1个. 2.交替选的时候选最小的符合条件的:如果大的符合,换小的 ...

  8. UVa 11039 设计建筑物

    https://vjudge.net/problem/UVA-11039 题意: 有n个绝对值各不相同的非0整数,选出尽量多的数,排成一个序列,使得正负号交替且绝对值递增. 思路:正数存一个数组,负数 ...

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

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

随机推荐

  1. C# 每天温习一点(IEnumerable<TSource>)

    1, IEnumerable<TSource> 多数屌丝写成  IEnumerable<T>  无论TSource还是T都代表一个意思:要枚举的对象的类型 .IEnumerab ...

  2. 在win下面使用cdt+cygwin+cmake

    在cygwin终端下面, cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug 当收获警告 Could ...

  3. mysql绿色版在windows系统中的启动

    mysql绿色版在windows系统中的启动 1.下载mysql免安装版 例如:mysql-5.7.11-winx64 2.修改配置文件,my-default.ini名称改为:my.ini,文件里面的 ...

  4. krpano资料

  5. mysql安装启动教程(两种方法)

    mysql安装启动: 方法一(简单版): cmd进入mysql安装的bin目录:mysqld.exe –install net start mysql  服务启动(或者选择计算机->(右键)管理 ...

  6. 关于AjaxPro的用法

    1.添加引用AjaxPro.2.dll到项目中 2.添加webconfig iis6添加 在<system.web>中添加: <httpHandlers> <add ve ...

  7. C#编写记事本(高仿)

    近一周写的关于记事本的代码,高仿记事本.本人C#入门不久,其中存在代码冗余,但懒得修改了. 经测试运行正常. 一.主窗体设计及代码 namespace BestEditor { public part ...

  8. php curl抓取远程页面内容的代码

    使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...

  9. zhuan:ubuntu下安装Apache2+php+Mysql

    from: http://www.cnblogs.com/lynch_world/archive/2012/01/06/2314717.html ubuntu下安装Apache+PHP+Mysql 转 ...

  10. spring mvc 初步接触学习笔记

    1.使用maven导入spring mvc web 的jar 包 最新语句 <dependency> <groupId>org.springframework</grou ...