首先送大家一个【样例解释】:
1.qu
【解题报告】
这道题给人一种模拟的感觉,我们直接开一个栈,一个队列,一个堆就行了。值得注意的是,这道题埋了几个坑:一是放入数比取出数多的情况需要考虑;二是取出的数就算和要求的不符它也不在数据结构中了。
为此,代码如下:
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#define NAME "qu"
using namespace std;
const int N=1000;
int a,b,c;
int n;
int opt,v;
int temp1,temp2;
int flag[5];
stack<int> s;
queue<int> q;
priority_queue<int> heap;
int main()
{
freopen(NAME".in","r",stdin);
freopen(NAME".out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&opt,&v);
if(opt==1)
{
temp1++;
s.push(v);
q.push(v);
heap.push(v);
}
if(opt==2)
{
temp2++;
if(s.empty())flag[1]=1;
if(q.empty())flag[2]=1;
if(heap.empty())flag[3]=1;
if(!flag[1]){a=s.top();s.pop();if(a!=v)flag[1]=1;}
if(!flag[2]){b=q.front();q.pop();if(b!=v)flag[2]=1;}
if(!flag[3]){c=heap.top();heap.pop();if(c!=v)flag[3]=1;}
}
}
if(temp1>=temp2)
for(int i=1;i<=3;i++)
if(!flag[i])printf("YES\n");
else printf("No\n");
else printf("No\nNo\nNo\n");
return 0;
}
2.ming
【解题报告】
这道题是一个贪心题,我们只用将deadline从小打大排一个序,按照这个顺序来处理每一件事件。最后一个循环取max就完了。至于其正确性的证明,我就当没看到。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define NAME "ming"
using namespace std;
const int N=1e5;
int n;
struct event
{
int n,t,d;
}e[N+5];
int cmp(event a,event b)
{
return a.d<b.d;
}
int main()
{
freopen(NAME".in","r",stdin);
freopen(NAME".out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{scanf("%d%d",&e[i].t,&e[i].d);e[i].n=i;}
sort(e+1,e+1+n,cmp);
int now=0,ans=0;
for(int i=1;i<=n;i++)
{
now+=e[i].t;
ans=max(ans,now-e[i].d);
}
printf("%d",ans);
return 0;
}
3.zi
【解题报告】
这道题让我们看一看朱爷的题解:
朱爷的题解
以上
2017.7.3