• BNUOJ-29364 Bread Sorting 水题


      题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29364

      题意:给一个序列,输出序列中,二进制1的个数最少的数。。

      随便搞搞就行了,关于更多算法,可以看<My github>.

      1 //STATUS:C++_AC_290MS_1324KB
      2 #include <functional>
      3 #include <algorithm>
      4 #include <iostream>
      5 //#include <ext/rope>
      6 #include <fstream>
      7 #include <sstream>
      8 #include <iomanip>
      9 #include <numeric>
     10 #include <cstring>
     11 #include <cassert>
     12 #include <cstdio>
     13 #include <string>
     14 #include <vector>
     15 #include <bitset>
     16 #include <queue>
     17 #include <stack>
     18 #include <cmath>
     19 #include <ctime>
     20 #include <list>
     21 #include <set>
     22 //#include <map>
     23 using namespace std;
     24 //#pragma comment(linker,"/STACK:102400000,102400000")
     25 //using namespace __gnu_cxx;
     26 //define
     27 #define pii pair<int,int>
     28 #define mem(a,b) memset(a,b,sizeof(a))
     29 #define lson l,mid,rt<<1
     30 #define rson mid+1,r,rt<<1|1
     31 #define PI acos(-1.0)
     32 //typedef
     33 //typedef __int64 LL;
     34 //typedef unsigned __int64 ULL;
     35 //const
     36 const int N=110;
     37 const int INF=0x3f3f3f3f;
     38 const int MOD=100000,STA=8000010;
     39 //const LL LNF=1LL<<60;
     40 const double EPS=1e-8;
     41 const double OO=1e15;
     42 const int dx[4]={-1,0,1,0};
     43 const int dy[4]={0,1,0,-1};
     44 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
     45 //Daily Use ...
     46 inline int sign(double x){return (x>EPS)-(x<-EPS);}
     47 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
     48 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
     49 template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
     50 template<class T> inline T Min(T a,T b){return a<b?a:b;}
     51 template<class T> inline T Max(T a,T b){return a>b?a:b;}
     52 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
     53 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
     54 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
     55 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
     56 //End
     57 
     58 int T,n;
     59 
     60 unsigned int table[256] =
     61 {
     62     0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
     63     1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
     64     1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
     65     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
     66     1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
     67     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
     68     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
     69     3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
     70     1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
     71     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
     72     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
     73     3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
     74     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
     75     3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
     76     3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
     77     4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
     78 };
     79 int BitCount(unsigned int n)
     80 {
     81     return table[n &0xff] +
     82         table[(n >>8) &0xff] +
     83         table[(n >>16) &0xff] +
     84         table[(n >>24) &0xff] ;
     85 }
     86 
     87 int main(){
     88   //  freopen("in.txt","r",stdin);
     89     int i,j,ca=1,a,t,hig,hignum;
     90     scanf("%d",&T);
     91     while(T--)
     92     {
     93         hig=INF;
     94         scanf("%d",&n);
     95         while(n--){
     96             scanf("%d",&a);
     97             t=BitCount(a);
     98             if(t<hig || (t==hig && a<hignum))
     99                 hig=t,hignum=a;
    100         }
    101 
    102         printf("Case %d: %d
    ",ca++,hignum);
    103     }
    104     return 0;
    105 }
  • 相关阅读:
    iOS中点击按钮复制指定内容
    iOS开发中,获取图片之后保存或下载到本地相册中
    This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value
    ios中友盟集成好使用总结
    ios中仿蚂蚁森林动画效果
    window frida安装
    Android_server提示端口被占用
    Android stdio Apktool源码编译
    Android ooVoo Apk附件关联分析
    cocos2d-x-2.2.6 project-creator文件夹下python.bat
  • 原文地址:https://www.cnblogs.com/zhsl/p/3282100.html
Copyright © 2020-2023  润新知