Description
John和Smith在玩一种竞技游戏。在游戏中,John给Smith由n个正整数组成的序列以及m条操作指令,需要Smith按照指令来对n个整数进行操作。其中每条指令都包括二个整数(a, b),意义如下:
如果a大于0,表示将序列中第b个数乘于2;
如果a小于0,表示将序列中第b个数加上2;
如果a等于0,则忽略此条指令。
游戏结束后,Smith需要求出序列中的最大值。现在Smith求助于你,希望你能用计算机编程求出他需要的答案。题目保证计算结果在int的表示范围内。
如果a大于0,表示将序列中第b个数乘于2;
如果a小于0,表示将序列中第b个数加上2;
如果a等于0,则忽略此条指令。
游戏结束后,Smith需要求出序列中的最大值。现在Smith求助于你,希望你能用计算机编程求出他需要的答案。题目保证计算结果在int的表示范围内。
Input
输入数据第一行为一整数T,表示有T组数据。每组输入数据第一行有二个整数n, m, (1 <= n <= 100), (1 <= m <= 100), 第二行有n个整数(1 ~100),表示初始序列,编号从1...n。接着是m行表示m条指令,每行共有2个用空格隔开的整数a b,
(-50<= a <= 50), (1 <= b <= n)。
(-50<= a <= 50), (1 <= b <= n)。
Output
对于每组数据,输出一个整数占一行,表示操作后的序列中的最大整数。
Sample Input
2 2 2 1 2 1 1 -1 2 3 4 1 5 6 1 1 1 1 0 1 -1 1
Sample Output
4 6
waters!
#include<iostream> #include<string.h> #include<stdio.h> #include<ctype.h> #include<algorithm> #include<stack> #include<queue> #include<set> #include<math.h> #include<vector> #include<map> #include<deque> #include<list> using namespace std; int s[999]; void f(int a,int b,int *s) { if(a>0) s[b]*=2; else if(a<0) s[b]+=2; else if(a==0) s[1]+=0; } int main() { int t; int m,n; int a,b; scanf("%d",&t); while(t--) { memset(s,0,sizeof(s)); scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) scanf("%d",&s[i]); for(int i=0; i<m; i++) { scanf("%d%d",&a,&b); f(a,b,s); } sort(s,s+n+1); printf("%d ",s[n]); } return 0; }