cpp
文章平均质量分 63
epsilon1
这个作者很懒,什么都没留下…
展开
-
C++查看任意数据类型比特位串
本文介绍如何查看C++基本数据类型的二进制位串,及用二进制串生成任意基本类型数据。C++中的基本数据类型charboolshortintunsignedlongfloatdoublelong longvoid *有些编译平台甚至包含 long double,主流的基本数据类型最长不超过64比特位。任意基本类型转化为比特串布尔运算和移位操作只能用于整型类数据,这与硬件有关,其实浮原创 2016-09-17 19:13:33 · 3654 阅读 · 0 评论 -
UVA - 816 Abbott's Revenge
原题链接分析:本题和普通的迷宫在本质上是一样的,但是由于“朝向”也起到了关键作用,所以需要用一个三元组(r,c,dir)表示“位于(r,c),面朝dir”这个状态。假设入口的位置为(r0,c0),朝向为dir,则初始状态并不是(r0,c0,dir),而是(r1,c1,dir),其中,(r1,c1)是(r0,c0)沿着方向dir走一步之后的坐标。此处用d[r][c][dir]表示初始状态原创 2015-10-10 17:27:42 · 581 阅读 · 0 评论 -
UVA - 572 Oil Deposits
DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid原创 2015-10-09 15:59:09 · 352 阅读 · 0 评论 -
UVA - 839 Not so Mobile
DescriptionBefore being an ubiquous communications gadget, a mobile was just a structure made of strings and wires suspending colourfull things. This kind of mobile is usually found hanging over c原创 2015-10-09 13:42:56 · 478 阅读 · 0 评论 -
UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)
分析:本题并不能简单的用数组,应该采用链表,这里我用数组作为链表。为了方便起见,假设字符串s的最前面还有一个虚拟的s[0],则next[0]就可以表示显示屏中最左边的字符。再用一个变量cur表示光标位置:即当前光标位于s[cur]的右边。cur=0说明光标位于’虚拟字符‘s[0]的右边,即显示屏的最左边。为了移动光标,还需要用一个变量last表示显示屏的最后一个字符是s[last]。#原创 2015-10-09 16:50:52 · 406 阅读 · 0 评论 -
UVA - 297 Quadtrees
DescriptionA quadtree is a representation format used to encode images. The fundamental idea behind the quadtree is that any image can be split into four quadrants. Each quadrant may again be spli原创 2015-10-09 15:32:30 · 366 阅读 · 0 评论 -
UVA - 699 The Falling Leaves
DescriptionEach year, fall in the North Central region is accompanied by the brilliant colors of the leaves on the trees, followed quickly by the falling leaves accumulating under the trees. If th原创 2015-10-09 14:58:33 · 447 阅读 · 0 评论 -
UVA - 11134 Fabled Rooks
题目大意:在一个n*n的棋盘上放置n个车,使得它们之间都不能互相攻击(任意两个车都不能同行或同列),并且,对于第i个车,限制它只能放在一个矩形区域内,(xli, yli),这个矩形的左上角顶点坐标是(xli, yli),右下角顶点坐标是 (xri, yri), 1 ≤ i ≤ n,1 ≤ xli ≤ xri ≤ n,1 ≤ yli ≤ yri ≤ n.思路:原创 2015-10-22 22:21:43 · 475 阅读 · 0 评论 -
UVA - 12657 Boxes in a Line
InputThere will be at most 10 test cases. Each test case begins with a line containing 2 integers n,m(1OutputFor each test case, print the sum of numbers at odd-indexed positions. Positions a原创 2015-10-09 17:26:21 · 491 阅读 · 0 评论 -
UVA - 10129 Play on Words
InputThe input consists of T test cases. The number of them (T) is given on the first line of the input file.Each test case begins with a line containing a single integer number N that indicates t原创 2015-10-14 16:27:43 · 434 阅读 · 0 评论 -
UVA_673: Parentheses Balance
DescriptionYou are given a string consisting of parentheses () and []. A string of this type is said to be correct:(a)if it is the empty string(b)if A and B are correct, AB is correct,(c)i原创 2015-10-14 17:07:09 · 499 阅读 · 0 评论 -
UVA_10305: Ordering Tasks
InputThe input will consist of several instances of the problem. Each instance begins with a line containingtwo integers, 1 ≤ n ≤ 100 and m. n is the number of tasks (numbered from 1 to n) and m i原创 2015-10-14 15:31:28 · 437 阅读 · 0 评论 -
IEEE 754四种舍入方向
四种舍入方向:向最接近的可表示的值:当有两个最接近的可表示的值时首选“偶数”值,这与我们常见的“四舍五入”只有一点不同,对.5的舍入上,采用取偶数的方式。 如:Round(0.5) = 0;Round(1.5) = 2;Round(2.5) = 2;对比采用四舍五入:Round(0.5) = 1;Round(1.5) = 2;Round(2.5) = 3;之所以IEEE754要这么做,主要原创 2016-09-17 18:49:09 · 4360 阅读 · 0 评论 -
C++11 中的右值引用与转移语义
本文介绍了 C++11 标准中的一个特性,右值引用和转移语义。这个特性能够使代码更加简洁高效。新特性的目的右值引用 (Rvalue Referene) 是 C++ 新标准 (C++11, 11 代表 2011 年 ) 中引入的新特性 , 它实现了转移语义 (Move Sementics) 和精确传递 (Perfect Forwarding)。它的主要目的有两个方面:消除两个对象交互时不必要的对象拷原创 2016-07-22 22:52:37 · 964 阅读 · 0 评论 -
如何加快 C++ 代码的编译速度
C++代码一直以其运行时的高性能高调面对世人, 但是说起编译速度,却只有低调的份了。比如我现在工作的源代码,哪怕使用Incredibuild调动近百台机子,一个完整的build也需要四个小时,恐怖!!!虽然平时开发一般不需要在本地做完整的build,但编译几个相关的工程就够你等上好一段时间的了(老外管这个叫monkey around,相当形象)。想想若干年在一台单核2.8GHZ上工作时的场景 -原创 2016-02-28 10:30:04 · 1984 阅读 · 0 评论 -
UVA - 536 Tree Recovery
DescriptionLittle Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes.This is an example o原创 2015-10-15 19:43:44 · 594 阅读 · 0 评论 -
UVA - 712 S-Trees
DescriptionA Strange Tree (S-tree) over the variable set is a binary tree representing a Boolean function . Each path of the S-tree begins at the root node and consists of n+1 nodes. Each原创 2015-10-15 18:51:22 · 427 阅读 · 0 评论 -
UVA - 524 Prime Ring Problem
DescriptionA ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of numbers in two adjacent circles should be a p原创 2015-10-15 09:32:33 · 557 阅读 · 0 评论 -
UVA - 10562 Undraw the Trees
InputThe first line of the input file (which you can assume comes from standard input) contains the numberof trees, T (1 ≤ T ≤ 20) drawn in the file. Then you would have T trees, each ending with原创 2015-10-15 11:11:13 · 505 阅读 · 0 评论 -
UVA_548: Tree
DescriptionYou are to determine the value of the leaf node in a given binary tree that is the terminal node of a path of least value from the root of the binary tree to any leaf. The value of a pa原创 2015-10-08 11:35:51 · 462 阅读 · 0 评论 -
UVA_122: Trees on the level
DescriptionBackgroundTrees are fundamental in many branches of computer science. Current state-of-the art parallel computers suchas Thinking Machines' CM-5 are based onfat trees. Quad- andocta原创 2015-10-08 11:20:06 · 434 阅读 · 0 评论 -
UVA_11059: Maximum Product
题意: 输入n个元素组成的序列S,找出一个乘积最大的连续子序列。如果这个最大的乘积不是正数,输出0(表示无解)。1案例: Sample Input 3 2 4 -3 5 2 5 -1 2 -1 Sample Output Case #1: The m原创 2015-10-07 16:58:15 · 474 阅读 · 0 评论 -
UVA_1592: Database
DescriptionPeter studies the theory of relational databases. Table in the relational database consists of values that are arranged in rows and columns. There are differentnormal forms that databas原创 2015-10-05 21:21:34 · 585 阅读 · 0 评论 -
UVA_10935: Throwing cards away I
注意输出格式,利用队列即可#include #include #include #include using namespace std;queue rest;vector discard;int main(){ int n; while(~scanf("%d",&n)&&n) { discard.clear(); for(int i=1; i<=n原创 2015-10-06 09:43:41 · 341 阅读 · 0 评论 -
UVA_1593: Alignment of Code
DescriptionYou are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is basically a text editor with bells and whistles. You are working on a module that take原创 2015-10-05 22:24:48 · 609 阅读 · 0 评论 -
UVA_400: Unix ls
DescriptionThe computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your assignment原创 2015-10-05 17:34:58 · 720 阅读 · 0 评论 -
UVA_12096: The SetStack Computer
点击查看原题分析:本题的集合并不是数字或字母,而是集合的集合。我们不妨给每个集合分配唯一的ID,则每个集合都可以表示成所包含元素的ID集合,这就可以用set来表示了,而整个栈则是stack,注意这里所谓的ID并不是真实的数字,而是集合数组的标号。#include #include #include #include #include #include #include原创 2015-10-05 13:40:04 · 481 阅读 · 0 评论 -
UVA - 136 Ugly Numbers
DescriptionUgly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included.原创 2015-10-05 15:46:22 · 1004 阅读 · 0 评论 -
UVA_540: Team Queue
DescriptionQueues and Priority Queues are data structures which are known to most computer scientists. TheTeam Queue, however, is not so well known, though it occurs often in everyday life. At l原创 2015-10-05 15:07:39 · 458 阅读 · 0 评论 -
C++:set_union is not a member of std;
这是什么鬼错,写程序都是include一大堆头文件,确实也有include set,但是依然报错,using namespace std;也没用,后来去C++官网逛了下,发现原来set_union和set并没有什么直接的关系,应该说set_union是一种算法,而set是一种数据结构,所以应该include algorithm点击查看C++ reference原创 2015-10-05 13:29:34 · 1053 阅读 · 0 评论 -
UVA_1594: Ducci Sequence
DescriptionA Ducci sequence is a sequence of n-tuples of integers. Given ann-tuple of integers (a1,a2, ... , an), the nextn-tuple in the sequence is formed by taking the absolute differences o原创 2015-10-05 23:07:07 · 473 阅读 · 0 评论 -
UVA - 10763 Foreign Exchange
DescriptionYour non-profit organization (iCORE - internationalConfederation of Revolver Enthusiasts) coordinates a very successful foreign student exchange program. Over the last few years, de原创 2015-10-06 10:28:47 · 498 阅读 · 0 评论 -
UVA_10391: Compound Words
分析:读取所有字符串到字符数组中并存在map中建立映射,之后进入主循环,遍历每个字符串,按长度截取成两个字符串,分别在map中查找,如果找到了说明可以拆,进行下一个,不能继续找。#include #include #include #include #include using namespace std;char words[120010][30];map wmap;原创 2015-10-06 15:47:36 · 491 阅读 · 0 评论 -
UVA_442: Matrix Chain Multiplication
DescriptionSuppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices.Since matrix multiplication is associative, the order in which multiplications are performed isa原创 2015-10-07 14:05:25 · 834 阅读 · 0 评论 -
UVA_679: Dropping Balls
DescriptionA number of K balls are dropped one by one from the root of a fully binary tree structure FBT. Each time the ball being dropped first visits a non-terminal node. It then keeps moving down原创 2015-10-07 21:14:26 · 499 阅读 · 0 评论 -
UVA_10976: Fractions Again?!
题意: 输入一个正整数k,找出所有正整数x>=y,使得1/k=1/x+1/y分析: x>=y推出1/x#include #include using namespace std;const int maxn = 10000+10;int x[maxn];int y[maxn];int main(){ int k; while(~scanf("%d",原创 2015-10-07 17:12:37 · 461 阅读 · 0 评论 -
UVA_725: Division
DescriptionWrite a program that finds and displays all pairs of 5-digit numbers thatbetween them use the digits0 through 9 once each, such that thefirst number divided by the second is equal to an原创 2015-10-07 16:34:44 · 540 阅读 · 0 评论 -
C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
1、const成员:只能在类中初始化#include using namespace std;class A {public: const int c = 1;};int main(){ A a; cout << a.c << endl; return 0;}2、static成员:初始化在类外,且不加static修饰#incl原创 2015-11-07 16:59:32 · 551 阅读 · 0 评论 -
UVA_1595: Symmetry
DescriptionThe figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper along avertical line, drawn as a dashed line, and to cut the figure into two identical原创 2015-10-06 12:58:48 · 493 阅读 · 0 评论 -
UVA_12100: Printer Queue
点击查看原题分析:本题解法多种,可以用两个队列,一个普通的存放id,另一个是优先队列存放id,还有一个数组用于优先队列的比较;我这里用的比较麻烦,两个队列,一个存放id和优先级二元组,一个存放优先级;#include #include #include #include #include using namespace std;typedef pair id_pri原创 2015-10-06 14:19:51 · 419 阅读 · 0 评论