hdu-5747 Aaronson (water problem)

Source: Internet
Author: User

Topic Links:

Aaronson

Time limit:4000/2000 MS (java/others)

Memory limit:131072/131072 K (java/others)


Problem descriptionrecently, Peter saw the equationX0+2X1+4x2++ 2mx M=n . He wants to find a solution  (x 0, x1 , X2 , Xm) In such a manner that∑I=0mxi is minimum and every xi (0≤i≤m) is non-negative.

Inputthere is multiple test cases. The first line of input contains an integerT(1≤T≤5) , indicating the number of test cases. For each test case:

The first contains and the integersNand m (0≤n,m≤9) .

Outputfor each test case, output the minimum value of∑I=0mxi.

Sample Input101 23 25 210 210 310 413 520 411 1112 3

Sample Output1223223232 Test Instructions:

Divide n into such, coefficients and smallest, greedy; AC Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath>//#include <bits/stdc++.h> #include <stack>using namespace std; #define for (i,j,n) for (int i=j;i <=n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long LONG ll;template<class t> void Read (T&num)    {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;}    while (p) stk[++ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E9;CONST int N=1e5+10;const int Maxn=500+10;const double eps= 1e-8;    LL f[60];void Init () {f[0]=1;    for (i,1,50) {f[i]=f[i-1]*2;        }}int Main () {int t;      Read (t);  Init ();         while (t--) {int n,m;         Read (n); read (m);         int ans=0;                for (int i=min (40,m); i>=0;i--) {if (N>=f[i]) {ans+=n/f[i];            N=n%f[i];        }} printf ("%d\n", ans); } return 0;}

  

hdu-5747 Aaronson (water problem)

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.