P2326 AKN’s PPAP
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的更多相关文章
- 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, ...
- 洛谷P2326 AKN’s PPAP
https://www.luogu.org/problemnew/show/P2326 按位贪心 找到最高位&1的数,确定次高位的时候只从最高位&1的数里选 此次类推 #include ...
- 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 ...
- 洛谷2114 bzoj3668[NOI2014]起床困难综合症
题目描述 21世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm一直坚持与起床困难综合症作斗争.通过研究相关文献,他找到了该病的发病原因 ...
- BZOJ1087=Codevs2451=洛谷P1896&P2326互不侵犯
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2885 Solved: 1693[Submit][ ...
- Android—关于自定义对话框的工具类
开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...
- [Spring]01_环境配置
)在资源库界面点击Artifacts标签,然后点击libs-release-local,展开后依次点击org -> springframework -> spring.
- [LeetCode] Word Break II 拆分词句之二
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each ...
- jquery的animate({})动画整理
在网页制作的过程中少不了用到各种动画,形式多种多样,flash,css,js,canvas,等等都能实现,对于其优劣和效果只能说各有千秋. 什么是动画效果,其实网页中的渐变效果就是一种很基础的动画,动 ...
随机推荐
- [JXOI2018]游戏 (线性筛,数论)
[JXOI2018]游戏 \(solution:\) 这一道题的原版题面实在太负能量了,所以用了修改版题面. 这道题只要仔细读题,我们就可以将题目的一些基本性质分析出来:首先我们定义:对于某一类都可以 ...
- TCP网络协议通信原理(客户端和服务器端)
下面直接用代码来说明TCP协议的基础知识: 服务器端代码块: from socket import * from time import ctime ''' 指定主机地址.工作端口号.接收缓存的长度 ...
- python - class类 (七) 三大特性 - 封装 结尾
封装: # 封装 #第一层,类就是麻袋,本身就是一种封装 #第二层,类中定义私有的,至在类的内部使用,外部无法访问 #第三层,封装在于明确区分内外,使得类实现者可以修改封装内的东西二不影响外部调用者 ...
- 2018-2019 前期任务(一):资料阅读&Python入门
2018-2019 前期任务(一):资料阅读&Python入门 资料原文地址:Dumbcoin - An educational python implementation of a bitc ...
- Pytorch 资料汇总(持续更新)
1. Pytorch 论坛/网站 PyTorch 中文网 python优先的深度学习框架 Pytorch中文文档 Pythrch-CN文档地址 PyTorch 基礎篇 2. Pytorch 书籍 深度 ...
- Linux mmc framework2:基本组件之block
1.前言 本文主要block组件的主要流程,在介绍的过程中,将详细说明和block相关的流程,涉及到其它组件的详细流程再在相关文章中说明. 2.主要数据结构和API 2.1 struct mmc_ca ...
- 关于 MVCC 的基础【转】
1. 什么是MVCC 1.1 基础概念 MVCC,Multi-Version Concurrency Control,多版本并发控制.MVCC 是一种并发控制的方法,一般在数据库管理系统中,实现对数据 ...
- phantomjs 下拉滚动条获取网页的全部源码
//codes.js var system = require('system'); var fs = require("fs"); //console.log('Loading ...
- git安装及基础用法
1.安装GitGit-2.9.3-64-bit.exe 2.打开Git Bash,设置用户名,Email $ git config --global user.name "Your Name ...
- 002_mtr_a network diagnostic tool
一. mtr combines the functionality of the traceroute and ping programs in a single network diagnostic ...