UVA 10718 Bit Mask

Source: Internet
Author: User

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineSC3 (x, Y, z) scanf ("%lld%lld%lld", &x, &y, &z)6 #definePF (x) printf ("%lld\n", X)7 #definefor (i,b,e) for (int i=b;i<=e;i++)8 #defineFOR1 (i,b,e) for (int i=b;i>=e;i--)9 #defineCL (x, y) memset (x,y,sizeof (×))Ten using namespacestd; OnetypedefLong Longll; All bit[ *]; - inta[ *]; - voidInit () the { -bit[0] =1; -for (I,1, to) -     { +Bit[i] =2* bit[i-1]; -     } + } A intMain () at { - ll N, L, U, MAX; - init (); - //cout << bit[0] << Endl; -      while(~sc3 (N, L, U)) -     { inMAX =0; -for (I,0, to) to         { +A[i] = N%2; -N/=2; the         } *FOR1 (I, to,0) $         {Panax NotoginsengMAX + =Bit[i]; -             if((a[i] = =0&& MAX > U) | | (MAX > L && a[i] = =1))//the next condition is to consider the smallest max value that fits in the range theMAX-=Bit[i]; +         } A PF (MAX); the     } +     return 0; -}
View Code

The main consideration is the binary problem, there is a suitable range of the smallest ans value, is a good thinking problem

UVA 10718 Bit Mask

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.