The first lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
The first lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
The second lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
The first lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
The first lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
What is Data Type?
Primitive Types in C#: Integer Types, Floating-Point Types, Decimal Type, Boolean Type, Character Types, Strings, Objects
Value Types and Reference Types
Variables. Using Variables: Declaring, Initializing, Assigning Value, Accessing Value
Literals: The Values of the Variables in the Source Code. Boolean Literals. Integer Literals. Floating-Point Literals, Decimal Literals, String Literals and Escaping Sequences
Exercises: Working with Primitive Types and Variables
In this chapter we will get familiar with the console as a tool for data input and output. We will explain what it is, when and how to use it, and how most programming languages access the console. We will get familiar with some of the features in C# for user interaction: reading text and numbers from the console and printing text and numbers. We will also examine the main streams for input-output operations Console.In, Console.Out and Console.Error, the Console and the usage of format strings for printing data in various formats.
03. Operators Expressions and statementsIntro C# Book
In this chapter we will get acquainted with the operators in C# and the actions they can perform on the different data types. We will explain the priorities of the operators and we will analyze the different types of operators, according to the count of the arguments they can take and the actions they can perform. In the second part we will examine the conversion of data types. We will explain when and why it is needed to be done and how to work with different data types. At the end of the chapter we will pay special attention to the expressions and how we should work with them.
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
Abstract: Chances are you code in a language that's either descended from C, inspired by C, or run in an interpreter that itself is written in C. Still... do you actually know how to code in C? Despite its long-standing position as a sort of "lingua franca", an agreed-upon common language, more and more developers are putting together successful, satisfying careers, without ever learning this seminal language. But what if you have to call into C code from your favorite scripting language, or use APIs like OpenGL that are written to be called from C? Many developers find C very challenging, particularly its manual memory-management and other low-level concerns. In this session, we'll show you why you shouldn't be afraid of C, how you can use the skills you already have from the languages you code in today, and how to master structs, enums, typedefs, malloc(), free(), and the rest of C's sharp edges. Examples will be from the point-of-view of the C-skewing iPhone SDK, but will be designed to be broadly applicable and platform-agnostic.
The first lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
The second lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
The first lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
The first lecture of the ACM Aleppo CPC training. The local contest of ICPC. This lecture will help you get started in programming contests word with the lower bound techniques. The lectures focus on the C++ programming language and the STL library to solve programming problems.
What is Data Type?
Primitive Types in C#: Integer Types, Floating-Point Types, Decimal Type, Boolean Type, Character Types, Strings, Objects
Value Types and Reference Types
Variables. Using Variables: Declaring, Initializing, Assigning Value, Accessing Value
Literals: The Values of the Variables in the Source Code. Boolean Literals. Integer Literals. Floating-Point Literals, Decimal Literals, String Literals and Escaping Sequences
Exercises: Working with Primitive Types and Variables
In this chapter we will get familiar with the console as a tool for data input and output. We will explain what it is, when and how to use it, and how most programming languages access the console. We will get familiar with some of the features in C# for user interaction: reading text and numbers from the console and printing text and numbers. We will also examine the main streams for input-output operations Console.In, Console.Out and Console.Error, the Console and the usage of format strings for printing data in various formats.
03. Operators Expressions and statementsIntro C# Book
In this chapter we will get acquainted with the operators in C# and the actions they can perform on the different data types. We will explain the priorities of the operators and we will analyze the different types of operators, according to the count of the arguments they can take and the actions they can perform. In the second part we will examine the conversion of data types. We will explain when and why it is needed to be done and how to work with different data types. At the end of the chapter we will pay special attention to the expressions and how we should work with them.
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
Abstract: Chances are you code in a language that's either descended from C, inspired by C, or run in an interpreter that itself is written in C. Still... do you actually know how to code in C? Despite its long-standing position as a sort of "lingua franca", an agreed-upon common language, more and more developers are putting together successful, satisfying careers, without ever learning this seminal language. But what if you have to call into C code from your favorite scripting language, or use APIs like OpenGL that are written to be called from C? Many developers find C very challenging, particularly its manual memory-management and other low-level concerns. In this session, we'll show you why you shouldn't be afraid of C, how you can use the skills you already have from the languages you code in today, and how to master structs, enums, typedefs, malloc(), free(), and the rest of C's sharp edges. Examples will be from the point-of-view of the C-skewing iPhone SDK, but will be designed to be broadly applicable and platform-agnostic.
45 Days C++ Programming Language Training in Ambalajatin batra
Are you looking for C++Programming Training In Ambala?
Now you search ends here... Batra Computer Centre provides you best C++ Programming Language Training in Ambala Cantt. We also proides you training in C, HTML, PHP, Web Designing, Web Development, SEO, SMO also.
The Goal and The Journey - Turning back on one year of C++14 MigrationJoel Falcou
C++14 has been announced as the next best thing since sliced bread in terms of simplicity, performance and overall elegance of c++ code. This talk is the story of why and how we decided to migrate one of our old 'modern C++' software library -- BSP++, a C++ implementation of the BSP parallel programming model -- to C++14.
More than just a recollection of 'use this' or 'do that' mottos, this talk will try to ponder on :
why one should consider migrating to C++14 now
which features actually helped and which one did not
the traps and pitfalls compilers tried to pull on us
45 Days C++ Programming Language Training in Ambalajatin batra
Are you looking for C++Programming Training In Ambala?
Now you search ends here... Batra Computer Centre provides you best C++ Programming Language Training in Ambala Cantt. We also proides you training in C, HTML, PHP, Web Designing, Web Development, SEO, SMO also.
The Goal and The Journey - Turning back on one year of C++14 MigrationJoel Falcou
C++14 has been announced as the next best thing since sliced bread in terms of simplicity, performance and overall elegance of c++ code. This talk is the story of why and how we decided to migrate one of our old 'modern C++' software library -- BSP++, a C++ implementation of the BSP parallel programming model -- to C++14.
More than just a recollection of 'use this' or 'do that' mottos, this talk will try to ponder on :
why one should consider migrating to C++14 now
which features actually helped and which one did not
the traps and pitfalls compilers tried to pull on us
I am Charles B. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, Texas University, USA. I have been helping students with their homework for the past 6 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.
The amortized analysis method originally emerged as aggregated analysis (Ullmanm, Aho and Hopcroft used a version of it to analyze set representations) to analyze basic set operation in binary trees and union operations. The technique was first formally introduced by Robert Tarjan in his paper Amortized Computational Complexity. It was used to study balanced binary trees and the operation for set representations.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Acm aleppo cpc training fifth session
1. ACM Aleppo CPC Training
Part 1 C++ Programming Concepts
By Ahmad Bashar Eter
2. Math problems
• We’ve seen a lot of math problems till now.
• Remember to be precise when you use the floating point numbers
or constants.
• C++ cmath (or math.h) reference can be found hear:
http://www.cplusplus.com/reference/cmath/
• Some problems need the output to be formatted in special way
• You can set the number of decimals places after the point for float
numbers by setprecision(4) after including iomanip library.
• There are a lot of IO manipulation technique in c++ the flowing
table show a lot of flags to manipulate the IO streams.
3. Math problems
field member constant effect when set
independent
flags
ios::boolalpha read/write bool elements as alphabetic strings (true and false).
ios::showbase write integral values preceded by their corresponding numeric base prefix.
ios::showpoint write floating-point values including always the decimal point.
ios::showpos write non-negative numerical values preceded by a plus sign (+).
ios::skipws skip leading whitespaces on certain input operations.
ios::unitbuf flush output after each inserting operation.
ios::uppercase write uppercase letters replacing lowercase letters in certain insertion operations.
numerical base
(basefield)
ios::dec read/write integral values using decimal base format.
ios::hex read/write integral values using hexadecimal base format.
ios::oct read/write integral values using octal base format.
float format
(floatfield)
ios::fixed write floating point values in fixed-point notation.
ios::scientific write floating-point values in scientific notation.
adjustment
(adjustfield)
ios::internal
the output is padded to the field width by inserting fill characters at a specified
internal point.
ios::left the output is padded to the field width appending fill characters at the end.
ios::right the output is padded to the field width by inserting fill characters at the beginning.
4. Math problems
• For the full IO manipulation techniques see these pages and
remember to ask Google about it:
• http://www.cplusplus.com/reference/ios/ios_base/fmtflags/
• http://www.cplusplus.com/reference/iomanip/
5. Time Complexity Analysis:
• Time Complexity is a way to estimate the time that the algorithm
will take to do its job relative to the input size.
• consider we have an algorithm that iterate over all n element of the
input one time we can say that this algorithm complexity Is relative
to n.
• consider we have an algorithm that iterate over all n element and
for each element we iterate another n times (like if we have 2 for
loop nested inside each other) we can say that this algorithm
complexity Is relative to 𝒏 𝟐.
• There is a lot of notation to use when we want to estimate Time
Complexity, we are interested in the Big O notation.
6. Time Complexity Analysis:
• Big O notation used to estimate the upper bound of the growth rate
of a function and defined as:
• Consider we have two function 𝒇 𝒙 , 𝒈(𝒙) defined on some subset
of real numbers.
• We say that: 𝒇 𝒙 = 𝑶 𝒈 𝒙
if and only if there is positive constant C
and a number 𝒙 𝟎 such that
the flowing is true:
𝒇 𝒙 ≤ 𝑪 𝒈 𝒙 𝒇𝒐𝒓 𝒂𝒍𝒍 𝒙 > 𝒙 𝟎
Reference:
7. Time Complexity Analysis:
• Away from mathematics in real life when we want to compute the
complexity of an algorithm we see what is the maximum number of
operations that an algorithm may do by counting the number of
nested loops or by understanding the functions behavior.
• And in Big O notation we eliminate the low order terms (ex. If we
have an algorithm that do 𝟕𝒏 𝟑 + 𝟔𝒏 𝟐 𝒍𝒐𝒈 𝒏 + 𝒏 opration we say
this algorithm is order of n cube or 𝑶(𝒏 𝟑) ).
• So se consider the highest order (or the highest growth) term only
without the multiplied constants.
• From now we will calculate the complexity of every problem we will
solve.
Reference:
8. Time Complexity in CP:
• In competitive programing word we have to analyze the time
complexity of a problem in order to avoid the TLE response.
• Typically if your algorithm will do 𝟓𝟎 × 𝟏𝟎 𝟔
operation for each
second then it is ok.
• The following table contain the most common worst case Time
complexity with the maximum recommended input size:
Reference:
9. Time Complexity in CP:
CommentComplexityN
e.g. Enumerating permutations𝑶 𝒏! , 𝑶(𝒏 𝟔
)≤ [10…11]
e.g. DP TSP𝑶(𝟐 𝒏
× 𝒏 𝟐
)≤ [15…18]
e.g. DP with bitmask technique, Perfect matching𝑶(𝟐 𝒏 × 𝒏)≤ [18…22]
e.g. DP with 3 dimensions + O(n) loop𝑶(𝒏 𝟒)≤ 100
e.g. Floyd Warshall’s𝑶(𝒏 𝟑
)≤ 400
e.g. 2-nested loops + (a tree-related DS or binary
search)
𝑶(𝒏 𝟐
𝒍𝒐𝒈 𝟐 𝒏)≤ 𝟐 × 𝟏𝟎 𝟑
e.g. Bubble/Selection/Insertion Sort𝑶(𝒏 𝟐
)≤ 𝟏𝟎 𝟒
e.g. Merge Sort, building Segment Tree𝑶(𝒏 𝒍𝒐𝒈 𝟐 𝒏)≤ 𝟏𝟎 𝟔
Most contest problem has n ≤ 1M (I/O bottleneck)𝑶 𝒏 , 𝑶 𝒍𝒐𝒈 𝟐 𝒏 , 𝑶(𝟏)≤ 𝟏𝟎 𝟖
Reference:
10. Example 1: UVA - 441 - Lotto
In the German Lotto you have to select 6 numbers from the set {1,2,...,49}.
A popular strategy to play Lotto - although it doesn’t increase your chance of
winning — is to select a subset S containing k (k > 6) of these 49 numbers,
and then play several games with choosing numbers only from S.
For example, for k = 8 and S = {1, 2, 3, 5, 8, 13, 21, 34} there are 28 possible
games: [1,2,3,5,8,13], [1,2,3,5,8,21], [1,2,3,5,8,34], [1,2,3,5,13,21], ...,
[3,5,8,13,21,34].
Your job is to write a program that reads in the number k and the set S and then
prints all possible games choosing numbers only from S.
Solve At:
11. Example 1: UVA - 441 - Lotto
Input The input file will contain one or more test cases. Each test case consists of
one line containing several integers separated from each other by spaces. The
first integer on the line will be the number k (6 < k < 13). Then k integers,
specifying the set S, will follow in ascending order. Input will be terminated by a
value of zero (0) for k.
Output For each test case, print all possible games, each game on one line. The
numbers of each game have to be sorted in ascending order and separated from
each other by exactly one space. The games themselves have to be sorted
lexicographically, that means sorted by the lowest number first, then by the
second lowest and so on, as demonstrated in the sample output below. The test
cases have to be separated from each other by exactly one blank line. Do not put
a blank line after the last test case.
Solve At:
13. Example 2: UVA - 10360 - Rat Attack
Baaaam! Another deadly gas bomb explodes in Manhattan’s underworld.
Rats have taken over the sewerage and the city council is doing everything to get
the rat population under control.
As you know, Manhattan is organized in a regular fashion with streets and
avenues arranged like a rectangular grid.
Waste water drains run beneath the streets in the same arrangement and the
rats have always set up their nests below street intersections.
The only viable method to extinguish them is to use gas bombs like the one
which has just exploded.
Solve At:
14. Example 2: UVA - 10360 - Rat Attack
However, gas bombs are not only dangerous for rats. The skyscrapers above the
explosion point have to be evacuated in advance and so the point of rat attack
must be chosen very carefully.
The gas bombs used are built by a company called American Catastrophe
Management (ACM) and they are sold under the heading of “smart rat gas”.
They are smart because —when fired— the gas spreads in a rectangular fashion
through the under street canals.
The strength of a gas bomb is given by a number d which specifies the
rectangular “radius” of the gas diffusion area.
Solve At:
15. Example 2: UVA - 10360 - Rat Attack
For example, the figure shows what happens when a bomb with d = 1 explodes.
Solve At:
16. Example 2: UVA - 10360 - Rat Attack
The area of interest consists of a discrete grid of 1025 × 1025 fields.
Rat exterminator scouts have given a detailed report on where rat populations of
different sizes have built their nests. You are given a gas bomb with strength d and
your task is to find an explosion location for this gas bomb which extinguishes the
largest number of rats. The best position is determined by the following criteria:
1) The sum of all rat population sizes within the diffusion area of the gas bomb
(given by d) is maximal.
2) If there is more than one of these best positions then the location with the
“minimal” position will be chosen. Positions are ordered first by their x coordinate
and second by their y coordinate. Formally, given a location (x1, y1) on the grid, a
point (x2, y2) is within the diffusion area of a gas bomb with strength d if the
following equation holds: max(abs(x2 − x1), abs(y2 − y1)) ≤ d
Solve At:
17. Example 2: UVA - 10360 - Rat Attack
Input The first line contains the number of scenarios in the input.
For each scenario the first line contains the strength d of the gas bomb in the
scenario (1 ≤ d ≤ 50). The second line contains the number n (1 ≤ n ≤ 20000) of rat
populations. Then for every rat population follows a line containing three
integers separated by spaces for the position (x, y) and “size” i of the population
(1 ≤ i ≤ 255).
It is guaranteed that position coordinates are valid (i.e., in the range between 0
and 1024) and no position is given more than once.
Output For every problem print a line containing the x and y coordinate of the
chosen location for the gas bomb, followed by the sum of the rat population sizes
which will be extinguished. The three numbers must be separated by a space.
Solve At:
19. Bit manipulation
• In competitive programing many problems need to utilize numbers
as there bit representation.
• The techniques of utilize the numbers bit representation is called Bit
manipulation.
• We will see in this part how to:
1. set or unset bit in number and check the state of a bit.
2. Know the right most bit.
3. Check if a number is power of 2.
4. Count the number of ones in binary representation.
5. Check if a number is odd or even or divide by 2.
Reference:
20. Bit manipulation
• To set the i-th position bit in a number we can do an OR operator
with a number that have a single 1 at the i-th position like that:
num = num | (1 << i);
• To unset the i-th bit in a number we must clear the i-th bit and leave
all numbers as it by this:
num = num & ~(1 << i);
• To check the state of the i-th bit we can do AND operator on the
number and the i-th bit like this:
if(num & (1<<i))
• To filp the state of a bits in number we can use the XOR operator:
num ^ mask; // if num=101 and mask= 011 the result
// will be flipped at each 1 in the
// mask and will be 110
Reference:
21. Bit manipulation
• We can use the last 3 techniques to represent a subset of element of
a set by a number which the 0 or 1 in it means that we take or leave
the elements.
• E.g. the flowing set {1,3,9,7,5,4} and the subset {9,5,4} can be
represented as the binary number 001011.
• This number is called bit mask.
Reference:
22. Bit manipulation
• To clear the right most digit in a number we can do & on the
number and the number-1:
x = num & num-1;
• Check if the number is power of 2 we can clear the right most digit if
the number became 0 then it is power of 2 (power of 2 contain
single 1 in binary representation) and the only power of 2 that don’t
have ones in it is 0 then we can do like that:
if(x && !(x&x-1))
• To divide a number by 2 we can simply shift it to the right by 1 and
to multiply it by 2 we can shift it to the left.
• In general to divide by any x that power of 2 we can shift to the right
by the log2 of x, and to multiply by any x that is power of 2 we can
shift to the left by log2 of x.
Reference:
23. Bit manipulation
• To determine if a number is odd or even we can simply check the
first bit if it set:
if(x & 1) cout <<”odd”; else cout<<“even”;
• To count the number of ones effectively we can loop while the
number is not 0 and clear the right most 1:
while( x ) {
x = x&(x-1);
count++;
}
• To get the right most digit we can simply XOR the number with it
after removing the right most digit:
x ^ ( x & (x-1))
Reference:
24. Example 3: Monk's Choice of Numbers
Monk loves cakes! He visits the Binary Bakery to buy some of his favorite
cheesecakes.
The owner of the bakery, Bob, is a clever man. He does not want Monk to finish
all his cheesecakes. Hence, he plays a game.
The Monk is given N numbers and has to select K of these numbers. For each
number that Monk chooses, he will get as many cheesecakes as the number
of 1's in the Binary representation of the number i.e. the number of bits that are
set.
Help Monk find the maximum number of cakes that he can have.
Solve At:
25. Example 3: Monk's Choice of Numbers
Input:
The first line of input contains T. T test cases follow.
First line of each test cases contains 2 space-separated integers N and K.
The next line contains N space-separated integers.
Output:
For each test cases, print the answer in a new line.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 103
0 ≤ K ≤ N
0 ≤ Numbers ≤ 105
Solve At:
27. Example 4: Monk and his Friend
Monk has a very good friend, Puchi. As weird as his name, are the games he
plays.
One fine day, they decided to play a game to test how diverse their choices are.
Both of them choose exactly one integer each. Monk chooses an integer M and
Puchi chooses an integer P.
The diversity of their choices is defined as the number of bits whose status is
different in the binary representation of M and P , i.e. , count of bits that are
,either set in M and unset in P or set in P and unset in M.
Find the answer to their game.
Solve At:
28. Example 4: Monk and his Friend
Input:
First line contains T. T test cases follow.
Each test case consists of 2 space-separated integers P and M.
Output:
Print the answer to each test case in a new line.
Constraints:
1 ≤ T ≤ 104
0 ≤ M, P ≤ 1016
Solve At:
29. Example 4: Monk and his Friend
Sample Input
4
1 4
3 3
5 1
8 7
Solve At:
Sample Output
2
0
1
4