HDU 1496 Train Problem I 火车问题1(桟,水)
题意:
给出两个串,串中的数字i 代表编号为i的火车进入车站的顺序,车站如桟一样,先进后出。第二个串是火车出站的顺序,问若按照第一个串那样进站,是否有可能如第二个串一样的出站顺序?火车顶多9辆,即1~9。
思路:
用桟模拟,每进入一辆火车就加到桟顶,判断第二个串中开头是否是此车,若是,两者都删掉,若不是,继续添加火车进桟,继续判断。直到判断匹配了,将桟顶出桟,串头删除,继续匹配桟顶和串头,直到不匹配了,继续进桟。这样一直反复,直到最后,桟中一定为空,第二个串也一定为空。以此判断是否符合条件。
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int has1[];
int has2[];
int qq[][][][]; int cal()
{
memset(has1,,sizeof(has1));
memset(has2,,sizeof(has2));
int ans=;
for(int x1=; x1<=; x1++)
for(int x2=; x2<=; x2++)
{
int tmp=a*x1*x1+ b*x2*x2;
if( tmp>= )
has1[tmp]++;
else
has2[-tmp]++;
} for(int x3=; x3<=; x3++)
{
for(int x4=; x4<=; x4++)
{
int tmp=c*x3*x3+d*x4*x4;
if(tmp>)
ans+=has2[tmp];
else
ans+=has1[-tmp];
}
}
return (ans<<);
} int main()
{
//freopen("input.txt", "r", stdin);
while(~scanf("%d%d%d%d",&a,&b,&c,&d))
{ if(a> && b> && c> && d> || a< && b< && c< && d<)
{
printf("0\n");
continue;
} if(!qq[a+][b+][c+][d+])
{
qq[a+][b+][c+][d+]=cal()+;
}
printf("%d\n",qq[a+][b+][c+][d+]-);
} return ;
}
AC代码
HDU 1496 Train Problem I 火车问题1(桟,水)的更多相关文章
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- hdu 1023 Train Problem II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022 Train Problem I(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- Hdu 1022 Train Problem I 栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022.Train Problem I【栈的应用】【8月19】
Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy n ...
- HDU 1023 Train Problem II (大数卡特兰数)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022:Train Problem I(数据结构,栈,递归,dfs)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- LA 3713
The Bandulu Space Agency (BSA) has plans for the following three space missions: Mission A: Landing ...
- line-height 与垂直居中!
在此之前,对于line-height 与垂直居中的问题,经常碰到. 比如,图片与span在同一个box中的时候,竟然会各种偏移.要想达到理想的效果真的是各种难. 有时间,决定认真的啃一啃. 一 lin ...
- UVA 11806 Cheerleaders dp+容斥
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- Codeforces Round #336 (Div. 2) B. Hamming Distance Sum 计算答案贡献+前缀和
B. Hamming Distance Sum Genos needs your help. He was asked to solve the following programming pro ...
- mq_setattr
NAME mq_setattr - 设置消息队列的属性(REALTIME) SYNOPSIS #include <mqueue.h> int mq_setattr(mqd_t mqdes, ...
- sip比较好的博客
http://blog.sina.com.cn/s/articlelist_1796220243_1_1.html
- QScrollArea可以帮助我们实现让一个widget的内容带有滚动条(QWidget里内置QScrollArea,QScrollArea里再内置其它QWidget)
使用QScrollArea可以帮助我们实现让一个widget的内容带有滚动条,用户可以通过拖动滚动条来查看更多内容, 代码示例如下: 1.带有滚动条的widget列表 #include "w ...
- CentOS编译安装Python3
前话 最近想学一下一门新的高级语言,无意中看到用python仿AIphaGo的github项目,就决定是他了. AIphaGo的Git传送门: https://github.com/Rochester ...
- 自由软件VS开源软件
自由软件VS开源软件 “自由软件运动”是一项倡导软件这种知识产品应该免费共享的社会运动,它主要是从社会伦理学,道德的高度,强调我们每个人都有自由使用软件的权利.这种权利不应该被软件私有所破坏. 反对软 ...
- SQL语句 递归
--正向递归查询(根据ID查到自己和自己以下的所有数据) connect by prior a.id = a. parentid --反向递归查询(根据叶子ID查出自己和自己以上的根数据) ...