白书上的例题比较难,认真理解样例代码有助于提高自己 后面的练习题相对简单,独立思考解决问题,增强信心 题意:n个绝对值各不相同的非0整数,选出尽量多的数排成序列,使得该序列正负交错且绝对值递增. 解法:先按绝对值从小到大排序,然后第一个数先入队,然后依次比较后面的数,如果和队尾的数符号相反则入队,直到所有的数遍历完为止 这里用了异或运算,因为这里面没有0,所谓符号相同的两个数异或值为正,不同符号的数异或值为负 //#define LOCAL #include <algorithm> #incl…
题目链接:UVA - 11039 题意描述:建筑师设计房子有两条要求:第一,每一层楼的大小一定比此层楼以上的房子尺寸要大:第二,用蓝色和红色为建筑染色,每相邻的两层楼不能染同一种颜色.现在给出楼层数量和每层楼的尺寸(楼层尺寸的大小没有按照顺序给出),求出满足这样要求的最大楼层数. 算法分析:把楼层尺寸按照从大到小排序,然后遍历一次的同时记录相邻楼层所染颜色不同,把不满足要求的楼层去掉即可. #include<iostream> #include<cstdio> #include&l…
UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r++; printf("Case %d: %d\n",++kas,r); } ; } LA 3602 DNA Consensus String 贪心构造,每一位上选出现次数最多的. #include<bits/stdc++.h> using namespace std; ,ma…
  Building designing  An architect wants to design a very high building. The building will consist of some floors, and each floor has a certain size. The size of a floor must be greater than the size of the floor immediately above it. In addition, th…
BZOJ_4010_[HNOI2015]菜肴制作_拓扑排序+贪心 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高到低给予 1到N的顺序编号,预估质量最高的菜肴编号为1.由于菜肴之间口味搭配的问题, 某些菜肴必须在另一些菜肴之前制作,具体的,一共有 M 条形如“i 号菜肴‘必须’ 先于 j 号菜肴制作”的限制,我们将这样的限制简写为<i,j>.现在,酒店希望能求 出一个最优的菜肴的制作顺序,使…
http://codeforces.com/contest/1294/problem/B 大致题意: 一张图上有n个包裹,给出他们的坐标,一个机器人从(0,0)出发,只能向右(R)或向上(U),问能否收集到所有包裹,如果能,给出字典序最小的路径. 最开始当成搜索题了,其实可以排序+贪心写的. #include <stdio.h> #include <string.h> #include <iostream> #include <string> #includ…
题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计数,easy!!! 代码如下: #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int maxn = 5…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1980 题意 n个数,要求正负相间,绝对值增长,问n个数能组成的这样数列最长多长 思路 明显,分成正负两组,挨个在两组内取最小,直到不能取就行 代码 #include <algorithm> #include <cassert> #include <cma…
水题一题,按绝对值排序后扫描一片数组(判断是否异号,我是直接相乘注意中间值越界)即可. 感觉是让我练习sort自定义比较函数的. #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int MAXN=500000+10; int a[MAXN]; bool compare(const int &a,const int &b) { return ab…
题目链接 本质上是DP,但是俩变量就搞定了. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; bool cmp(int a,int b) { ) a = -a; ) b = -b; return a < b; } int main() { int t,n,p1,p2,i; scanf("%d",&t); while(t--…