• 【codeforces 508C】Anya and Ghosts


    【题目链接】:http://codeforces.com/contest/508/problem/C

    【题意】

    每秒钟可以点一根蜡烛;
    这根蜡烛会燃烧t秒;
    然后会有m只鬼来拜访你;
    要求在鬼来拜访你的时候,至少有r根蜡烛是处于燃烧状态的;
    然后你能在任意一个时刻点蜡烛;
    问你最少需要点多少根蜡烛;

    【题解】

    对每只鬼进行考虑;
    则必须有r跟蜡烛能够”控制它”
    在什么地方控制呢?
    一定是离它最近的地方;
    因为这样;
    能够让这根蜡烛的使用范围达到最大;
    尽可能地覆盖到更多的鬼;
    这样那些鬼需要的蜡烛就能变少;
    就按照这个贪心策略搞就好;

    【Number Of WA

    0

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define ps push_back
    #define fi first
    #define se second
    #define rei(x) cin >> x
    #define pri(x) cout << x
    #define ms(x,y) memset(x,y,sizeof x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,0,-1,0,-1,-1,1,1};
    const int dy[9] = {0,0,-1,0,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int M = 3e2+100;
    
    struct abc
    {
        int x,need;
    };
    
    int m,t,r,ans = 0;
    abc a[M];
    map <int,int> dic;
    
    int main()
    {
        //freopen("D:\rush.txt","r",stdin);
        ios::sync_with_stdio(false);
        cin >> m >> t >> r;
        rep1(i,1,m)
            cin >> a[i].x,a[i].need = r;
        rep1(i,1,m)
            if (a[i].need>0)
            {
                int j = a[i].x-1;
                while (a[i].need)
                {
                    while (dic[j]==1) j--;
                    //dic[j]>0
                    if (j+t<a[i].x) return cout <<-1<<endl,0;
                    dic[j] = 1;
                    ans++;
                    rep1(k,i+1,m)
                        if (j+t>=a[k].x)
                            a[k].need--;
                    a[i].need--;
                }
            }
        cout << ans << endl;
        //printf("
    %.2lf sec 
    ", (double)clock() / CLOCKS_PER_SEC);
        return 0;
    }
  • 相关阅读:
    2016.10.15先占坑
    2016.10.11先占坑
    2016.10.13先占坑
    2016.10.7先占坑
    main()里面为什么要放String[] args
    对于一个给定的正整数 n ,请你找出一共有多少种方式使 n 表示为若干个连续正整数的和,要求至少包括两个正整数。
    求两个数的最大公约数的三种算法总结
    C++
    Dev-c5.11的使用
    客户端和服务器端的交互(未完待续)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626430.html
Copyright © 2020-2023  润新知