Codeforces Round 867 (Div. 3)
目录
A. TubeTube Feed
B. Karina and Array
C. 包子情人
D. Super-Permutation
A. TubeTube Feed
输入
5
5 9
1 5 7 6 6
3 4 7 1 9
4 4
4 3 3 2
1 2 3 4
5 7
5 5 5 5 5
2 1 3 9 7
4 33
54 71 69 96
42 24 99 1
2 179
55 66
77 88
输出
3
2
3
-1
2
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int N = 110;
signed main()
{
int t;
cin >> t;
while(t --)
{
int cnt=0,num=0,flag=0;
int a[N],b[N];
int n,m;
cin >> n >> m;
for(int i = 1;i <= n;i ++)
{
cin >> a[i];
a[i]+=i-1;//换一个频道需要花一秒的时间
}
for(int i = 1;i <= n;i ++)
{
cin >> b[i];
}
for(int i = 1;i <= n;i ++)
{
if(a[i]<=m)
{
if(cnt<b[i])
{
cnt=max(cnt,b[i]);
num=i;
flag=1;
}
}
}
if(flag) printf("%lld\n",num);
else printf("-1\n");
}
return 0;
}
B. Karina and Array
例
输入
7
4
5 0 2 1
3
-1 1 0
5
2 0 -1 -4 0
6
-8 4 3 7 1 -9
6
0 3 -2 5 -4 -4
2
1000000000 910000000
7
-1 -7 -2 -5 -4 -6 -3
输出
10
0
4
72
16
910000000000000000
42
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e7;
int a[N],b[N],c[N];
signed main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
for(int i = 1;i <= n;i ++)
{
cin >> a[i];
}
sort(a+1,a+1+n);
printf("%lld\n",max(a[1]*a[2],a[n]*a[n-1]));
}
return 0;
}
C. 包子情人
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
signed main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
printf("%lld\n",(n+1)*(n+1)+1);
}
return 0;
}
D. Super-Permutation
大致题意:
给你一个数n。你需要构造出一个1-n的排列,顺序不定,前缀和之后的数组。每个位置%n,之后,每个位置再加1,仍然是一个排列,就满足了
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int a[N];
signed main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
if(n == 1)
printf("1\n");
else if(n%2)
{
printf("-1\n");
}
else
{
a[0]=n;
for(int i = 1;i < n;i ++)
{
a[i]=n-i;
if(a[i]%2==0) a[i]=n-a[i];
}
for(int i = 0;i < n;i ++)
{
printf("%lld ",a[i]);
}
printf("\n");
}
}
return 0;
}