zoukankan      html  css  js  c++  java
  • NKOJ2322: OSU!

      最简单的,贪心算法就可以解决。

    #include<iostream>
    using namespace std;
    #define ll long long
    
    int main()
    {
        int n,v,result=0;
        cin>>n>>v;
        ll nt=-100;
        for(int i=0;i<n;++i)
        {
            ll tempT;
            cin>>tempT;
            if(tempT-nt>=v)
            {
                nt=tempT;
                ++result;
            }
        }
        cout<<result*100<<endl;
    }
    View Code

      顺便放上最开始写的复杂不堪的dp

    #include<iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;
    #define ll long long
    struct line {
        ll left, right, val;
    };
    
    ll Max(int a, int b)
    {
        return a > b ? a : b;
    }
    
    int findPreV(const vector<line>& lines, int L)//找到编号为L的线段前的线段编号
    {
        int i;
        for (i = L-1; i >= 0; --i)
        {
            if (lines[i].right <= lines[L].left)
            {
                break;
            }
        }
        if (i == lines.size())
        {
            return -1;
        }
        return i ;
    }
    
    int v[100005];
    
    int main()
    {
        ios::sync_with_stdio(false);
        ll n,V;
        cin >> n>>V;
        if (V == 0)
        {
            cout << n * 100 << endl;
            return 0;
        }
        vector<line> lines(n);
        for (int i = 0; i < n; ++i)
        {
            int sec;
            cin >> sec;
            lines[i].left = sec;
            lines[i].right = sec+V;
            lines[i].val = 100;
        }
        v[0] = 0;
        v[1] = lines[0].val;
        for (int i = 2; i <= n; ++i)
        {
            int lineNum = i - 1;
            int preLineNum = findPreV(lines, lineNum);
            v[i] = Max(v[i - 1], v[preLineNum + 1] + lines[lineNum].val);
        }
        cout << v[n] << endl;
        //system("pause");
    }
    View Code
  • 相关阅读:
    svn问题(队列)
    linux的七大运行级别及级别修改
    Elasticsearch配置文件说明
    openstack-swift云存储部署(二)
    openstack-swift云存储部署(一)
    今天发现一些很有意思的ubuntu命令
    python使用xlrd 操作Excel读写
    Python初记
    SQL Server常用命令
    SQL Server 流程控制
  • 原文地址:https://www.cnblogs.com/Algorithm-X/p/7522011.html
Copyright © 2011-2022 走看看