51nod 1596 搬货物
来源:互联网 发布:路由器和交换机 知乎 编辑:程序博客网 时间:2024/05/24 07:02
1596搬货物
现在有n个货物,第i个货物的重量是
样例解释:
1,1,2作为一组。
3,3作为一组。
Input
单组测试数据。第一行有一个整数n (1≤n≤10^6),表示有几个货物。第二行有n个整数 w1,w2,...,wn,(0≤wi≤10^6)。
Output
输出最少的运货次数。
Input示例
样例输入151 1 2 3 3
Output示例
样例输出12
暴力乱搞一发过了,时间还贼快。。。
#include <iostream>#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1100000;ll b[2][N];const int MAXS=10*1024*1024;char buf[MAXS],*ch;void read(ll &x){ while(*(++ch)<'0'); for(x=0;*ch>='0';++ch) x=x*10+*ch-'0';}void read_init(){ ch=buf-1; fread(buf,1,MAXS,stdin);}int main(){ ll n; int t; read_init(); read(n); for(int i=0;i<(int)n;i++) read(b[0][i]); int n1=(ll)n,n2=0; t=0; while(1) { if(n1==n2) break; sort(b[t],b[t]+n1); n2=0; for(int i=0;i<n1;i++) { if(i<n1-1&&b[t][i]==b[t][i+1]) { b[t^1][n2++]=b[t][i]+1; i++; } else { b[t^1][n2++]=b[t][i]; } } t^=1; swap(n1,n2); } cout<<n1<<endl;}
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 搬货物
- mysql优化策略
- okhttp的简单使用例子
- 前端开发工具整理
- Python使用urlib添加头部实现https请求 同时使用PyExecJS-1.4.0触发JS
- 直播服务器的搭建以及感想
- 51nod 1596 搬货物
- 多线程(5)- 控制线程
- Http与Servlet数据传输全流程
- spark 2.1 BlockManagerMasterEndpoint
- Echarts折线图点击事件
- 欢迎使用SuperTextView
- 简单说说Android四中启动方式
- Windows中python机器学习numpy,scipy,matplotlib的安装
- AngularJS中的一次性数据绑定 (bindonce)