You are not logged in. Please login at www.codechef.com to post your questions!

×

How to solve this codeforces problem?

Link to the problem is.... http://codeforces.com/contest/588/problem/C

asked 30 Oct '15, 19:04

akhileshydv20's gravatar image

2★akhileshydv20
173
accept rate: 0%


link

answered 30 Oct '15, 21:03

dragonemperor's gravatar image

3★dragonemperor
89321134
accept rate: 10%

in this question if u sum all the numbers then a number will formed that has x no of digits =1 set bits means that ans=x.. but the problem is no which we get after sum of all the no can be very large beacuse 2^(n) n can be 10000... so what we are going to do is this we make a array arr[100000]={0}; ex--the pow of 2's are--->3,3,5

if no is 2^(3) we will set the arr[3]++; -->arr[3]=1; if this no again comes arr[3]++ ;----->arr[3]=2 means 2^(3) comes two times... now 2^(5) arr[5]++;

now we have array 1-index based 0 0 2 0 1
now see here if u have 2^(3) two times u can repersent it 2.(2^(3))--->2^(4) if arr[i] is even then: arr[i+1]+=arr[i]/2; arr[i]=0;

now think othe thing if arr[i] is odd means 2^(3) three times sum is 3.2^(3)--->2.2^(3)+2^(3)--->2^(4)+2^(3) ; means current bit is also set and increse next bit value to arr[i]/2; now we can say that if arr[i] is odd then:: arr[i+1]+=arr[i]/2; arr[i]=1;

we are doing a simple work repersenting the binary number manually at last in our array each value of array either have 0 or 1 no other value ,,,means we have succcessfully repersented the sum of powers of two(as in question) as a array from left to right

so simply calculte number of set value of the array :: arr[i]==1; thats our ans==.. now u can done the example by yourself this is the main hurdle in this question that how to repersent large sum of the numbers which is in form of 2^(x)...... i have put my best here...i guess u will definetly understand this ... happy to help...if u find any difficulty although.

link

answered 31 Oct '15, 16:21

rohitangira's gravatar image

2★rohitangira
939
accept rate: 0%

got the idea thanks :-)

(31 Oct '15, 17:35) akhileshydv202★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×655

question asked: 30 Oct '15, 19:04

question was seen: 944 times

last updated: 01 Nov '15, 19:04