Question.
Give you a sequence and two operations. The first operation is to add the number K to the end of the sequence, and the second operation is to delete the first number.
After several times, this sequence is completely the same, and the number of outputs is returned. Otherwise,-1 is output.
To solve this problem, first determine whether the number after K is equal, and then find out which position of the sequence is equal, and output this bit-1 is the number of operations.
[Cpp]
While (scanf ("% d", & n, & m )! = EOF)
For (int I = 1; I <= n; I ++)
Scanf ("% d", & a [I]);
Bool flag = 0;
For (int I = m; I <= n; I ++)
{
If (a [I]! = A [n])
{
Flag = 1;
Break;
}
}
If (flag)
Cout <-1 <endl;
Else
{
Int I;
For (I = m; I> = 1; I --)
{
If (a [I]! = A [m])
{
Cout <I <endl;
Break;
}
}
If (I <1)
Cout <0 <endl;
}
B. Here is a matrix containing numbers. Now, after some row changes and column changes, you are asked to output the numbers in column y of row x.
[Cpp]
Int hang [2000], lie [2000];
Int Map [2000] [2000];
Int main ()
{
Int n, m, k;
While (scanf ("% d", & n, & m, & k )! = EOF)
{
Char;
Int x, y;
For (int I = 1; I <= n; I ++)
{
Hang [I] = I;
For (int j = 1; j <= m; j ++)
{
Lie [j] = j;
Scanf ("% d", & Map [I] [j]);
}
}
While (k --)
{
Cin>;
Scanf ("% d", & x, & y );
If (a = 'G ')
{
Printf ("% d \ n", Map [hang [x] [lie [y]);
}
Else if (a = 'R ')
{
Int temp = hang [x];
Hang [x] = hang [y];
Hang [y] = temp;
}
Else
{
Int temp = lie [x];
Lie [x] = lie [y];
Lie [y] = temp;
}
}
}
Return 0;
}
C.
D. Give n, m.
Then there are n * two pieces of data, representing the first round of results and the second round of results. M is the lowest score of Vasya.
Output the best and worst rankings.
Obviously, the best place is the first place.
The worst ranking is the number of groups with the most greedy search results greater than m.
[Cpp]
Bool cmp (int a, int B)
{
Return a> B;
}
Int a [100001], B [100001];
Int main ()
{
Int n, m;
While (scanf ("% d", & n, & m )! = EOF)
{Www.2cto.com
For (int I = 0; I <n; I ++)
{
Scanf ("% d", & a [I]);
}
For (int j = 0; j <n; j ++)
{
Scanf ("% d", & B [j]);
}
Sort (a, a + n, cmp );
Sort (B, B + n );
Int ans = 0;
For (int I = 0; I <n; I ++)
{
If (a [ans] + B [I]> = m)
Ans ++;
}
Cout <1 <"" <ans <endl;
}
}
E.