【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("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:44  AWCXV  阅读(96)  评论(0编辑  收藏  举报