51nod 1596 搬货物
来源:互联网 发布:json图片解析 编辑:程序博客网 时间:2024/06/08 07:41
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1596
思路:
2^2+2^2=2^3
2^2+2^2+2^2+2^2=2*(2^3)
2^3+2^3=2^4
可以一直往上“合并”。单出来的就拿出来。
#include<cstdio>#include<queue>#include<iostream>#include<vector>#include<map>#include<cstring>#include<string>#include<set>#include<stack>#include<algorithm>#define cle(a) memset(a,0,sizeof(a))#define inf(a) memset(a,ox3f,sizeof(a))#define ll long long#define Rep(i,a,n) for(int i=a;i<=n;i++)using namespace std;const int INF = ( 2e9 ) + 2;const int maxn = 1e6+100;int a[maxn];template <class T>inline void scand(T &ret){ char c; ret = 0; while ((c = getchar()) < '0' || c > '9'); while (c >= '0' && c <= '9') { ret = ret * 10 + (c - '0'), c = getchar(); }}int main(){ int n; scanf("%d",&n); int mx=-1; for(int i=0;i<n;i++) { int t; scand(t); a[t]++; if(mx<t)mx=t; } int ans=0; for(int i=0;i<=mx+99;i++) { if(a[i]) { a[i+1]+=a[i]/2; ans+=a[i]%2; } } printf("%d\n",ans);}
阅读全文
0 0
- 51NOD 1596 搬货物
- 51Nod-1596-搬货物
- 51nod 1596 搬货物
- 51nod 1596 搬货物
- 51nod 1596 搬货物
- 51Nod 1596 搬货物
- 51nod-1596 搬货物
- 51Nod 1596 搬货物
- 51nod-1596 搬货物
- 51nod 1596 搬货物
- 51Nod 1596 搬货物
- 51nod 1596 搬货物
- 51Nod 1596 搬货物
- 51nod 1596 搬货物
- 51nod 1596 搬货物
- 51nod 1596 搬货物
- 51nod 1596 搬货物
- 51nod 搬货物
- Tomcat源码解析(7)
- zabbix3.2监控日志脚本
- 看过三生三世的桃花,你吃过凌晨三点的桃子吗?
- Selenium + Headless Chrome with Python3
- Android 获取百度地图开发版和发布版sha1
- 51nod 1596 搬货物
- 设计模式之原型模式
- EXTjs鼠标右键单击事件,及 location.href=encodeURI()请求操作
- spring boot 集成solr
- 十条jQuery代码片段助力Web开发效率提升
- 传统以太网和时间敏感网络TSN的区别
- POJ1417
- CSS3常用选择器和属性
- ImageView的scaleType的属性理解