首页 > 其他分享 >Codeforces Round #655 (Div. 2)

Codeforces Round #655 (Div. 2)

时间:2023-02-03 11:33:49浏览次数:41  
标签:cnt int rep Codeforces -- 655 ans Div sd


A Omkar and Completion

只要找两个相加不等的数交叉构造即可。

AC代码:

int main()
{
int t;
sd(t);
while (t--)
{
sd(n);
rep(i, 1, n)
{
if (i & 1)
printf("500 ");
else
printf("501 ");
}
printf("\n");
}
return 0;
}

B. Omkar and Last Class of Math

Codeforces Round #655 (Div. 2)_5e 为两个解,假设 Codeforces Round #655 (Div. 2)_整除_02,那么显然 Codeforces Round #655 (Div. 2)_Math_03 一定 Codeforces Round #655 (Div. 2)_5e_04。这里我们一定要构造 Codeforces Round #655 (Div. 2)_Math_05 的解,因为 Codeforces Round #655 (Div. 2)_Math_06 一定 Codeforces Round #655 (Div. 2)_Math_07,而 Codeforces Round #655 (Div. 2)_Math_03Codeforces Round #655 (Div. 2)_Math_06 的倍数,就算 Codeforces Round #655 (Div. 2)_Math_10 也一定 Codeforces Round #655 (Div. 2)_5e_11,所以 Codeforces Round #655 (Div. 2)_Math_05 也就是说,Codeforces Round #655 (Div. 2)_整除_13 可以整除 Codeforces Round #655 (Div. 2)_Math_06,这又等价于 Codeforces Round #655 (Div. 2)_整除_13 整除 Codeforces Round #655 (Div. 2)_5e_16。要让 Codeforces Round #655 (Div. 2)_Math_03 尽可能小,相当于让 Codeforces Round #655 (Div. 2)_Math_06 尽可能小也就是 Codeforces Round #655 (Div. 2)_整除_13 尽可能大。所以总结一下,要让 Codeforces Round #655 (Div. 2)_整除_13 整除 Codeforces Round #655 (Div. 2)_5e_16 并且 Codeforces Round #655 (Div. 2)_整除_13 尽可能大,那就找 Codeforces Round #655 (Div. 2)_5e_16 的最大的不等于 Codeforces Round #655 (Div. 2)_5e_16

AC代码:

int main()
{
int t;
sd(t);
while (t--)
{
sd(n);
if (n % 2 == 0)
{
pdd(n / 2, n / 2);
continue;
}

int ans = -1;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
{
ans = max(ans, i);
ans = max(ans, n / i);
}
}
if (ans == -1)
ans = 1;
pdd(ans, n - ans);
}
return 0;
}

C. Omkar and Baseball

  • 原序列已经是 Codeforces Round #655 (Div. 2)_Math_25
  • 原序列中,有一段区间中所有元素都错位,操作一次。
  • 原序列中一部分在原位置,一部分不在原位置,操作两次。

AC代码:

const int N = 5e5 + 50;
int n, k, m;
int a[N];

int main()
{
int t;
sd(t);
while (t--)
{
sd(n);
int cnt = 0;
rep(i, 1, n)
{
sd(a[i]);
if (a[i] == i)
cnt++;
}
if (cnt == n)
{
puts("0");
continue;
}
rep(i, 1, n)
{
if (a[i] == i)
cnt--;
else
break;
}
per(i, n, 1)
{
if (a[i] == i)
cnt--;
else
break;
}
if (cnt == 0)
puts("1");
else
puts("2");
}
return 0;
}

D. Omkar and Circle

首先把环断开,发现最优情况只可能是把所有奇数位置上的数加起来。因为偶数位置的数根本不可能留到最后。那么这个结论应用到环上就是,很多“偶数”位置其实都会被抛弃,最后的答案一定是,选取恰当的位置把环断开后的奇数位置之和。所以实现的时候只要记录奇偶位置的前缀和,然后 Codeforces Round #655 (Div. 2)_5e_26

AC代码:

const int N = 5e5 + 50;
int n, k, m;
ll a[N], s[2][N];

int main()
{
int t;
sd(n);
rep(i, 1, n)
{
sld(a[i]);
s[0][i] = s[0][i - 1] + (i % 2 == 0 ? a[i] : 0);
s[1][i] = s[1][i - 1] + (i % 2 == 1 ? a[i] : 0);
}
ll ans = 0;
rep(i, 1, n)
ans = max(ans, s[i % 2][i] + s[i % 2 ^ 1][n] - s[i % 2 ^ 1][i]);
pld(ans);
return 0;
}


标签:cnt,int,rep,Codeforces,--,655,ans,Div,sd
From: https://blog.51cto.com/u_15952369/6035732

相关文章

  • Codeforces 1360 D. Buying Shovels
    题意:要买个铲子,商店中有中不同的卖法,依次每一次卖到个铲子,现在只能选择其中的一种买法,问最少买几次同一种的买法,使得刚好买到直接选择小于的AC代码:intn,m,k;......
  • Codeforces 1360 E. Polygon
    题意:在一个的网格上方和左边都有一排大炮,每次可以发射一个,遇到边界和都会停下来,有没有一种发射频率可以组成给出的大炮的位置在左和上,所以每个非右边界或者下边界的......
  • Codeforces 1358 C. Celex Update
    题意:一个矩形内有多个方格,每个方格都按照顺序填写了一些数。给两个坐标,求这两个坐标间路径经过的数字和不同的路线总数。可以看出比如要从走到,这两种走法和第二个比......
  • Codeforces 1354 D. Multiset(树状数组)
    题意;要你实现一个求第k大数的数据结构。树状数组模板题。AC代码:constintN=1e6+50;inta[N];intn,q;voidadd(intp,intval){while(p<=n){a[p]+=va......
  • codeforces 580C Kefa and Park (树上DFS)
    Description:Kefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisarootedtreeconsistingof n ve......
  • CodeForces - 253E Table with Letters - 2
    Description:Let'sconsideranetworkprinterthatfunctionslikethat.Itstartsworkingattime0.Ineachseconditcanprintonepageofatext.Atsomemomen......
  • Codeforces1201 B Maximum Median (二分)
    Description:Youaregivenanarray aa of nn integers,where nn isodd.Youcanmakethefollowingoperationwithit:Chooseoneoftheelementsofthearray......
  • Codeforces Round #596 D
    找到a[i]*a[j]=x^k符合这个式子的有多少种组合。分解质因子来做就行了AC代码:#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<s......
  • Codeforces-343D Water Tree(树链剖分)
    Description:MadscientistMikehasconstructedarootedtree,whichconsistsof n vertices.Eachvertexisareservoirwhichcanbeeitheremptyorfilledw......
  • Codeforces Round #596 B2. TV Subscriptions
    题意就是让你在N个数中找到D个连续的数,使这D个数中不同的数最小。hard数据较大,优化到nlogn才能过。具体怎么优化看代码吧AC代码:#include<cstdio>#include<cstring>......