Piggy-Bank
Problem Description
Before ACM can do anything, a budget must be prepared and the 阅读全文 »
Problem Description
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. 阅读全文 »
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China! 阅读全文 »
Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
Output
In this problem, you have to output the translation of the history book.
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
Sample Output
hello, i'm from mars.
i like earth!
Hint Huge input, scanf is recommended.
Author
Ignatius.L
题目类型:trie树
算法分析:将外文单词插入到Trie树中,每个终止节点额外存储一个对应的英文单词,然后在文本中找到一个字符串ss,然后判断其是否在Trie树中,不在就直接输出ss,否则就输出这个终止节点所对应的英文单词
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
#include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> #define lson rt << 1, l, m #define rson rt << 1 | 1, m + 1, r using namespace std; const int INF = 0x7FFFFFFF; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int MOD = 1e9 + 7; const int maxn = 26; struct Trie { Trie *next[maxn]; char ss[maxn]; Trie () { memset (next, 0, sizeof (next)); memset (ss, 0, sizeof (ss)); } }; Trie *root; void Init () { root = new Trie (); } void Insert (char *s, char *bb) { if (!s[0]) return ; Trie *p = root; for (int i = 0; s[i]; i++) { if (!p -> next[s[i]-'a']) { p -> next[s[i]-'a'] = new Trie; } p = p -> next[s[i]-'a']; } strcpy (p -> ss, bb); } char res[maxn+66]; bool Query (char *s) { if (!s[0]) return false; Trie *p = root; for (int i = 0; s[i]; i++) { if (!p -> next[s[i]-'a']) return false; p = p -> next[s[i]-'a']; } if (p -> ss[0]) { strcpy (res, p -> ss); return true; } return false; } void DelTrie (Trie *t) { if (!t) return ; for (int i = 0; i < maxn; i++) { if (t -> next[i]) DelTrie (t -> next[i]); } delete t; } int main() { // freopen ("aaa.txt", "r", stdin); char aa[maxn+3000], bb[maxn+3000]; scanf ("%s", aa); Init (); while (scanf ("%s", aa) != EOF) { if (!strcmp (aa, "END")) break; scanf ("%s", bb); Insert (bb, aa); } scanf ("%s", aa); gets (aa); while (gets (aa)) { if (!strcmp (aa, "END")) break; char temp[maxn]; int len; for (int i = 0; aa[i]; ) { if (aa[i] >= 'a' && aa[i] <= 'z') { len = 0; while (aa[i] >= 'a' && aa[i] <= 'z') { temp[len++] = aa[i]; i++; } temp[len] = 0; if (Query (temp)) printf ("%s", res); else printf ("%s", temp); } else { printf ("%c", aa[i]); i++; } } puts (""); } return 0; } |
Problem Description
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
Input
The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.
Output
For each test case, you have to output a line contains an integer P which indicate the different equations you have found.
Sample Input
4
10
20
Sample Output
5
42
627
Author
Ignatius.L
题目类型:整数的拆分
算法分析:直接使用普通母函数将其转换成求解多项式乘法的问题,然后直接输出coeff[n]的值即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
#include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> #define lson rt << 1, l, m #define rson rt << 1 | 1, m + 1, r using namespace std; const int INF = 0x7FFFFFFF; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int MOD = 10000 + 7; const int maxn = 100 + 66; int coeff[maxn], temp[maxn]; void Init () { memset (coeff, 0, sizeof (coeff)); memset (temp, 0, sizeof (temp)); } void GenerFunction (long long expnum) { for (long long i = 0; i <= expnum * 1; i += 1) coeff[i] = 1; for (long long i = 2; i <= expnum; i++) { for (long long j = 0; j <= expnum; j++) { for (long long k = 0; k + j <= expnum; k += i) temp[k+j] += coeff[j]; } for (long long j = 0; j <= expnum; j++) { coeff[j] = temp[j]; temp[j] = 0; } } } int main() { // ifstream cin ("aaa.txt"); long long n; while (cin >> n) { Init (); GenerFunction (n); cout << coeff[n] << endl; } return 0; } |
Problem Description
JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. 阅读全文 »
Problem Description
As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway. 阅读全文 »
Problem Description
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
Input
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.
Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
Sample Input
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
13.3333
1.500
Author
CHEN, Yue
Source
题目类型:贪心
算法分析:直接算出每一种物品的价值/花费,然后按其从大到小排序。最后对于给定的背包的容量,尽量将单位价值高的物品放入。注意本题的坑点是精度!!!!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
#include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> #define lson rt << 1, l, m #define rson rt << 1 | 1, m + 1, r using namespace std; const int INF = 0x7FFFFFFF; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int MOD = 7; const int maxn = 66600 + 66; struct Node { double v, w; double avr; }; Node ans[maxn]; bool Cmp (Node a, Node b) { return a.avr > b.avr; } int main() { // ifstream cin ("aaa.txt"); int n, m; while (cin >> m >> n) { if (m == -1 && n == -1) break; int i; for (i = 0; i < n; i++) { cin >> ans[i].v >> ans[i].w; ans[i].avr = ans[i].v * 10.0 / ans[i].w / 10; } sort (ans, ans + n, Cmp); double sum = 0; i = 0; while (i < n && m - ans[i].w >= 1e-5) { sum += ans[i].v; m -= ans[i].w; i++; } if (i < n) sum += ans[i].avr * m; printf ("%.3lf\n", sum); } return 0; } |
Problem Description
A number sequence is defined as follows:
f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
Given A, B, and n, you are to calculate the value of f(n). 阅读全文 »
Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0
Sample Output
red
pink
Author
WU, Jiazhi
Source
题目类型:map/Trie树
算法分析:直接建立一个映射字符串的数据结构,然后统计次数即可,这里分别使用STL中的map和Trie树
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; const int INF = 0x7FFFFFFF; const int MOD = 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 60000 + 66; int main() { // ifstream cin ("aaa.txt"); // freopen ("aaa.txt", "r", stdin); int n; while (cin >> n) { if (n == 0) break; map <string, int> cnt; string s; int maxval = -INF; string res; for (int i = 1; i<= n; i++) { cin >> s; cnt[s]++; if (maxval < cnt[s]) { maxval = cnt[s]; res = s; } } cout << res << endl; } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
#include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; const int INF = 0x7FFFFFFF; const int MOD = 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 26; const int nodemaxn = 15000; int maxval; struct Trie { int next[nodemaxn][maxn], last[nodemaxn], cnt[nodemaxn]; int root , len; void Init () { len = 0; root = newnode (); } int newnode () { for (int i = 0; i < maxn; i++) next[len][i] = -1; last[len] = 0, cnt[len] = 0; len++; return len - 1; } void Insert (char *s) { int p = root; for(int i = 0; s[i]; i++) { if(next[p][s[i]-'a'] == -1) next[p][s[i]-'a'] = newnode (); else { p = next[p][s[i]-'a']; } } last[p] = 1; cnt[p]++; } int Query (char *s) { if (!s[0]) return 0; int p = root; for (int i = 0; s[i]; i++) { if (next[p][s[i]-'a'] == -1) return 0; p = next[p][s[i]-'a']; } if (last[p]) return cnt[p]; } }; Trie aa; char ss[1111][maxn]; int main() { // ifstream cin ("aaa.txt"); // freopen ("aaa.txt", "r", stdin); int n; while (cin >> n) { if (n == 0) break; aa.Init (); for (int i = 1; i <= n; i++) { cin >> ss[i]; aa.Insert (ss[i]); } maxval = -INF; char sss[maxn]; for (int i = 1; i <= n; i++) { if (maxval < aa.Query(ss[i])) { maxval = aa.Query (ss[i]); strcpy(sss, ss[i]); } } cout << sss << endl; } return 0; } |
Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), 阅读全文 »
You are given two distinct points A and B in the two-dimensional plane. Your task is to find any point C with the following properties:
C is different from A and B. 阅读全文 »
Problem Description
Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and there will not be more than one pipe between two ponds. Each pond has a value v. Now Betty wants to remove some ponds because she does not have enough money. But each time when she removes a pond, she can only remove the ponds which are connected with less than two ponds, or the pond will explode. Note that Betty should keep removing ponds until no more ponds can be removed. After that, please help her calculate the sum of the value for each connected component consisting of a odd number of ponds
Input
The first line of input will contain a number T(1≤T≤30) which is the number of test cases. For each test case, the first line contains two number separated by a blank. One is the number p(1≤p≤104) which represents the number of ponds she owns, and the other is the number m(1≤m≤105) which represents the number of pipes. The next line contains p numbers v1,...,vp, where vi(1≤vi≤108) indicating the value of pond i. Each of the last m lines contain two numbers a and b, which indicates that pond a and pond b are connected by a pipe.
Output
For each test case, output the sum of the value of all connected components consisting of odd number of ponds after removing all the ponds connected with less than two pipes.
Sample Input
1
7 7
1 2 3 4 5 6 7
1 4
1 5
4 5
2 3
2 6
3 6
2 7
Sample Output
21
Source
2015 ACM/ICPC Asia Regional Changchun Online
题目类型:拓扑排序删点+DFS
算法分析:先使用链式前向星建图,然后使用拓扑排序的方法将所有不符合的点删去(标记),易知此时的连通分量都是环,然后使用DFS将所有的分量中点的数量是奇数的val和累加起来即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
#pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("aaa.txt", "r", stdin) #define CPPFF ifstream cin ("aaa.txt") #define LL long long #define ULL unsigned long long #define DB(ccc) cout << #ccc << " = " << ccc << endl const int INF = 0x7FFFFFFF; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e4 + 66; //分别表示顶点v。w和下一个邻接的位置 struct Node { LL v, w, next; }; Node edge[maxn*10]; LL head[maxn], edgelen;//分别表示顶点的表头节点和边的数量 //将所有的数组均初始化为-1 void Init () { memset (head, -1, sizeof (head)); memset (edge, -1, sizeof (edge)); edgelen = 0; } //使用头插法构建 void AddEdge (LL u, LL v, LL w) { edge[edgelen].v = v; edge[edgelen].w = w; edge[edgelen].next = head[u]; head[u] = edgelen++; } LL val[maxn], deg[maxn], res, temp, cnt; bool vvis[maxn]; void dfs (LL cur) { for (LL i = head[cur]; i != -1; i = edge[i].next) { if (!vvis[edge[i].v] && deg[edge[i].v] >= 2) { temp += val[edge[i].v]; cnt++; vvis[edge[i].v] = true; dfs (edge[i].v); } } } int main() { // CPPFF; LL t; cin >> t; while (t--) { Init (); memset (deg, 0, sizeof (deg)); LL n, m; cin >> n >> m; for (LL i = 1; i <= n; i++) cin>> val[i]; for (LL i = 1; i <= m; i++) { LL u, v; cin >> u >> v; AddEdge (u, v, 1); AddEdge (v, u, 1); deg[u]++; deg[v]++; } queue <LL>qu; for (LL i = 1; i <= n; i++) if (deg[i] < 2) qu.push (i); while (!qu.empty ()) { LL tt = qu.front (); qu.pop (); for (LL i = head[tt]; i != -1; i = edge[i].next) { if (deg[edge[i].v] >= 2) { deg[edge[i].v]--; if (deg[edge[i].v] < 2) qu.push (edge[i].v); } } } res = 0; memset (vvis, false, sizeof (vvis)); for (LL i = 1; i <= n; i++) { if (deg[i] >= 2 && !vvis[i]) { temp = cnt = 0; dfs (i); if (cnt & 1) res += temp; } } cout << res << endl; } return 0; } |
Problem Description
In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,anrepresenting the size of the water source. Given a set of queries each containing 2 integers l and r, please find out the biggest water source between al and ar.
Input
First you are given an integer T(T≤10) indicating the number of test cases. For each test case, there is a number n(0≤n≤1000) on a line representing the number of water sources. n integers follow, respectively a1,a2,a3,...,an, and each integer is in {1,...,106}. On the next line, there is a number q(0≤q≤1000)representing the number of queries. After that, there will be q lines with two integers l and r(1≤l≤r≤n) indicating the range of which you should find out the biggest water source.
Output
For each query, output an integer representing the size of the biggest water source.
Sample Input
3
1
100
1
1 1
5
1 2 3 4 5
5
1 2
1 3
2 4
3 4
3 5
3
1 999999 1
4
1 1
1 2
2 3
3 3
Sample Output
100
2
3
4
4
5
1
999999
999999
1
Source
2015 ACM/ICPC Asia Regional Changchun Online
题目类型:水题
算法分析:数据比较小,所以可以直接暴力枚举
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("aaa.txt", "r", stdin) #define CPPFF ifstream cin ("aaa.txt") #define LL long long #define ULL unsigned long long #define DB(ccc) cout << #ccc << " = " << ccc << endl const int INF = 0x7FFFFFFF; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e3 + 66; int a[maxn]; int main() { // CPPFF; int t; cin >>t; while (t--) { int n; cin >>n; for (int i = 1; i <= n; i++) cin >> a[i]; int q; cin >>q; for (int i = 1; i <= q; i++) { int u, v; cin >>u >>v; int maxval = -INF; for (int j = u; j <= v; j++) maxval = max (maxval, a[j]); cout << maxval << endl; } } return 0; } |