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 ...
随机推荐
- HDU4010 Query on The Trees(LCT)
人生的第一道动态树,为了弄懂它的大致原理,需要具备一些前置技能,如Splay树,树链剖分的一些概念.在这里写下一些看各种论文时候的心得,下面的代码是拷贝的CLJ的模板,别人写的模板比较可靠也方便自己学 ...
- HDU 1715 大菲波数(JAVA, 简单题,大数)
题目 //BigInteger 和 BigDecimal 是在java.math包中已有的类,前者表示整数,后者表示浮点数 import java.io.*; import java.util.*; ...
- Jquery---用jQuery实现的智能隐藏、滑动效果的返回顶部代码
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.min.js"></script& ...
- java 继承类与接口问题
java 先extends 继承类,再implements 继承接口 public class DataBase extends ClassBase implements Ijiekou { }// ...
- WCF分布式开发步步为赢(7):WCF数据契约与序列化
本节继续学习WCF分布式开发步步为赢(7):WCF数据契约与序列化.数据契约是WCF应用程序开发中一个重要的概念,毫无疑问实现客户端与服务端数据契约的传递中序列化是非常重要的步骤.那么序列化是什么?为 ...
- 错误处理--pure specifier can only be specified for functions
错误处理--pure specifier can only be specified for functions 今天下载了log4cpp的源代码,在VC6下编译时出现错误: ..\..\includ ...
- Linux网络编程10——使用UDP实现五子棋对战
思路 1. 通信 为了同步双方的棋盘,每当一方在棋盘上落子之后,都需要发送给对方一个msg消息,让对方知道落子位置.msg结构体如下: /* 用于发给对方的信息 */ typedef struct t ...
- UVA 10574 - Counting Rectangles 计数
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...
- 深入理解javascript:揭秘命名函数表达式
这是一篇转自汤姆大叔的文章:http://www.cnblogs.com/TomXu/archive/2011/12/15/2288411.html 前言 网上还没用发现有人对命名函数表达式进去重复深 ...
- Struts2 Convention插件的使用(4)使用@Action注解返回json数据
package com.hyy.action; import java.util.HashMap; import java.util.Map; import org.apache.struts2.co ...