ACM tips

(Updated -ing)

1, memset operation is byte, each byte may be the same Memset (a byte has eight bits), for example (int type): 0x3f3f3f3f, 0, -1 ,,, (- 1 is in reverse stored code, each bit is 1); it is not assigned a memset, such memset (& a, 1, sizeof (int)); Fu is actually 00000001000000010000000100000001 to a (2) = 16843009.

2, bit operations:
       A. 1 &          \implies Corresponds to a% 2 == 1 (Analyzing parity);
       A ^ B         \implies Corresponds to a! = B (Analyzing a, b are equal)
       . 1 << n-       \implies 2 N

: 3, the output of a long long comparison c / c ++ long long and the different compilation environment __int64

4, c ++ can not in parentheses after the variable is defined for, c in

5, the output of a line break: Puts ( ""); cin << end1; printf ( "\ n");

6, c the sqrt () function of real argument can be an integer, c ++ are not, or will compile error

. 7, || (a true is true) calculation, first a determination will not be true of a second; && (if a false false) calculation, first a determination is not to continue the second false

8, printf stack is implemented so int i = 8; printf ( "% d% d", i ++, i- -); the output is: 78

9, when accessing the array or the container first determines whether the index is out of bounds to empty multiple sets of input remember stl

10, Staggered formula D (n) = (n-1) [D (n-2) + D (n-1)], specially, D (1) = 0, D (2) = 1.

11, int dir [8] [2] = {{- 2, -1}, {- 2,1}, {- 1, -2}, {- 1,2}, {1, -2}, { 1,2}, {2, -1}, {2,1}}; // this order out of the search result is lexicographically

12, the whole arrangement sequence calculation function: next_permutation (start, end) (a current array arrangement), and prev_permutation (start, end) (the arrangement of a current arrangement).

13, from: the ACM tips
read end of the file, the program automatically end (input Scanf a successful data return 1, otherwise -1)
the while ((Scanf ( "% D", & A)) = -1!)
The while ((Scanf ( "% D", & A))! = the EOF)
the while ((Scanf ( "% D", & A)) ==. 1)
the while (~ (Scanf ( "% D", & A))) // Bitwise
when reading a 0, the program ends
the while (Scanf ( "% D", & a), a)
the while (Scanf ( "% D", & a)! = the EOF && a)
when a plurality of read 0, the routine ends
while (scanf ( "% d% d% d", & a, & b, & c), a + b + c) // a, b, c nonnegative

14, gets () returns a pointer, if the read end of the file is returned empty, that is NULL

15, ceil (), floor () return value is of type double

16, for upper_bound, the return of the first sequence is checked to find a value greater than the pointer is pointing to return the inspected value> find the minimum value of the pointer, lower_bound is returned is checked first sequence seek pointer value greater than or equal

17、1B=8b,1kb=1024b

18, the data value range, or larger, whether or not If there wa, note that the data overflow (beyond the scope of int)

19, STL addition to vector and string are not supported * (it + 1) in the form of access

20, the same as the inverted positive number to its original code, negative anti-code is a positive number bitwise negation, the sign bit remains 1;
the same complement positive number to its original code, negative complement is, in its inverted the last bit plus 1;

21, the integer and integer calculation results are integers (not floating-point)
operation and an integer result type int int int is an integer of an integer type (long integer not be long long)

22, define a text replacement, and subroutines are not the same

23, Runtime Error, refer to your application run-time error has occurred. It may be due to memory access violations (including cross-border array subscript running index is negative cases), and other issues in addition to 0 run.

24, two variable exchange: a ^ = b ^ = a ^ = b

25, lowbit function: x & (-x) or (x - (x & (x - 1)))

26, judgment is not a power of 2: x> 0 (x & (x - 1)) == 0:? False

Published 52 original articles · won praise 26 · views 3195

Guess you like

Origin blog.csdn.net/qq_43803508/article/details/95863612