A. TubeTube Feed
分析:
从所有a[i]+i-1
code:
#include
using namespace std;
const int N = 55;
int a[N], b[N];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t --)
{
int n, m;
cin >> n >> m;
for (int i = 0; i > a[i];
for (int i = 0; i > b[i];
int s = 0, res = 0, idx = -1;
bool flag = false;
for (int i = 0; i res)
{
res = b[i];
idx = i + 1;
}
}
s ++;
}
if (!flag)
cout
B. Karina and Array
分析:
实际上就是取同符号乘积的最大值
code:
#include
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N];
typedef long long LL;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t --)
{
int n;
cin >> n;
if (n == 2)
{
int num1, num2;
cin >> num1 >> num2;
cout > x;
if (x >= 0)
a[cnt1 ++] = x;
else
b[cnt2 ++] = x;
}
sort(a, a + cnt1);
sort(b, b + cnt2);
LL res;
if (cnt1 >= 2 && cnt2 >= 2)
{
res = max((LL)b[0] * b[1], (LL)a[cnt1 - 2] * a[cnt1 - 1]);
}
else if (cnt1 >= 2 && cnt2 = 2)
res = (LL)b[0] * b[1];
cout
C. Bun Lover
分析:
找规律,发现结果与边长n的关系是:res = n * (n + 3) – (n – 2)
code:
#include
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N];
typedef long long LL;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t --)
{
LL n;
cin >> n;
cout
D. Super-Permutation
分析:
①当n为奇数时,除了1其他均无解
②当n为偶数时,我们可以构造一个形如n,1,n – 2,3,…的数列
首先我们可以发现n必定出现在起始位置。如果n不在起始位置,假设在位置i,那么s[i – 1] % n == (s[i – 1] + n) % n = s[i] % n。
接着,考虑构造方式。最方便的即是考虑让序列取模结果为:0,1,-1,2,-2…(-1取模意义下溢出实际上就是n – 1),按上述结果形式构造的序列n,1,n – 2,3,…即可满足所有条件
最后从结果来看就是n在偶数位递减,1在奇数位递增。
code:
#include
using namespace std;
const int N = 2e5 + 5;
int a[N];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t --)
{
int n;
cin >> n;
if (n == 1)
cout
E. Making Anti-Palindromes
分析:
①当n为奇数时:根据定义无解。
②当n为偶数时:
当某个字符出现的次数大于n / 2时,根据容斥原理,一定存在s[i] = s[n – i + 1]。
若不存在上述情况则一定有解,考虑如何处理对称字符:倘若存在形如..a..b..b..a的字符对我们优先选择交换a和b,这样一次操作可以处理两对字符,否则将对称对形如..a..b..d..a的情况交换a和d,一次操作处理一对字符。统计出现次数最多的字符对,其出现次数记为cnt1,所有字符对总数量记为cnt2,优先处理cnt1,所以当cnt1
code:
#include
using namespace std;
const int N = 27;
int h[N], h2[N];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t --)
{
int n;
cin >> n;
string s;
cin >> s;
if (n & 1)
cout n / 2)
{
check = false;
break;
}
}
if (check)
{
int Max = 0, cnt = 0;
for (int i = 0, j = n - 1; i
机房租用,北京机房托管,大带宽租用,IDC机房服务器主机租用托管-价格及服务咨询 www.e1idc.net