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轴上,再把 ...
随机推荐
- laravel5.5授权系统
目录 1. Gates 1.1 一个简单的使用Gates的例子 1.2 编写Gates 1.3 授权动作 2. policy策略 2.1 还是先看个例子 2.2 编写策略 2.3 授权策略 2.3.1 ...
- Android学习记录(10)—Android之图片颜色处理
你想做到跟美图秀秀一样可以处理自己的照片,美化自己的照片吗?其实你也可以自己做一个这样的软件,废话不多说了,直接上图,上代码了! 效果图如下: 没处理前: 处理之后: MainActivity.jav ...
- 架构师速成6.7-设计开发思路-uml 分类: 架构师速成 2015-07-29 18:25 157人阅读 评论(0) 收藏
uml是什么东西?统一建模语言,一门语言,是用来进行软件设计的一门语言. 其实一门语言的诞生并不伟大,让大多数人都使用才足够伟大.uml就是一门伟大的语言,因为目前软件设计的唯一语言就是它. UML其 ...
- PhpStorm 格式化中花括号缩进方式
格式化前: function func() { return ; } 格式化后: function func() { return ; } 在PhpStorm中的配置:File -> Setti ...
- win 7 查看端口被占用
开始---->运行---->cmd,或者是window+R组合键,调出命令窗口 输入命令:netstat -ano,列出所有端口的情况.在列表中我们观察被占用的端口,比如是4915 ...
- (转\整)UE4游戏优化 多人大地型游戏的优化(四)内存的优化
施主分享随缘,评论随心,@author:白袍小道,当苦无妨 小道暗语: 1.因为小道这里博客目录没自己整,暂时就用随笔目录结构,所以二级目录那啥就忽略了.标题格式大致都是(原or转) 二级目录 (标题 ...
- [python] 网络数据采集 操作清单 BeautifulSoup、Selenium、Tesseract、CSV等
Python网络数据采集操作清单 BeautifulSoup.Selenium.Tesseract.CSV等 Python网络数据采集操作清单 BeautifulSoup.Selenium.Tesse ...
- 深入理解css之absolute
在慕课网上看到的张鑫旭大神的视频,做的笔记,以便日后翻看. 绝对定位与float 1.绝对定位和float有一样的特性,都有包裹性,和破坏性. 2.absolute和relative 如果不把他们俩放 ...
- 在Struts2 Action中快速简便的访问Request、Session等变量
前言——正常情况下如何在Action中获取到这些变量 全部方法(共四种)可以参考:http://blog.csdn.net/itmyhome1990/article/details/7019476 这 ...
- canvas 基础
1.<canvas>元素 <canvas id="tutorial" width="150" height="150"&g ...