HDU 4908 -- BestCoder Sequence, hdu4908
BestCoder Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 169 Accepted Submission (s): 82
Problem DescriptionMr Potato is a coder.
Mr Potato is the BestCoder.
One night, an amazing sequence appeared in his dream. Length of this sequence is odd, the median number is M, and he named this sequence
Bestcoder Sequence.
As the best coder, Mr potato has strong curiosity, he wonder the number of consecutive sub-sequences which are
Bestcoder sequencesIn a given permutation of 1 ~ N.
InputInput contains multiple test cases.
For each test case, there is a pair of integers N and M in the first line, and an permutation of 1 ~ N in the second line.
[Technical Specification]
1. 1 <= N <= 40000
2. 1 <= M <= N
OutputFor each case, you shocould output the number of consecutive sub-sequences which are
Bestcoder Sequences.
Sample Input
1 115 34 5 3 2 1
Sample Output
13HintFor the second case, {3},{5,3,2},{4,5,3,2,1} are Bestcoder Sequence.
--------------------------------------------
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # define M 100001 # define base 40000 using namespace std; int a [M], dp [M]; int main () {int n, m, x; while (scanf ("% d", & n, & m )! = EOF) {for (int I = 0; I <n; ++ I) {scanf ("% d", & a [I]); if (a [I] = m) x = I;} memset (dp, 0, sizeof dp); int ans = 0; for (int I = x + 1; I <n; ++ I) {if (a [I]> m) ans ++; // a large addition and a small subtraction else ans --; dp [ans + base] ++; // record the number of times this status occurs} ans = ++ dp [base]; // when the status is base, the median int tmp = 0; for (int I = X-1; I> = 0; -- I) {if (a [I]> m) tmp ++; else tmp --; ans + = dp [-tmp + base]; // number of States added to the base} cout <ans <endl;} return 0 ;}
1242
Hangdian ACM1005 Number Sequence
This question is related to IQ and is a mathematical question.
Cycle: 49 I was told by someone else
# Include <stdio. h>
Int main ()
{
Int f [1000] = {0}, n, I, a, B;
While (scanf ("% d", & a, & B, & n )! = EOF)
{
F [0] = 1;
F [1] = 1;
If (a = 0 & B = 0 & n = 0)
Break;
For (I = 2; I <(n % 49); I ++)
{
F [I] = (a * f [I-1] + B * f [I-2]) % 7;
}
Printf ("% d \ n", f [n % 49-1]);
}
Return 0;
}
Max Sum http: // acmhdueducn/showproblemphp? Pid = 1003 Problem Description Given a sequence a [1],
Go to machine debugging.