Hdu 5063 Operation the Sequence
来源:互联网 发布:数据库应用领域 编辑:程序博客网 时间:2024/05/01 06:03
题目链接
Operation the Sequence
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 359 Accepted Submission(s): 151
Problem Description
You have an array consisting of n integers: a1=1,a2=2,a3=3,…,an=n . Then give you m operators, you should process all the operators in order. Each operator is one of four types:
Type1: O 1 call fun1();
Type2: O 2 call fun2();
Type3: O 3 call fun3();
Type4: Q i query current value of a[i], this operator will have at most 50.
Global Variables: a[1…n],b[1…n];
fun1() {
index=1;
for(i=1; i<=n; i +=2)
b[index++]=a[i];
for(i=2; i<=n; i +=2)
b[index++]=a[i];
for(i=1; i<=n; ++i)
a[i]=b[i];
}
fun2() {
L = 1;R = n;
while(L<R) {
Swap(a[L], a[R]);
++L;--R;
}
}
fun3() {
for(i=1; i<=n; ++i)
a[i]=a[i]*a[i];
}
Type1: O 1 call fun1();
Type2: O 2 call fun2();
Type3: O 3 call fun3();
Type4: Q i query current value of a[i], this operator will have at most 50.
Global Variables: a[1…n],b[1…n];
fun1() {
index=1;
for(i=1; i<=n; i +=2)
b[index++]=a[i];
for(i=2; i<=n; i +=2)
b[index++]=a[i];
for(i=1; i<=n; ++i)
a[i]=b[i];
}
fun2() {
L = 1;R = n;
while(L<R) {
Swap(a[L], a[R]);
++L;--R;
}
}
fun3() {
for(i=1; i<=n; ++i)
a[i]=a[i]*a[i];
}
Input
The first line in the input file is an integer T(1T20) , indicating the number of test cases.
The first line of each test case contains two integern(0<n100000) ,m(0<m100000) .
Then m lines follow, each line represent an operator above.
The first line of each test case contains two integer
Then m lines follow, each line represent an operator above.
Output
For each test case, output the query values, the values may be so large, you just output the values mod 1000000007(1e9+7).
Sample Input
13 5O 1O 2Q 1O 3Q 1
Sample Output
24
题意:略。
题解:对于第1种操作来说:假设操作后的位置为x,那么操作前的位置y为:
如果:x<=(n+1)/2,y=(x-1)*2+1
如果:x>(n+1)/2 , y=( x-(n+1)/2 )*2。
对于第2种操作来说:假设操作后的位置为x,那么操作前的位置y为:
y=n-x+1。
由于询问只有50,我们可以记录下每个操作,每次询问的时候从后往前推,推导出当前询问的位置的数初始的时候在哪个位置,在根据操作三的个数,就可以算出答案了。
代码如下:
#include<stdio.h>#include<algorithm>#include<queue>#include<stack>#include<map>#include<set>#include<vector>#include<iostream>#include<string.h>#include<string>#include<math.h>#include<stdlib.h>#define inff 0x3fffffff#define eps 1e-8#define nn 110000#define mod 1000000007typedef __int64 LL;const LL inf64=LL(inff)*inff;using namespace std;int n,m;int op[nn];LL solve(LL x,int y){ int i; for(i=1;i<=y;i++) { x=(x*x)%mod; } return x;}int main(){ int t; char s[5]; int x,i,j; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int ix=0; int lv=0; for(i=1;i<=m;i++) { scanf("%s %d",s,&x); if(s[0]=='O') { if(x==3) ix++; else op[lv++]=x; } else { for(j=lv-1;j>=0;j--) { if(op[j]==1) { if(x<=(n+1)/2) { x=(x-1)*2+1; } else x=(x-(n+1)/2)*2; } else x=n-x+1; } printf("%I64d\n",solve(x,ix)); } } } return 0;}
0 0
- hdu-5063 Operation the Sequence
- Hdu 5063 Operation the Sequence
- Hdu 5063 Operation the Sequence
- HDU 5063 Operation the Sequence
- hdu 5063 Operation the Sequence
- HDU 5063 Operation the Sequence(暴力)
- hdu 5063 Operation the Sequence(模拟)
- HDU 5063 - Operation the Sequence (置换)
- 【瞎搞】 HDU 5063 Operation the Sequence
- hdu 5063——Operation the Sequence
- Operation the Sequence(HDU 5063)
- HDU 5063Operation the Sequence(暴力)
- hdu 5063 Operation the Sequence(思路)
- HDU - 5036 Operation the Sequence
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
- HDU 5063 Operation the Sequence(暴力 数学)
- hdu 5063 Operation the Sequence (数学公式逆推)
- HDOJ 5063 Operation the Sequence
- cocos2d-x初探学习笔记(30)2.1新特性之CCClippingNode
- controlfile控制文件
- FrameSize、WinSize、VisibleSize、VisibleOrigin概念理解
- Exchange Server 2013 运维系列——恢复已删除或禁用的邮箱
- 关于STM32的IAP很不错的文章
- Hdu 5063 Operation the Sequence
- Objective-第一个OC程序解析
- 基于NVIDIA显卡的硬编解码的一点心得
- 关于ajaxFileUpload只能上传一次的解决
- WindowManager.LayoutParams文档中文参照
- IOS-TextField知多少
- Python之实现简单的注册登录系统
- R语言 一元线性回归
- windows 下配置 rsync