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 ...
随机推荐
- Light OJ 1364 Expected Cards (期望dp,好题)
题目自己看吧,不想赘述. 参考链接:http://www.cnblogs.com/jianglangcaijin/archive/2013/01/02/2842389.html #include &l ...
- 【OpenCV入门教程之二】 一览众山小:OpenCV 2.4.8组件结构全解析
转自: http://blog.csdn.net/poem_qianmo/article/details/19925819 本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:ht ...
- 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 ...
- hdu 1669(二分+多重匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 思路:由于要求minimize the size of the largest group,由此 ...
- 关于null == 0?返回false的问题
1.首先我们先看各种情况的结果: null > 0? //=>false null < 0? //=>false null >= 0? //=>true null ...
- oracle 密码忘记 找回密码
生活中,容易忘记Oracle数据库system用户的密码,怎么办呢,小生带你一步步重新登上Oracle ,及时你密码忘记了. 1.打开cmd窗口,输入 sqlplus / as sysdba 2.运行 ...
- 【pku2115-C Looooops】拓展欧几里得-不定方程
http://poj.org/problem?id=2115 题解:一个变量从A开始加到B,每次加C并mod2^k,问加多少次.转化为不定方程:C*x+2^K*Y=B-A //poj2115 #inc ...
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-004JPA例子的代码
一.结构 二.Repository层 1. package spittr.db; import java.util.List; import spittr.domain.Spitter; /** * ...
- SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-001-Spring对原始JDBC的封装
1.spring扩展的jdbc异常 2.Template的运行机制 Spring separates the fixed and variable parts of the data-access p ...
- QTableView带可编辑进度条
main文件与上一个例子完全一致,也使用QStandardItemModel,关键是有这句:QStandardItem.setEditable(false); 继承QAbstractItemDele ...