今晚的两道 bc

第一道题    Beautiful Palindrome Number 

,简单组合计数问题,手算打表就好~大概十五分钟左右搞定【第一次 提交竟然 wa了一次 有一个小小的坑在那。。。。

 /*********************************
 Author: jusonalien
 Email : jusonalien@qq.com
 school: South China Normal University
 Origin:
 *********************************/
 #include <iostream>
 #include <cstdio>
 #include <map>
 #include <cstring>
 #include <string>
 #include <set>
 #include <queue>
 #include <vector>
 using namespace std;
 int ans[7] = {1,9,18,54,90,174,258};
 int T;
 int main(){
     cin>>T;
     int k;
     while(T--){
         cin>>k;
         printf("%d
",ans[k]);
     }
     return 0;
 }

第二道题,Operation the Sequence

一开始想到的就是 线段树啥的,尼玛一个人在那想啊想啊,想到蛋碎 都没想到究竟要怎么操作,突然间想到能不能到时反过来 递推过去?这么一想会不会很傻X?会不会T啊?尼玛 连具体方法都没想好,就担心T了,,简直太低能了,后来lpt好像也在做这个比赛,她在Q上吐槽道说她刚去图书馆水过第一题后图书馆就闭馆了,然后我和她讨论了一下第二题,聊着聊着就聊到了递推,然后就她说有个词叫做离线。。。哎原来这就是离线?然后 我就开始写 ,为了能够保证到时能够倒着推过去,就用stack咯,,结果还没写完就out of submit time了,没办法交了,,,rating就这么跑了囧rz

晚上出去散了一下步之后,回来接着写那道题目,第一次t了一次,,原来我天真地用了快速幂,其实不用快速幂更快,然后答案没有设为long long 又wa 了一发,然后 乱搞了几次后就ac了

/*********************************
Author: jusonalien
Email : jusonalien@qq.com
school: South China Normal University
Origin:
*********************************/
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
const int MOD = 1e9 + 7;
int n,m,pow;
stack<int> op;
inline int fun_1(int o){
    if(n&1){
        if(o <= (n+1)/2)
            return o*2 - 1;
        else
            return (o - (n+1)/2)*2;
    }else{
       if(o <= n/2)
            return o*2 - 1;
        else
            return (o - n/2) * 2;
    }
}
inline int fun_2(int o){
    return n - o + 1;
}
inline int solve(int o,int q){
    if(o == 1)
        return fun_1(q);
    else
        return fun_2(q);
}
int query(int o){
    stack<int> q = op;
    while(!q.empty()){
        o = solve(q.top(),o);
        q.pop();
    }
    long long ans = o;
    for(int i = 1;i <= pow;++i)
        ans = (ans*ans)%MOD;
    return ans;
}
int T;
int main(){
    n = 5;
    char ope[3];
    int ope_;
    cin>>T;
    while(T--){
        pow = 0;
        while(!op.empty()) op.pop();
        scanf("%d%d",&n,&m);
    for(int i = 1;i <= m;++i){
            scanf("%s %d",ope,&ope_);
            if(ope[0] == 'O'&&ope_ != 3)
                    op.push(ope_);
            else if(ope[0] == 'O'&&ope_ == 3 )
                    pow++;
            else if(ope[0] == 'Q')
                 cout<<query(ope_)<<endl;
        }
    }
    return 0;
}
额 继续努力吧 骚年~~~
原文地址:https://www.cnblogs.com/jusonalien/p/4019955.html