其他分享
首页 > 其他分享> > Meet in another world, enjoy tasty food!(思维)

Meet in another world, enjoy tasty food!(思维)

作者:互联网

传送门:Meet in another world, enjoy tasty food!
题目给的数据范围很大,$n$只有1000的范围,考虑$O(N^2)$的做法,并且由于数值很大,那么可以往除法的角度思考。

#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
const int N = 1010;
typedef long long ll;
struct node{
    ll id, value;
};
vector<node> vec;
map<ll, ll> mp;
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++){
        ll x;
        cin >> x;
        vec.push_back({i, x});
    }
    int ans = 0;
    while(1){
        ll minn = 1e18;
        int pos = 0;
        for(int i = 0; i < vec.size(); i ++){
            ll temp = ceil((double)vec[i].value / (i + 1));
            if(minn > temp){
                minn = temp;
            }
		}
        for(int i = 0; i < vec.size(); i ++){
            ++ pos;
        	vec[i].value -= (minn - 1)* pos + i + 1;
        	if(vec[i].value <= 0){
        		mp[++ ans] = vec[i].id;
				vec.erase(vec.begin() + i);		
        		i --; 
			}
		}
		if(vec.size() == 0)
			break;
    }
    for(int i = 1; i <= n; i ++)
    	cout << mp[i] << ' ';
    return 0;
}

标签:enjoy,minn,food,ll,value,int,tasty,vec,include
来源: https://www.cnblogs.com/pureayu/p/14746544.html