zoukankan      html  css  js  c++  java
  • poj 1477

    贪心+优先队列

    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <queue>
    using namespace std;
    const int maxn=50;
    int h[maxn],n;
    int main()
    {
    	int tot=0;
    	while(cin>>n&&n)
    	{
    		tot++;
    		int i;
    		priority_queue<int> q1;
    		priority_queue<int,vector<int>,greater<int>>q2;
    		int a;
    		for(i=1;i<=n;i++)
    		{
    			cin>>a;
    			q1.push(a);
    			q2.push(a);
    		}
    		int step=0,x,y;
    		while(q1.top()!=q2.top())
    		{
    			step++;
    			x=q1.top();q1.pop();
    			y=q2.top();q2.pop();
    			x-=1;
    			y+=1;
    			q1.push(x);
    			q2.push(y);
    		}
    		printf("Set #%d\nThe minimum number of moves is %d.\n\n",tot,step);
    	}
    	return 0;
    }
    


  • 相关阅读:
    搜索区间
    搜索插入位置
    旋转排序数组
    搜索二维矩阵
    njnja 安装
    rpmbuild打包
    snappy 安装
    mysql8 安装
    re2c安装
    make 安装
  • 原文地址:https://www.cnblogs.com/lj030/p/3002226.html
Copyright © 2011-2022 走看看