HDU 4302 Contest 1
维护两个优先队列即可。要注意,当出现蛋糕的位置刚好在狗的位置时,存在右边。
注意输出大小写。。。
#include <iostream>
#include <queue>
#include <cstdio> using namespace std; struct RP{
int pos;
bool operator < (const RP &t)const{
if(pos>t.pos) return true;
return false;
}
};
struct LP{
int pos;
bool operator < (const LP &t)const{
if(pos<t.pos) return true;
return false;
}
}; priority_queue<LP>LeftPush;
priority_queue<RP>RightPush;
LP tmpL;
RP tmpR; void Clear(){
while(!LeftPush.empty())
LeftPush.pop();
while(!RightPush.empty())
RightPush.pop();
} int main(){
int T,P,N,POS,kase=0;
int op,position;
int direct,left,right;
bool flagL,flagR;
scanf("%d",&T);
int ans;
while(T--){
Clear();
POS=0;
direct=1;
ans=0;
scanf("%d%d",&P,&N);
while(N--){
scanf("%d",&op);
if(!op){
scanf("%d",&position);
if(position>=POS){
tmpR.pos=position;
RightPush.push(tmpR);
}
else if(position<POS){
tmpL.pos=position;
LeftPush.push(tmpL);
}
}
else{
flagR=flagL=false;
if(!RightPush.empty()){
flagR=true;
tmpR=RightPush.top();
}
if(!LeftPush.empty()){
flagL=true;
tmpL=LeftPush.top();
}
if(!flagR&&!flagL){
// direct=-1;
continue;
}
else if(!flagR&&flagL){
direct=-1;
ans+=(POS-tmpL.pos);
POS=tmpL.pos;
LeftPush.pop();
}
else if(flagR&&!flagL){
direct=1;
ans+=(tmpR.pos-POS);
POS=tmpR.pos;
RightPush.pop();
}
else{
left=POS-tmpL.pos;
right=tmpR.pos-POS;
if(right<left){
direct=1;
ans+=right;
RightPush.pop();
POS=tmpR.pos;
}
else if(left<right){
ans+=left;
direct=-1;
LeftPush.pop();
POS=tmpL.pos;
}
else {
if(direct>0){
direct=1;
ans+=right;
RightPush.pop();
POS=tmpR.pos;
}
else{
ans+=left;
direct=-1;
LeftPush.pop();
POS=tmpL.pos;
}
}
}
}
}
printf("Case %d: %d\n",++kase,ans);
}
return 0;
}
HDU 4302 Contest 1的更多相关文章
- hdu 4302 Holedox Eating
http://acm.hdu.edu.cn/showproblem.php?pid=4302 #include <cstdio> #include <cstring> #inc ...
- HDU 4302 Holedox Eating(multiset)
http://acm.hdu.edu.cn/showproblem.php?pid=4302 题意: 在一条直线上,会有多条命令,如果是0,那么就会在x位置处出现一个蛋糕,如果是1,某人就会找到最近的 ...
- HDU 5045 Contest(状压DP)
Problem Description In the ACM International Collegiate Programming Contest, each team consist of th ...
- hdu - 5045 - Contest(国家压缩dp)
意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...
- [ACM] hdu 5045 Contest (减少国家Dp)
Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...
- HDU 4302 Holedox Eating (STL + 模拟)
Holedox Eating Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU–5988-Coding Contest(最小费用最大流变形)
Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- hdu 4302 优先队列
进一步学习了优先队列的用法 题意:一只小动物在直线上走,起始位置为零,之后会出现食物,动物要去距离自己最短的食物那,若两边的食物距离相等,则选择之前走的方向的食物 0 x,代表x的位置出现了食物,1代 ...
- hdu 5045 Contest(状态压缩DP)
题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...
随机推荐
- leetCode(32):Power of Two
Given an integer, write a function to determine if it is a power of two. 2的幂的二进制表示中,必定仅仅有一个"1&q ...
- eclipse转Android studio遇到的那些坑
公司项目有导入10多个libray,还有涉及ndk,转Android studio时碰到不少问题.前后大概花费5个工作日,中间各种奇葩bug,各种编译出错,非常多还有没错误提示.一度想过 ...
- Chrome插件开发新手教程
近期在用百词斩这个站点来学单词,感觉非常不错,就是在回想单词列表的时候仅仅有单词和意思.却没有读音.感觉非常不方便,思来思去,想到了Chrome插件能够胜任这个工作.于是小小的研究了一下. Chrom ...
- 《深入理解Android 卷III》第六章 深入理解控件(ViewRoot)系统
<深入理解Android 卷III>即将公布,作者是张大伟.此书填补了深入理解Android Framework卷中的一个主要空白,即Android Framework中和UI相关的部分. ...
- Android图文混排-实现EditText图文混合插入上传
前段时间做了一个Android会议管理系统,项目需求涉及到EditText的图文混排,如图: 在上图的"会议详情"中.须要支持文本和图片的混合插入,下图演示输入的演示样例: 当会议 ...
- 客户端通过wcf来启动或者停止服务器上的windows service
1.设置服务器上的windows service的security,下面的命令只能用cmd.exe来运行(以管理员模式) sc sdset "LISA_43_Dev_Batch" ...
- 2017-3-5 leetcode 442 531 533
今天莫名其妙睡到了中午,很难受... leetcode442 https://leetcode.com/problems/find-all-duplicates-in-an-array/?tab=De ...
- Vmware 安装samba之二
安装samba:sudo apt-get install samba 安装smbclient:sudo apt-get install 安装smbfs:sudo apt-get smbfs 2.修改配 ...
- jetty服务器数据源配置JNDI-Oracle,MySQL,SQLServer,DB2等 (转)
下载jetty 下载jetty服务器(8.1.0.RC2),解压到任意目录下 http://dist.codehaus.org/jetty/jetty-hightide-8.1.0/jetty-hig ...
- SQL Server数据库性能优化
开篇: 最近遇到了很多性能问题,一直没来的及总结,今天正好周末抽时间总结下: 对于稍微大点的公司或者说用户多一些的公司,说白了就是数据量较大的公司,在查询数据时往往会遇到很多瓶颈.这时就需要 ...