hdu 5063(思路题-反向操作数组)
Operation the Sequence
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 842 Accepted Submission(s): 288
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];
}
The first line of each test case contains two integer n(0<n≤100000), m(0<m≤100000).
Then m lines follow, each line represent an operator above.
3 5
O 1
O 2
Q 1
O 3
Q 1
4
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL; int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n,q;
scanf("%d%d",&n,&q);
char s[];
int opr;
stack<int> stk;
stack<int> stk1;
int num = ;
while(q--)
{
scanf("%s%d",s,&opr);
if(s[]=='O')
{
if(opr==||opr==) stk.push(opr);
else num++;
}
else
{
LL ans;
while(!stk.empty())
{
int now = stk.top();
stk.pop();
stk1.push(now);
if(now==) opr = n-opr+;
if(now==)
{
if(n%==)
{
if(opr<=n/+) ///原来是奇数位
{
opr = *opr - ;
}
else
{
opr = (opr - (n/+))*;
}
}
else
{
if(opr<=n/)
{
opr = *opr - ;
}
else
{
opr = *(opr - n/);
}
}
}
}
while(!stk1.empty()){
stk.push(stk1.top());
stk1.pop();
}
ans = opr;
for(int i=; i<num; i++)
{
ans = ans*ans%;
}
printf("%lld\n",ans);
}
}
}
return ;
}
hdu 5063(思路题-反向操作数组)的更多相关文章
- hdu 4908(思路题)
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4857(好题,反向拓扑排序)
逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- Proud Merchants HDU - 3466 (思路题--有排序的01背包)
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- hdu 5101(思路题)
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 4859(思路题)
Goffi and Squary Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu 5191(思路题)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 4956(思路题)
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 5400(思路题)
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 1173 思路题
题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把 ...
随机推荐
- Error:Java home supplied via 'org.gradle.java.home' is invalid
Finally i found my solution. In the project root i found gradle.properties configure this java home ...
- PowerCmd
今天在手机上看慕课网,看到一个好玩的东西.Powercmd. 一开始的感觉是,妈的,我会cmd命令,为什么要用你的cmd? 后来,用了之后,感觉,嗯,还是Powercmd好用.功能强大. 我们来看看它 ...
- 批量修改Linux文件夹下所有文件大小写
小写转大写: [zengs@SYS SOS]$ for cpplive in *; do mv $cpplive `echo $cpplive|tr [a-z] [A-Z]`; done 大写转小写: ...
- python - web自动化测试 - 元素操作 - 定位
# -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: find_ele.py @ide: PyCharm Community ...
- 使用python 3导入MySQLdb 报No module named 'MySQLdb'异常错误
MySQLdb只支持Python2.*,还不支持3.* 可以用PyMySQL代替安装PyMySQL后,在使用模块时使用import pymysql as MySQLdb 后续使用方式与MySQLdb ...
- scheduled定时任务cron表达式知识地址
https://www.cnblogs.com/javahr/p/8318728.html https://www.cnblogs.com/sunjie9606/archive/2012/03/15/ ...
- scrapy爬取图片并自定义图片名字
1 前言 Scrapy使用ImagesPipeline类中函数get_media_requests下载到图片后,默认的图片命名为图片下载链接的哈希值,例如:它的下载链接是http://img.iv ...
- Android记事本09
昨天: Activity的数据传递. 今天: 从Activity中返回数据 请求码和返回码的作用 遇到的问题: 无.
- SqlServer中截取小数位数
方法一:convert(float,字段名) as 别名 select convert(float,round(10.123232,2)) 结果:10.12 select convert(float, ...
- PHP文件操作函数及文件指针理解
知识点: 一.fopen(),文件打开函数,读写参数有: 1.R : 只读,指针在文件开头 2.r+:读写,指针同上 3.W :只写,写入前会删除文件内容,然后指针回到文件开头,文件不存在则创建 4 ...