UVA11039-Building designing】的更多相关文章

  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…
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…
题目链接 本质上是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--…
题目大意:n个绝对值各不相同的非0整数,选出尽量多的数,排成一个序列,使得正负号交替且绝对值递增. 分析:按照绝对值大小排一次序,然后扫描一次,顺便做个标记即可. #include<cstdio>#include<algorithm>#include<cmath>using namespace std; int cmp(int a,int b){ return abs(a)<abs(b);}int main(){ int cas,a[100000],n; scan…
白书上的例题比较难,认真理解样例代码有助于提高自己 后面的练习题相对简单,独立思考解决问题,增强信心 题意:n个绝对值各不相同的非0整数,选出尽量多的数排成序列,使得该序列正负交错且绝对值递增. 解法:先按绝对值从小到大排序,然后第一个数先入队,然后依次比较后面的数,如果和队尾的数符号相反则入队,直到所有的数遍历完为止 这里用了异或运算,因为这里面没有0,所谓符号相同的两个数异或值为正,不同符号的数异或值为负 //#define LOCAL #include <algorithm> #incl…
先取正的和负的绝对值较小者为开头 .然后交替从正负数中取绝对值最小但比上一个大的. 证明: 1.开头选正负数中绝对值较小的:否则能再多放1个. 2.交替选的时候选最小的符合条件的:如果大的符合,换小的仍符合. #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1980 题意 n个数,要求正负相间,绝对值增长,问n个数能组成的这样数列最长多长 思路 明显,分成正负两组,挨个在两组内取最小,直到不能取就行 代码 #include <algorithm> #include <cassert> #include <cma…
题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计数,easy!!! 代码如下: #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int maxn = 5…
题目链接:UVA - 11039 题意描述:建筑师设计房子有两条要求:第一,每一层楼的大小一定比此层楼以上的房子尺寸要大:第二,用蓝色和红色为建筑染色,每相邻的两层楼不能染同一种颜色.现在给出楼层数量和每层楼的尺寸(楼层尺寸的大小没有按照顺序给出),求出满足这样要求的最大楼层数. 算法分析:把楼层尺寸按照从大到小排序,然后遍历一次的同时记录相邻楼层所染颜色不同,把不满足要求的楼层去掉即可. #include<iostream> #include<cstdio> #include&l…
题目总结来说求一段序列,必须正负交替,且绝对值递增 #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <vector> #include <algorithm> using namespace std; #define lowbit(x) (x&(-x)) #defi…