NOI ONLINE 第二场入门组 T1

广告区!

屠龙宝刀点击就送

NOI ONLINE 第二场入门组 T1

1. 题面

2. Input/Output

2.1 Input

2.2 Output

2.3 样例

2.3.1 样例输入

2.3.2 样例输出

2.4 样例解释

思路:无可奉告

这道题的话。。。第一眼肯定想到贪心啊!直到我们看到了数据范围。。。
于是,我们想到了:面向储存的源码级轻量预处理编程=打表
意思是说,我们可以用打表预处理来提前处理一些答案以达到优化的效果!

代码:

//
//  main.cpp
//  mathlab
//
//  Created by Theodore H on 4/17/20.
//  Copyright © 2020 Theodore H. All rights reserved.
//

#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <time.h>
#include <climits>
#include <deque>
#include <stdio.h>
#define ll long long
#define N 200005
using namespace std;
double tme[N];
ll n, L, v;
ll a[N];

int main()
{
    freopen("endless.in", "r", stdin);
    freopen("endless.out", "w", stdout);
    cin >> n >> L >> v;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n, greater<int>());//排序
    long long s = L;
    tme[0] = s * 1.0 / v;
    for(int i = 1; i <= n; i++)
    {
        s += a[i];
        tme[i] = s * 1.0 / v;
    }//这个循环是预处理。它会处理出:在释放前i个魔法的情况下sisyphus要用多久到山顶。
    int q;
    cin >> q;
    while(q--)
    {
        int t;
        cin >> t;
        if(tme[0] > t)
        {
            cout << 0 << endl;
            continue;
        }
        else if(tme[n] <= t)
        {
            cout << -1 << endl;
            continue;
        }
        cout << upper_bound(tme + 1, tme + n + 1, t) - tme << endl;//stl的二分
    }
    return 0;
}

没了

猜你喜欢

转载自www.cnblogs.com/earthlingblog/p/12795830.html