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. [转]python 装饰器

    以前你有没有这样一段经历:很久之前你写过一个函数,现在你突然有了个想法就是你想看看,以前那个函数在你数据集上的运行时间是多少,这时候你可以修改之前代码为它加上计时的功能,但是这样的话是不是还要大体读读 ...

  2. Mybatis的分页插件PageHelper分页失效的原因

    引用博客:个人博客地址:https://alexaccele.github.io/ PageHelper是Mybatis的一个很好的分页插件,但要使用它的分页功能需要注意一下几点 1.导入相关包,例如 ...

  3. 【Mysql sql inject】【入门篇】SQLi-Labs使用 part 2【12-14】

    这几关主要是考察POST形式的SQLi注入闭合 ## Less-12 - POST - Error Based- Double quotes- String ### 1)知识点 主要考察报错注入中的双 ...

  4. [转]HEX文件格式解析

    1.前言 本文主要讲述keil MDK 下STM32编译生成的的HEX镜像文件格式.并说明镜像load地址是如何添加进HEX文件的. 2.keil MDK如何在HEX文件中添加load addr 通过 ...

  5. 手把手教你写makefile【原创】

    Makefile  编写 Make  -f  makefile1 指定 如下是 本人的一点makefile学习笔记,再分享一个不错的写makefile总结的网址: http://www.cnblogs ...

  6. ubuntu cron 及 crontab 自动执行任务

    Add the below line (with tweaks) to the end of /etc/crontab: 30 23 * * * root shutdown -h now At 23: ...

  7. Advanced Installer 14.9 – WPF或winform应用程序打包成exe文件

    Advanced Installer14.9 下载地址:https://pan.baidu.com/s/1uj2QcxWcpGdqsjAinNPIAw 提取码:sa3r  选择Visual Studi ...

  8. elasticsearch5.0集群大数据量迁移方法及注意事项

    当es集群的数据量较小的情况下elasticdump这个工具比较方便,但是当数据量达到一定级别比如上百G的时候,elasticdump速度就很慢了,此时我们可以使用快照的方法进行备份 elasticd ...

  9. centos系统中perl进程病毒占用大量网络流量导致网络瘫痪的问题分析及解决方案

    故障现象: 1.系统在早上9点的时候非常慢,单台服务器占用流量很大,使交换机流量被占满,而连累挂在同一交换机上的其他应用也无法提供服务,或者速度非常慢     2.通过查看进程发现大量的perl程序占 ...

  10. 解决vmware虚拟机克隆后启动centos报错device eth0 does not seem to be present, delaying initialization

    centos启动报错: device eth0 does not seem to be present, delaying initialization ifcfg-eth0的配置文件里保存了以前的M ...