Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) 简单解析

A题

输入两个长度为n的数组a,b,(其中第i项是1的话代表有,0代表没有, 要求a比b数组大,对于每一项都有对应的价值pi, 尽可能控制每一项最小)

输出 要求出使得a数组比b大的pi中的最大项

思路:相同情况的就抵消掉(不许考虑),只需要考虑1.b有,a没有;2.  a有,b没有,两种情况,对于所有1情况都将对应的pi设置为1,计算总和,然后平分在情况2中

 1 #include <iostream>
 2 #include <bits/stdc++.h>
 3
 4 using namespace std;
 5 typedef long long ll;
 6 typedef pair<int,int>PII;
 7 const int N = 1e5+10;
 8 const ll mod = 1e9+7;
 9 int a[110],b[110];
10 int main()
11 {
12     int n;
13     cin >> n;
14     ll num =0,cun=0;
15     for(int i=1;i<=n;i++)
16     {
17         cin>> a[i];
18     }
19      for(int i=1;i<=n;i++)
20     {
21         cin>> b[i];
22     }
23      for(int i=1;i<=n;i++)
24     {
25         if(b[i]==1&&a[i]==1)continue;
26         else if(a[i]==1&&b[i]==0)num++;
27         else if(a[i]==0&&b[i]==1)cun++;
28     }
29     if(num==0)
30     {
31         cout << -1<<endl;
32     }
33     else
34     cout << cun/num +1<<endl;
35     return 0;
36 }

B题

输入长度为n的一组数组

输出符合条件的最大和

条件是要求 对于满足 ( aj - ai = j- i   )一组数(对于这一组数任意两项瞒足,这个条件)的和,求最大和

重点分析一下哈aj-ai = j- i,合并一下同类项  aj - j = ai - i;因此可以将这个数组所有的情况都计算一遍

 1 B
 2 //a[i] - a[j] = i -j;----> a[i]-i=a[j]-j
 3 //这里为了保证a[i]-i>=0;就对n取模
 4 #include <bits/stdc++.h>
 5
 6 using namespace std;
 7 typedef long long ll;
 8 const int N = 2e5+10;
 9 const int M = 1e6+10;
10 int a[N];
11 ll tg[M];
12 int main()
13 {
14     int n;
15     cin >> n;
16     for(int i=1;i<=n;i++)
17     {
18         cin >> a[i];
19         tg[a[i]-i+n]+=a[i];
20     }
21     ll ma =0;
22     for(int i=0;i<=M;i++)
23         ma =max(ma,tg[i]);
24     cout << ma <<endl;
25 }

原文地址:https://www.cnblogs.com/wsxmmfby-jy/p/12400786.html

时间: 2024-10-10 05:37:11

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) 简单解析的相关文章

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(思维题)

Polycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, and the score of each robot in the competition is cal

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最长我们肯定是取最小x和最大的y连起来就完事. 但是要求长度最小又得覆盖,那么可以这样想,我们需要把最小的x不断右移到这条线段的y, 最大的左移到x,所以就是最大x-最小y完事 #include <bits/stdc++.h> using namespace std; #define ll long

【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:

Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round) D. Peculiar apple-tree

D. Peculiar apple-tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained i

cf 20190307 Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)

B. Mike and Children time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) 题解

A..B略 C 对当前的值排序,再二分答案,然后对于(i%x==0 && i%y==0)放入大的,再放其他的贪心解决即可. #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #define LL long long #define lson rt<<1 #define rson rt<

Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

B2 - TV Subscriptions (Hard Version) 遍历,维护一个set和set<pair<int,int>>即可 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e6+7; 5 const ll mod = 1e9 + 9; 6 #define afdafafafdafaf y1; 7 int ar[maxn]

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造

C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence s=s1s2-sn of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation you can choo

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心

B. Box Permutation p is a sequence of integers p=[p1,p2,-,pn], consisting of n distinct (unique) positive integers between 1 and n, inclusive. For example, the following sequences are permutations: [3,4,1,2], [1], [1,2]. The following sequences are n