首页 > 其他分享 >C. Anya and Ghosts(Codeforces Round #288 (Div. 2))

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))

时间:2023-09-27 16:32:48浏览次数:31  
标签:memset EOF int d% Codeforces 288 sizeof include Round

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_Test

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_i++_02

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

struct node
{
    int x;
    int y;
}q[3010];

int a[3001];
int n,m,k;

int main()
{
    while(scanf("%d%d%d",&n,&m,&k)!=EOF)
    {
            memset(a,0,sizeof(a));
            memset(q,0,sizeof(q));
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
            }
            if(m<k)
            {
                printf("-1\n");
                continue;
            }
            int kk = m;
            int sum = 0;
            int flag = 0;
            for(int i=0;i<n;i++)
            {
                if(i == 0)
                {
                    sum = k;
                    for(int j=a[i]-k;j<a[i];j++)
                    {
                        q[j].y = 1;
                    }
                    for(int j=a[i];j<a[i]+m;j++)
                    {
                        q[j].x = kk;
                        kk--;
                    }
                }
                else
                {
                    if(q[a[i]].x < k)
                    {
                        //printf("q[%d].x = %d\n",a[i],q[a[i]].x);
                        int cnt = k - q[a[i]].x;
                        sum += cnt;
                        for(int j=a[i]-cnt;j<a[i];j++)
                        {
                            if(q[j].y == 1)
                            {
                                flag = 1;
                                break;
                            }
                            q[j].y = 1;
                            for(int v=j+1;v<m+j+1;v++)
                            {
                                q[v].x++;
                            }
                        }
                    }
                }
                if(flag == 1)
                {
                    break;
                }
            }
            if(flag == 1)
            {
                printf("-1\n");
            }
            else
            {
                printf("%d\n",sum);
            }

    }
    return 0;
}

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_Test_03

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_Test_04

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_i++_05

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_Test_06

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_#include_07

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_i++_08

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_Test_09

C. Anya and Ghosts(Codeforces Round #288 (Div. 2))_i++_10

标签:memset,EOF,int,d%,Codeforces,288,sizeof,include,Round
From: https://blog.51cto.com/u_14834528/7626424

相关文章

  • C. Anya and Ghosts( Codeforces Round #288 (Div. 2))
    #include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>usingnamespacestd;structnode{intx;inty;}q[3010];inta[3001];intn,m,k;intmain(){while(scanf("......
  • [892] Change the background color of a table in a Word document
    ref:python-docxChangingTableCellBackgroundColor.TochangethebackgroundcolorofatableinaWorddocumentusingPython,youcanusethepython-docxlibrary,whichallowsyoutocreateandmodifyWorddocumentsprogrammatically.Here'show......
  • Codeforces Round 900 (Div. 3)
    昨天晚上生病,没比(血亏)A:就是看k有没有在序列里B:随便放一个大的号码然后加i,应该就可以过了C:就是我们最少要拿k*(k+1)/2,最多可以拿k*(n+n-k+1)/2。啊,你问我怎么证明在这两个值里就一定可以拿到(当然是猜的!!)D:让f[x]表示当前出了多少次。然后就没个k看l[i],r[i]和j有没......
  • Codeforces Round 742 Div2 A-D题解
    CodeforcesRound742Div2A-D题解A.DominoDisaster这题就是说给出一些2x1tile,然后给出2xn的第一行构造,问第二行这个刚开始想着是啥dp,一看那么多人过了果断改思路,发现这题就是个模拟题,就是把U换成D,D换成U,L和R不影响,然后输出就行了代码#include<bits/stdc++.h>using......
  • 【教程】VIM的使用第九章-成对编辑的插件vim-surround以及收尾一些好用的常用插件
    书接上回,我们继续讲剩下的一些插件内容,以及对剩余的一些内容进行补充,这也就是vim的教程最后一章了~大家可以脱离苦海了~~但是后期想用好vim还是需要大家积极的练习多用。插件vim-surround在日常开发中我们需要成对的修改,比如一次性将单引号改为双引号,就可以用到这个插件了地址......
  • 9.26 SMU Autumn 2023 Round 5
    SMUAutumn2023Round5A-EveryoneLovestoSleep思路:将小于睡觉时间的闹钟加24:00,找到最小的时间min,答案即为min-睡觉时间#include<bits/stdc++.h>usingnamespacestd;//#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpair<int,i......
  • Codeforces Round 899 (Div. 2)
    Preface好久没现场打CF了(玩CC玩的.jpg),但这场久违的打的还不错,把Kusanagi_Misuzu这个小号也打上橙了虽然开场的时候状态不佳写的巨慢,但后面还是靠着ztc带我做出E1成功题数反超上大分接下来要考虑启动第三个小号了,只敢打Div2的FW是这样的A.IncreasingSequence比赛时候降智了......
  • Codeforces Round 738 (Div. 2) A. Mocha and Math
    给一个数组\(a_1,a_2,\cdots,a_n\)。可以执行以下操作任意次:选择\(l,r(1\leql<r\leqn)\),对于任意\(l\leqi\leqr\),同时执行所有\(a_{l+i}=a_{l+i}\&a_{r-i}\)。希望经过若干次操作后,\(a\)的最小的最大值。性质:\(x\&y\leqmin(x,y)\)。......
  • SMU Autumn 2023 Round 5
    SMUAutumn2023Round5A.EveryoneLovestoSleep把时间都转成分钟,然后存起来,二分找到离他睡觉点最近的一个时间段,减去他的睡觉点,如果最近的在第二天,则把中间的这段时间加起来#include<bits/stdc++.h>#defineintlonglong#definedebug(a)cout<<#a<<"="<<a<<'\n'......
  • Codeforces Round 898 (Div. 4)
    这是我的vp,不是正真的contest. A:不想多说,读者应该可以做到的!!! B:让g=product(移除掉0的a):如果有多过1个0答案肯定是0。如果只是有1个0答案就是g。没有0,答案就是max(g/a[i]*(a[i]+1))任何i。 C:没有仔细想那个profit的formula.手打表,sum就可以了。 D:就是双......