码迷,mamicode.com
首页 > 其他好文 > 详细

【CJ】APAC_RoundA

时间:2016-07-10 21:46:40      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

今天一天跟女神学姐一起打了一场APAC_RoundA, 做了AB, 还有CD的小数据。

还有晴神的友情帮助和营养毒奶。

D其实是比较简单的,分很多,应该说是性价比最高的题目,没有抓住。

B题枚举水位的高度,然后搜出联通块,涨水。

C题我还是不怎么确定,不知道为啥裸牛顿就能过大数据,这题挺二的。

D题是一个比较巧妙的题目,一下卡住了,其实只要枚举所有选的8个牌,然后分成两组,把两组可能的组合都枚举出来,然后按照花费排序,保证能获得的攻击力也单调递增。

然后把两个单调队列比对一下就行了,很快。

什么把程序往集群上扔的,那可真蠢。

 

这里贴一下BD的程序吧。D是比赛完了以后写的。实力不济,没办法咯,努力拿到T恤。

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int Answer;
int M;
int N;

bool dfs(int cnt, int x, int y, int H, vector<vector<int>>& v, vector<vector<int>>& g)
{


    if (x < 0 || y < 0 || x == M || y == N) return false;
    
    if (g[x][y] >= H) return true;
    
    if (v[x][y]) return true;
    v[x][y] = cnt;
    
    bool f0 = dfs(cnt,x - 1, y, H, v, g);
    bool f1 = dfs(cnt,x + 1, y, H, v, g);
    bool f2 = dfs(cnt,x, y - 1, H, v, g);
    bool f3 = dfs(cnt,x, y + 1, H, v, g);
    bool f = f0 && f1 && f2 && f3;

    return f;
}

int main()
{
    ifstream fin("in.txt");
    ofstream fout("out.txt");

    int T;
    fin >> T;
    for (int t = 0; t < T; t++)
    {
        fin >> M >> N;
        auto g = vector<vector<int>>(M,vector<int>(N,0));
        
        int maxH = 0;
        for (int i = 0; i < M;i++)
        for (int j = 0; j < N; j++)
        {
            fin >> g[i][j];
            maxH = max(maxH,g[i][j]);
        }
        
        Answer = 0;
        for (int H = 1; H <= maxH; H++)
        {
            auto v = vector<vector<int>>(M, vector<int>(N, 0));
            
            vector<bool> can = vector<bool>(M*N + 1, false);

            int cnt = 1;
            for (int i = 0; i < M;i++)
            for (int j = 0; j < N;j++)
            if (v[i][j] == 0 && g[i][j] < H)
            {
                can[cnt] = dfs(cnt, i, j, H, v, g);
                cnt++;
            }

            for (int i = 0; i < M; i++)
            for (int j = 0; j < N; j++)
            if (v[i][j] && can[v[i][j]])
            {
                Answer += (H - g[i][j]);
                g[i][j] = H;
            }
            
            /*/
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++) fout << v[i][j] << " ";
                fout << endl;
            }

            /*/
            /*/
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++) fout << g[i][j] << " ";
                fout << endl;
            }
            /*/

        }
        fout << "Case #" << t + 1 << ": ";
        fout << Answer;
        fout << endl;
    }

    return 0;
}
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

bool cmp(pair<long long, long long>& a, pair<long long, long long>& b)
{
    return (a.first < b.first || (a.first == b.first && a.second > b.second));
}

vector<pair<long long, long long>> make_queue(vector<int>& Index, int base, vector<int>& K, vector<int>& L, vector<vector<long long>>& A, vector<vector<long long>>& C)
{
    vector<pair<long long, long long>> ret;

    int x1 = Index[base + 0];
    int x2 = Index[base + 1];
    int x3 = Index[base + 2];
    int x4 = Index[base + 3];

    int cost = 0;
    for (int i1 = L[x1]; i1 <= K[x1]; i1++)
    for (int i2 = L[x2]; i2 <= K[x2]; i2++)
    for (int i3 = L[x3]; i3 <= K[x3]; i3++)
    for (int i4 = L[x4]; i4 <= K[x4]; i4++)
    {
        long long totC = C[x1][i1] + C[x2][i2] + C[x3][i3] + C[x4][i4];
        long long totA = A[x1][i1] + A[x2][i2] + A[x3][i3] + A[x4][i4];
        ret.push_back(make_pair(totC, totA));
    }

    sort(ret.begin(), ret.end(), cmp);
    
    vector<pair<long long, long long>> ret1;

    long long preC = -1;
    long long preA = -1;
    for (auto x : ret)
    {
        if (x.first != preC && x.second > preA)
        {
            ret1.push_back(x);
            preC = x.first;
            preA = x.second;
        }
    }
    return ret1;
    
}

vector<int> find1(int x)
{
    vector<int> ret;
    ret.clear();
    for (int i = 1; i <= 13; i++)
    {
        if (x & 1) ret.push_back(i);
        x = x / 2;
    }
    return ret;
}

int main()
{
    ifstream fin("in.txt");
    ofstream fout("out.txt");

    int T;
    fin >> T;
    for (int t = 0; t < T; t++)
    {
        int M, N;

        fin >> M >> N;

        auto K = vector<int>(N + 1, 0);
        auto L = vector<int>(N + 1, 0);
        auto A = vector<vector<long long>>(N + 1, vector<long long>(1, 0));
        auto C1 = vector<vector<long long>>(N + 1, vector<long long>(1, 0));
        auto C = vector<vector<long long>>(N + 1, vector<long long>(1, 0));
    
        for (int i = 1; i <= N; i++)
        {
            fin >> K[i] >> L[i];
            long long tmp;
            for (int j = 1; j <= K[i]; j++)
            {
                fin >> tmp;
                A[i].push_back(tmp);
            }
            for (int j = 1; j <= K[i] - 1; j++)
            {
                fin >> tmp;
                C1[i].push_back(tmp);
            }
            
            C[i] = A[i];
            C[i][L[i]] = 0;
            for (int j = L[i] + 1; j <= K[i]; j++)
                C[i][j] = C[i][j - 1] + C1[i][j - 1];
        }
        
        long long Answer = 0;
        
        for (int i = 0; i <= (1 << N) - 1; i++)
        {
            auto Index = find1(i);
            if (Index.size() != 8) continue;

            auto q1 = make_queue(Index, 0, K, L, A, C);
            auto q2 = make_queue(Index, 4, K, L, A, C);

            for (int i = 0; i < q1.size(); i++)
            {
                int j = q2.size() - 1;
                while (q1[i].first + q2[j].first > M && j >= 0) j--;
                if (j < 0) break;
                Answer = max(Answer, q1[i].second + q2[j].second);
            }
        
        }

        fout << "Case #" << t + 1 << ": ";
        fout << Answer << endl;

    }

    return 0;
}

 

【CJ】APAC_RoundA

标签:

原文地址:http://www.cnblogs.com/soya/p/5658489.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!