hdu-5063 Operation the Sequence
生活随笔
收集整理的這篇文章主要介紹了
hdu-5063 Operation the Sequence
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題意:給你三種操作,然后詢問當前第i個數(shù)的值
1、先奇后偶
2、對稱交換
3、對每個數(shù)平方
題解:可以對詢問的第i個位置逆推,求平方即可;
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef __int64 LL; const LL MOD = 1000000007; char a[100005][1]; int b[100005]; LL Pow(LL A,LL B){LL res = 1;while(B){if(B&1) res = res * A % MOD;A = A * A % MOD ;B /= 2;}return res; } int main(){int t,n,m;cin >> t;while(t--){cin >> n >> m;int x = (n+1)/2;for(int i = 1;i <= m;i++){scanf("%s %d",a[i],&b[i]);if(a[i][0] == 'Q'){LL p = 1;int pos = b[i];for(int j = i-1;j >= 1;j--){if(a[j][0] == 'O'){if(b[j] == 1){ // cout << " wqew " << endl;if(pos <= x)pos = pos + (pos - 1);elsepos = (pos - x) * 2;}else if(b[j] == 2){ // cout << " wqew " << endl;if(n%2){pos = 2 * x - pos;}else{pos = 2 * x - pos + 1;}}else{p = p * 2 % (MOD - 1);}}} // cout << pos << "====" << p << endl;LL x = pos;x = Pow(x,p);cout << x << endl;}}} }總結
以上是生活随笔為你收集整理的hdu-5063 Operation the Sequence的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微服务架构最强讲解,通俗易懂,写得太好了
- 下一篇: zoj - 3502 Contest