qbxt十一系列一

希望
【题目描述】
网页浏览器者有后退与前进按钮,一种实现这两个功能的方式是用两个栈,
“前进栈”、“后退栈”。
这里你需要实现以下几个功能:
BACK: 如果“后退栈”为空则忽略此命令。 否则将当前两面压入“前进栈”,
从“后退栈”中取出栈顶页面,并设置为当前页面。
FORWARD: 如果“前进栈”为空则忽略此命令。否则将当前两面压入“后
退栈”,从“前进栈”中取出栈顶页面,并设置为当前页面。
VISIT: 将当前页面压入“后退栈”、 并将当前页面置为指定页面, 并将“前
进栈”置空。
QUIT: 退出。
假设此浏览器初始页面为 http://www.acm.org/
【输入格式】
输入为一系列命令:BACK, FORWARD, VISIT 和 QUIT,页面网址为不含空
格的字符串
假设任一时刻任意时刻两个栈中的元素都不会超过 100。
最后一个命令为 QUIT。
【输出格式】
输对于除 QUIT 外所有命令,输出当前页面(网址)
如果该命令被忽略则输出“Ignored”。
【样例输入】
VISIT http://acm.ashland.edu/
VISIT http://acm.baylor.edu/acmicpc/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT

【样例输出】
http://acm.ashland.edu/
http://acm.baylor.edu/acmicpc/
http://acm.ashland.edu/
http://www.acm.org/
Ignored
http://acm.ashland.edu/
http://www.ibm.com/
http://acm.ashland.edu/
http://www.acm.org/
http://acm.ashland.edu/
http://www.ibm.com/
Ignored
【样例解释】
无。
【数据范围与规定】
对于100%的数据,操作数量不超过1000,每行字符串长度不超过500。

【题目分析】

    一道简单的模拟,只要按照题目中的要求来操作就可以

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
stack <int> ht;
stack <int> qj;
int cnt,bh;
char s[1005][505]={'h','t','t','p',':','/','/','w','w','w','.','a','c','m','.','o','r','g','/'};
int main ()
{
    //freopen ("kami.in","r",stdin);
    //freopen ("kami.out","w",stdout);
    while (scanf ("%s",s[++cnt]))
    {
        if (s[cnt][0]=='Q') return 0;
        if (s[cnt][0]=='V')
        {
            ht.push(bh);
            scanf ("%s",s[++cnt]);
            bh=cnt;// 当前页面的编号 
            printf ("%s
",s[cnt]);
            while (!qj.empty())//如果前进栈不为空,删除栈顶元素直到栈空 
                qj.pop();
        }
        if (s[cnt][0]=='B')
        {
            if (!ht.empty())
            {
                printf ("%s
",s[ht.top()]);
                qj.push(bh);
                bh=ht.top();
                ht.pop();
            }
            else printf ("Ignored
");
        }
        if (s[cnt][0]=='F')
        {
            if (!qj.empty())
            {
                printf ("%s
",s[qj.top()]);
                ht.push(bh);
                bh=qj.top();
                qj.pop();
            }
            else printf ("Ignored
");
        }
    }
    return 0;
}


【问题描述】
令?(?)为斐波那契数列第?项,其中f(0) = f(1) = 1,f(x) = f(x −1) +
f(x −2)。
所以要干啥呢?
求f(f(n))。
【输入格式】
第一行一个整数T代表数据组数。
接下来T行每行一个整数n。
【输出格式】
T行每行一个整数代表答案对10e9 + 7取模的值。
【样例输入】
4
0
1
2
6
【样例输出】
0
1
1
21
【样例解释】
无。
【数据规模与约定】
215 490。
70%的数据,1 ≤ n ≤ 10 5 。
对于100%的数据,1 ≤ ? ≤ 10 3 ,1 ≤ ? ≤ 10 100 。

#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int N=1e3+10;
const int mod=1e9+7;
struct node{
    int a[2][2];
}ss;
node mul(node a,node b,int md){
    node c;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            c.a[i][j]=0;
            for(int k=0;k<2;k++){
                c.a[i][j]=(c.a[i][j]+(ll)a.a[i][k]*b.a[k][j])%md;
            }
        }
    }
    return c;
}
char s[N];
int main(){
    freopen("na.in","r",stdin);
    freopen("na.out","w",stdout);
    ss.a[0][0]=ss.a[1][0]=ss.a[0][1]=1;ss.a[1][1]=0;
    int T;scanf("%d",&T);
    while(T--){
        node ans;
        ans.a[0][0]=ans.a[0][1]=1;ans.a[1][0]=ans.a[1][1]=0;
        scanf("%s",s+1);
        int len=strlen(s+1);
        int num=0;
        for(int i=1;i<=len;i++) num=(num*10+s[i]-'0')%329616;
        if(num==0){puts("0");continue;}
        if(num==1||num==2){puts("1");continue;}
        node tmp=ss;int p=num-2;
        for(;p;p>>=1,tmp=mul(tmp,tmp,2000000016)) if(p&1) ans=mul(ans,tmp,2000000016);
        p=ans.a[0][0]-2;
        ans.a[0][0]=ans.a[0][1]=1;ans.a[1][0]=ans.a[1][1]=0;
        for(tmp=ss;p;p>>=1,tmp=mul(tmp,tmp,mod)) if(p&1) ans=mul(ans,tmp,mod);
        printf("%d
",ans.a[0][0]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/xiaoningmeng/p/5929311.html