首页 > 其他分享 >Codeforces Round 867 (Div. 3)

Codeforces Round 867 (Div. 3)

时间:2023-12-17 16:46:09浏览次数:28  
标签:cout int Codeforces long cin solve 867 && Div

Codeforces Round 867 (Div. 3)

A:ABCD (E差一点点,最后把那种特殊情况想出来然后没写上去就结束了)

A. TubeTube Feed

题意:给两个数组分别是时间和价值,要价值最大但是只能选一个

思路:最开始以为是01背包,结果只选一个,一个一个枚举就行

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, t;
    cin >> n >> t;
    vector<int> a(n + 1);
    vector<int> b(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    int maxx = 0, ans = -1;
    for (int i = 1; i <= n; i++) {
        int x = a[i], y = b[i];
        int tt = i - 1 + x;
        if (tt <= t) {
            if (y > maxx) {
                ans = i;
                maxx = y;
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

B. Karina and Array

题意:两个数乘积最大

思路:分为两种情况负数×负数,正数×正数

#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve() {
    int x1 = 0, x2 = 0, y1 = 0, y2 = 0;//x表示正数y表示负数
    int n;
    cin >> n;
    if (n == 2) {
        int a, b;
        cin >> a >> b;
        cout << a * b << "\n";
        return;
    }
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a > 0 && a > x1 && a <= x2) {
            x1 = a;
        } else if (a > 0 && a > x2) {
            x1 = x2;
            x2 = a;
        } else if (a < 0 && a < y1 && a >= y2) {
            y1 = a;
        } else if (a < 0 && a < y2) {
            y1 = y2;
            y2 = a;
        }
    }
    cout << max(x1 * x2, y1 * y2) << "\n";
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

C. Bun Lover

题意:就是求棕色图案的长度

思路:慢慢找规律面向样例编程

#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve() {
    int n;
    cin >> n;
    cout << n * (n + 1) + n + 2 << "\n";
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

D. Super-Permutation

题意:给一个n,b[i]=(a[1]+...+a[i]) mod n,b如果也是一个排列那么a就是超级排列,输出a

思路:当n是奇数的时候,最后一个数求和应该是
$$
b[i]=(n+1)*n/2; b[i]mod n=0
$$
所以此时b是不可能为一个排列的
$$
确定n的位置因为 x mod n=(x+n) mod n 所以n必须处在第一位
$$
并且x和n-x不能连续排列,那么就1,n-2...这样排列

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAX = 2e5 + 10;
bool st[MAX];

void solve() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << "1\n";
        return;
    }
    if (n % 2) {
        cout << "-1\n";
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (i % 2) {
            cout << n - i + 1 << " ";
        } else {
            cout << i - 1 << " ";
        }
    }
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

E. Making Anti-Palindromes

题意:反排列:a[i]!=a[n-i-1]

操作:交换两个数;目标:整个数组都是反排列

思路:有两种情况直接不行1.他是奇数的话中间那个数始终与自身相等

2.若整个排列中有超过一半的数都是相同的也不行

剩下的就可以变成反排列,操作次数:应该为总次数的一般

注意:相同的是不能互相变化的(最后就是被这里卡了一下)

#include <bits/stdc++.h>

using namespace std;
#define int long long
int x[26], y[26];
const int MAX = 2e5 + 10;
char a[MAX];

void solve() {
    int n;
    memset(x, 0, sizeof(x));
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x[a[i] - 'a']++;
    }
    if (n % 2) {
        cout << "-1\n";
        return;
    }
    int ma = *max_element(x, x + 26);
    if (ma > n / 2) {
        cout << "-1\n";
        return;
    }
    int sum = 0;
    memset(y, 0, sizeof(y));
    for (int i = 0; i < n / 2; i++) {
        if (a[i] == a[n - i - 1]) {
            y[a[i] - 'a']++;
            sum++;
        }
    }
    int mx = *max_element(y, y + 26);
    if (mx <= sum / 2) {
        cout << (sum + 1) / 2 << '\n';
    } else {
        cout << mx << '\n';
    }
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

F. Gardening Friends

后面在补大概思路就是bfs+树形dp

板子(bfs):

queue<int> q;
st[1] = true; // 表示1号点已经被遍历过
q.push(1);

while (q.size())
{
    int t = q.front();
    q.pop();

    for (int i = h[t]; i != -1; i = ne[i])
    {
        int j = e[i];
        if (!st[j])
        {
            st[j] = true; // 表示点j已经被遍历过
            q.push(j);
        }
    }
}

标签:cout,int,Codeforces,long,cin,solve,867,&&,Div
From: https://www.cnblogs.com/bbbbear/p/17909279.html

相关文章

  • Codeforces Round 855 (Div. 3)
    CodeforcesRound855(Div.3)A.IsItaCat?题意:要求:字符串必须以只包含字母"m"或"M"的非空序列开始必须紧跟由'e'或'E'字符组成的非空序列必须紧接着仅由字符'o'或'O'组成的非空序列必须紧接着是仅由字符'w'或'W'组成的非空序列思路:一个一个来(WA了三发注意这几......
  • Codeforces Round 913 (Div. 3)
    CodeforcesRound913(Div.3)A:ABCA.Rook简单题,就两个循环搞定(直接上码)#include<bits/stdc++.h>usingnamespacestd;voidsolve(){chara;intb;cin>>a>>b;for(inti=1;i<=8;i++){if(i!=b){......
  • Codeforces Round 863 (Div. 3)
    CodeforcesRound863(Div.3)A.InsertDigit题意:插入一个字母使得这个数字最大化思路:只要从前往后便利就行#include<iostream>usingnamespacestd;voidsolve(){intn,k;cin>>n>>k;boolx=true,y=false;for(inti=0;i<n;i++){......
  • Codeforces Round 913 (Div. 3)
    CF1907总结A.Rook题面翻译给出车在国际象棋棋盘中的位置,输出其可到达的坐标(不必在意顺序)。车可以横着或竖着走任意格数。分析题意明了,输出车所在行和列所有格子的序号(除车所在位置外)。code#include<bits/stdc++.h>usingnamespacestd;intt;voidsolve(){ string......
  • Codeforces Round 891 (Div3)
    CodeforcesRound891(Div.3)A.ArrayColoring这个我vp的时候写复杂了,想不到答案的思路这么清晰,将两部分分别看,将偶数加进去其奇偶性不变,只有奇数加进去才会改变奇偶性,so只有改变偶数次奇偶性才能使其奇偶性相同,所以cnt%2==0.#include<bits/stdc++.h>usingnamespacestd;......
  • Codeforces Round 816 (Div. 2) VP
    基本情況A秒了,B错一次之后也过了,C没思路。B.BeautifulArrayProblem-B-Codeforcesvoidsolve(){ longlongn,k,b,s; memset(ans,0,sizeof(ans)); std::cin>>n>>k>>b>>s; if(s<b*k){std::cout<<"-1\n";ret......
  • Codeforces Round 815 (Div. 2)
    基本情况脑子太不清楚了。A题有思路,但是各种细节问题(数论题太不熟练了),错了好几次才过。B题直接分析数据愣猜一个解,猜对了。A.BurenkaPlayswithFractionsProblem-A-Codeforces难点在分析输出\(1\)的情况。我的想法是通分,然后直接比分子是否互相整除,想法很对,但是......
  • Codeforces Round 915 (Div. 2)
    A.ConstructiveProblems看了一眼数据,猜测可能是n,m里的最大#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ inta,b; cin>>a>>b; intans=max(a,b); cout<<ans<<"\n";}intmain(){ ios::sync_with_stdio(false);cin.tie......
  • Codeforces Round 915 (Div. 2)
    CodeforcesRound915(Div.2)唉,菜狗。A-CoverinWaterintmain(){IOS;for(cin>>_;_;--_){cin>>n>>m;cout<<max(n,m)<<'\n';}return0;}B-Begginer'sZelda除......
  • Educational Codeforces Round 159 (Rated for Div. 2) C. Insert and Equalize (贪心+
    EducationalCodeforcesRound159(RatedforDiv.2)C.InsertandEqualize思路:首先对\(a\)进行排序,然后对所有差值取gcd,获得可用的最大因子\(gc\),答案有两种情况:一种是\(a_{n+1}\)在$a_1\(~\)a_n$范围内,这时要获得最大的位置一种情况是$a_1\(~\)a_n$......