51Nod 1596 搬货物
来源:互联网 发布:mac mini安装win7教程 编辑:程序博客网 时间:2024/05/16 04:31
思路:题目要求每次搬的货物的重量和必须是2的次方数,给出得数据也是2的次幂,显然,两个货物的重量和为2的次方数,当且仅当这两个货物的次幂相等,所以我们始终保持数组是升序的,当w[i]==w[i+1]时,去掉w[i],w[i+1]++后保留,否则去掉w[i],保留w[i+1],方案数+1。可以用优先队列优化。
但这题卡了输入,需要使用输入挂。。。。。。。
#include <map>#include <set>#include <cmath>#include <ctime>#include <stack>#include <queue>#include <cstdio>#include <cstring>#include <memory>#include <cctype>#include <bitset>#include <string>#include <vector>#include <climits>#include <cstring>#include <iostream>#include <iomanip>#include <algorithm>#include <functional>//#define FIN freopen("input.txt","r",stdin);//#define FOUT freopen("output.txt","w+",stdout);using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const int mod = 1e9 + 7;const double eps=1e-8;const double Pi=acos(-1.0);const int N=1000100;template <class T>//适用于正整数的输入挂inline void scan_d(T &ret){ char c; ret = 0; while ((c = getchar()) < '0' || c > '9'); while (c >= '0' && c <= '9') { ret = ret * 10 + (c - '0'), c = getchar(); }}struct cmp{ bool operator ()(int x, int y) { return x > y;//小的优先级高 }};priority_queue<int,vector<int>,cmp> que;int main(){ int n; scanf("%d",&n); int num; for(int i=0;i<n;i++) { scan_d(num); que.push(num); } int ans=0; int tmp1,tmp2; while(!que.empty()) { if(int(que.size()==1)) { ans++; break; } tmp1=que.top(); que.pop(); tmp2=que.top(); que.pop(); if(tmp1==tmp2) { tmp2++; que.push(tmp2); } else { ans++; que.push(tmp2); } } 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 搬货物
- 计划表
- LeetCode 309: 一个很清晰的DP解题思路
- XYNUOJ 1251 美元汇率(dollars)—贪心算法
- Java内部类
- 阿里云 php断点上传
- 51Nod 1596 搬货物
- 判断三角形
- XYNUOJ 1252 纪念品分组—贪心算法
- XYNUOJ 1253 磁带最大利用率问题-贪心算法
- DownloadManager实现下载、安装更新app功能
- HDU--OJ--1241 Oil Deposits
- G
- spring & velocity > context tool
- Thread.yield后线程释放资源的时间节点