Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class DancingBits
- {
- static void Main()
- {
- int k = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- int length = 0;
- int lastBit = -1;
- int bitsCount = 0;
- for (int i = 0; i < n; i++)
- {
- int number = int.Parse(Console.ReadLine());
- int firstNonZeroBit = 0;
- for (int bitNumber = 31; bitNumber >= 0; bitNumber--)
- {
- int currentBit = (number >> bitNumber) & 1;
- if (currentBit == 1)
- {
- firstNonZeroBit = bitNumber;
- break;
- }
- }
- for (int bitNumber = firstNonZeroBit; bitNumber >= 0; bitNumber--)
- {
- int currentBit = (number >> bitNumber) & 1;
- if (currentBit == lastBit)
- {
- length++;
- }
- else
- {
- if (length == k)
- {
- bitsCount++;
- }
- length = 1;
- }
- lastBit = currentBit;
- }
- }
- if (length == k)
- {
- bitsCount++;
- }
- Console.WriteLine(bitsCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment