P2326 AKN’s PPAP
比较裸的贪心
从高位向下枚举,如果当前位为1的个数大于1,ans+=(1<<i),然后从这些数中再向下枚举。

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.25
using namespace std;
int n;
int ans;
queue<int>q[];
int t;
int a[];
int cnt;
int temp[];
int T;
void in(int &x)
{
int y=;
char c=g();x=;
while(c<''||c>'')
{
if(c=='-')
y=-;
c=g();
}
while(c<=''&&c>='')x=x*+c-'',c=g();
x*=y;
}
void o(int x)
{
if(x<)
{
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void bl(int now)
{
//ÓÃÊý×éÀ´´æ
int top;
cnt=;
while(q[now+].size()>)
{
top=q[now+].front();
/*if((top>>i)&1==1)
q[i].push(top);*/
q[now+].pop();
temp[++cnt]=top;
}
for(register int i=now;i>=;i--)
{
For(j,,cnt)
if((temp[j]>>i)&==)
q[i].push(temp[j]);
if(q[i].size()>)
{
ans+=(<<i);
if(i>)
bl(i-);
break;
}
}
} int main()
{
in(t);
T=t;
while(t--)
{
ans=;
in(n);
For(i,,n)
in(a[i]);
for(register int i=;i>=;i--)
{
For(j,,n)
if((a[j]>>i)&==)
q[i].push(a[j]);
if(q[i].size()>)
{
ans+=(<<i);
if(i>)
bl(i-);
break;
}
}
printf("Case #%d: %d ",T-t,ans);
p('\n');//o(ans),
For(i,,)
while(q[i].size()>)
q[i].pop(); } return ;
}

P2326 AKN’s PPAP的更多相关文章

  1. l洛谷 P2326 AKN’s PPAP

    P2326 AKN’s PPAP 题目描述 “I have a pen,I have an apple.Eh,Apple-Pen!. I have a pen,I have pineapple.En, ...

  2. 洛谷P2326 AKN’s PPAP

    https://www.luogu.org/problemnew/show/P2326 按位贪心 找到最高位&1的数,确定次高位的时候只从最高位&1的数里选 此次类推 #include ...

  3. Luogu P2326 AKN's PPAP【按位贪心】

    题目描述 “I have a pen,I have an apple.Eh,Apple-Pen!. I have a pen,I have pineapple.En,Pineapple-Pen! Ap ...

  4. 洛谷2114 bzoj3668[NOI2014]起床困难综合症

    题目描述 21世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm一直坚持与起床困难综合症作斗争.通过研究相关文献,他找到了该病的发病原因 ...

  5. BZOJ1087=Codevs2451=洛谷P1896&P2326互不侵犯

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2885  Solved: 1693[Submit][ ...

  6. Android—关于自定义对话框的工具类

    开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...

  7. [Spring]01_环境配置

    )在资源库界面点击Artifacts标签,然后点击libs-release-local,展开后依次点击org -> springframework -> spring.

  8. [LeetCode] Word Break II 拆分词句之二

    Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each ...

  9. jquery的animate({})动画整理

    在网页制作的过程中少不了用到各种动画,形式多种多样,flash,css,js,canvas,等等都能实现,对于其优劣和效果只能说各有千秋. 什么是动画效果,其实网页中的渐变效果就是一种很基础的动画,动 ...

随机推荐

  1. History API:ScrollRestoration

    By Paul Lewis(设计和性能倡导者)   翻译:江天 使用history api管理url是非常棒的一件事,可以说这是一个好web app的极为重要的特点.但它有一个缺点,滚动位置虽然被存储 ...

  2. saltstack系列~第三篇

    一 简介:今天来聊聊sls文件的编写二 目的:通过编写特定的sls文件实现环境的初始化和固定软件的安装三 目录: /srv/salt/ 可以构造deploy文件夹四 基本构造:配置基本以yaml规范. ...

  3. Properties文件工具类的使用--获取所有的键值、删除键、更新键等操作

    有时候我们希望处理properties文件,properties文件是键值对的文件形式,我们可以借助Properties类操作. 工具类如下:(代码中日志采用了slf4j日志) package cn. ...

  4. RAC

    RAC (Oracle网格计算技术) 编辑 Oracle RAC是Oracle Real Application Cluster的简写,官方中文文档一般翻译为“真正应用集群”,它一般有两台或者两台以上 ...

  5. Reverse Words in a String I & Reverse Words in a String II

    Reverse Words in a String I Given an input string, reverse the string word by word. For example,Give ...

  6. 关于python中的module

    python中的module(模块),关于这个概念以及使用时主要有以下几点需要注意: (1)import xx时,会首先将这个xx module中的代码执行一遍(且仅执行一遍): 例如: (2)模块包 ...

  7. ES系列十一、ES的index、store、_source、copy_to和all的区别

    1.基本概念 1.1._source 存储的原始数据._source中的内容就是搜索api返回的内容,如: { "query":{  "term":{   &q ...

  8. jvm系列三、java GC算法 垃圾收集器

    原文链接:http://www.cnblogs.com/ityouknow/p/5614961.html 概述 垃圾收集 Garbage Collection 通常被称为“GC”,它诞生于1960年 ...

  9. (常用)subprocess模块 详情官方

    subprocess包中定义有数个创建子进程的函数,这些函数分别以不同的方式创建子进程,所以我们可以根据需要来从中选取一个使用.另外subprocess还提供了一些管理标准流(standard str ...

  10. 安装最新版的2016版Pycharm后,激活码

    2016年安装Pycharm后,过段时间过期.亲测只需要复制以下激活码可以完美解决激活问题,又可以开心的写Python了.以下为激活码内容: BIG3CLIK6F-eyJsaWNlbnNlSWQiOi ...