砍竹子

用set过得··用排序会超时
数据比较大,用排序肯定会超时

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include <iostream>
#include <algorithm>
#include <set>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
bool st;
struct cmp{
    
    
	bool operator()(int a, int b){
    
    
		return a > b;
	}
};
set<int, cmp> ss;
int main() {
    
    
	IOS;
	int n, m;
	cin >> n >> m;
	int x;
	for (int i = 0; i < n*m; i++) {
    
    
		cin >> x;
		ss.insert(x);
	}
	while (*ss.begin()!=*ss.rbegin()){
    
    
		int s = *ss.begin();
		ss.erase(s);
		ss.insert(s/2);
	}
	cout << *ss.begin()<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45465598/article/details/110789308