Front exam week, I'm sorry it took so long.
A题 Alex and a Rhombus
The basic idea
Recursive solution, n when 1 =, Count (1) = 1; n> when 1, Count (n) = Count (n-1) + (n-1) * 4
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
long long res=1;
for(int i=1;i<=n;i++)
{
res+=4*(i-1);
}
cout<<res;
return 0;
}
B题 Nick and Array
The basic idea
In absolute terms, negative> positive, so long as the number of revolutions of all negative, if n is divisible by 2, the result is positive, if more than n% 2 1, will be converted into the smallest negative positive.
Note that the subject request output sequence
#include<bits/stdc++.h>
using namespace std;
int num[100005];
int MINN = 99999,pos=0;
int main()
{
int n,ncount=0;cin>>n;
for(int i=0;i<n;i++)
{
cin >> num[i];
if(num[i]>=0)
num[i] = -num[i] - 1;
if(num[i]<=MINN&&num[i]!=-1)
{
pos=i;
MINN=num[i];
}
}
if(n%2!=0)
{
num[pos]=-num[pos]-1;
}
for(int i=0;i<n;i++)
{
cout<<num[i]<<" ";
}
return 0;
}
C title
The basic idea
When deque q [0] is the maximum value will fall into the loop, therefore, the number of recursive steps need not exceed \ (10 ^ 5 \) the second number, the back die may be used to select the output array subscript of . (Remember to pop_front modulo n-1)
#include<bits/stdc++.h>
#include<deque>
using namespace std;
struct{
int a,b;
}qu[100010];
int main()
{
deque<int>q;int n,query,maxn=-99999;
cin>>n>>query;
for(int i=0;i<n;i++)
{
int num;cin>>num;
q.push_back(num);
maxn=max(maxn,num);
}
long long cnt=0;
while(q.front()!=maxn)
{
cnt++;
int n1=q.front();
q.pop_front();int n2=q.front();q.pop_front();
q.push_front(max(n1,n2));
q.push_back(min(n1,n2));
qu[cnt].a=n1;qu[cnt].b=n2;
}
q.pop_front();
for(int i=0;i<query;i++)
{
long long m;
cin>>m;
if(m<=cnt)
{
cout<<qu[m].a<<" "<<qu[m].b<<endl;
}
else
{
int pos=(m-cnt-1)%(n-1);
cout<<maxn<<" "<<q[pos]<<endl;
}
}
return 0;
}