题意:

  给出两个串,串中的数字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(桟,水)的更多相关文章

  1. HDU 1022 Train Problem I

    A - Train Problem I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  2. hdu 1023 Train Problem II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...

  3. HDU - 1022 Train Problem I STL 压栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDU 1022 Train Problem I(栈的操作规则)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...

  5. Hdu 1022 Train Problem I 栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. 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 ...

  7. HDU 1023 Train Problem II (大数卡特兰数)

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. hdu 1022 Train Problem I(栈的应用+STL)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 1022:Train Problem I(数据结构,栈,递归,dfs)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. Android 中建立一个OpenGL ES的开发环境

    转自: http://wiki.eoe.cn/page/Building_an_OpenGL_ES_Environment.html 负责人:zhangql原文链接:http://docs.eoean ...

  2. node.js的npm详解

    一.什么是npm呢 npm(Node Package Manager,node包管理器)是node的包管理器,他允许开发人员在node.js应用程序中创建,共享并重用模块.模块就是可以在不同的项目中重 ...

  3. MyEclipse — Maven+Spring+Struts+Hibernate 整合 [学习笔记-1]

    示例数据库test,用户信息表

  4. 应用内存优化之OnLowMemory&OnTrimMemory

    1.应用内存onLowMemory& onTrimMemory优化 onLowMemory& onTrimMemory简介:OnLowMemory是Android提供的API,在系统内 ...

  5. iOS 开发--NSMutableArray使用枚举方法

    可变数组也可以使用枚举方法, 我们在这里提供了两种枚举方法, 一个是正序枚举, 一个是倒序枚举, 在正序枚举中, 元素的个数和顺序都是不可以修改的, 但是在倒序枚举中却可以修改, 这有些耐人寻味. 涉 ...

  6. SRM 620 DIV1 L2

    题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...

  7. Pipeline aborted due to error

    报错内容 x. Pipeline aborted due to error {:exception=>"LogStash::ConfigurationError", ... ...

  8. js网页滚动条滚动事件实例分析

    本文实例讲述了js网页滚动条滚动事件用法.分享给大家供大家参考.具体分析如下: 在做js返回顶部的效果时,要监听网页滚动条滚动事件,这个事件就是:window.onscroll.当onscroll事件 ...

  9. chrome开发配置(二)获取源代码

    1.下载源代码,这里使用最简单的下载,chrome打包好的共享在百度云盘,点击下载 2.建议下载7z压缩工具解压压缩包,大概1个多小时. 3.至于以后怎么更新到最新版不能,等编译生成成功了,我们再具体 ...

  10. 机器学习 —— 概率图模型(Homework: Structure Learning)

    概率图的学习真的要接近尾声了啊,了解的越多越发感受到它的强大.这周的作业本质上是data mining.从数据中学习PGM的结构和参数,完全使用数据驱动 —— No structure, No par ...