其他分享
首页 > 其他分享> > CF720A Closing ceremony 贪心

CF720A Closing ceremony 贪心

作者:互联网

正解:贪心

解题报告:

传送门!

先考虑如果只有一列怎么搞?那就肯定是尽量走到最远的地方

然后用点儿类似的思想,现在考虑有两列的情况QAQ

为了方便表述,这里给每个位置两个值,a表示离一号入口的距离,b表示离二号入口的距离

可以先把从一号入口进去的安排了,所以考虑按体力从小往大考虑,然后在能满足a的情况下尽量选b比较大的位置

然后再处理二号入口的,就按体力从大往小考虑一下就好

具体实现的话就先把所有坐标按a排序,然后满足的就加入堆,堆的内部按b排序就好

over

先放个还没有A的代码我等下再改过来QAQ

 

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)

const int N=10000+100;
int n,m,k,a[N],nw=1,nod_cnt;
struct node{int x,y,disa,disb;}nod[N];
il bool operator < (node gd,node gs){return gd.disb>gs.disb;}
priority_queue<node>Q;

il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il bool cmp(node gd,node gs){return gd.disa<gs.disa;}
il bool cmq(ri gd,ri gs){return gd>gs;}

int main()
{
    freopen("720a.in","r",stdin);freopen("720a.out","w",stdout);
    n=read();m=read();rp(i,1,n)rp(j,1,m)nod[++nod_cnt]=(node){i,j,i+j,i+m+1-j};sort(nod+1,nod+1+nod_cnt,cmp);
    k=read();rp(i,1,k)a[i]=read();sort(a+1,a+1+k);
    rp(i,1,k){while(a[i]>=nod[nw].disa && nw<=nod_cnt)Q.push(nod[nw++]);if(Q.empty())return printf("NO\n"),0;Q.pop();}
    rp(i,nw,nod_cnt)Q.push(nod[i]);
    k=read();rp(i,1,k)a[i]=read();sort(a+1,a+1+k);
//    printf("nmdwsm??? %d\n",Q.size());
//    while(!Q.empty())printf("%d\n",Q.top().disb),Q.pop();
    rp(i,1,k){while(a[i]<Q.top().disb && !Q.empty())Q.pop();if(Q.empty())return printf("NO\n"),0;Q.pop();}
    printf("YES\n");
    return 0; 
}
View Code

 

 

标签:ceremony,ch,rp,nod,CF720A,int,read,Closing,define
来源: https://www.cnblogs.com/lqsukida/p/10574847.html