首页 > 其他分享 >Codeforces Round 892 div2.C

Codeforces Round 892 div2.C

时间:2023-08-13 12:45:00浏览次数:42  
标签:892 const int Codeforces long typedef ans div2 define

这C真的魔幻,官方题解完全和写的不一样,太玄学了,打表发现的规律

这是打表代码:

int main()
{
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        a[i] = i;
    LL ans = 0;
    do
    {
        auto b = a;
        LL sum = 0, mx = 0;
        for (LL i = 1; i <= n; i++)
        {
            sum += b[i] * i;
            mx = max(mx, b[i] * i);
        }
        sum -= mx;
        if (sum > ans)
        {
            ans = sum;
            cout << "ans = " << ans << endl;
            for (int i = 1; i <= n; i++)
                cout << b[i] << ' ';
            cout << endl;
        }
    } while (next_permutation(a.begin() + 1, a.end()));
    return 0;
}

然后通过打表发现的数据发现是反转一段后缀区间就行了0.o

以下是暴力求解正解:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f; // 无穷大
const int MOD = 1e9 + 7;    // 取余
const int N = 2e5 + 10;     // 初始N
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define endl '\n'
LL n, m;
void solve()
{
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        a[i] = i;
    LL ans = 0;
    for (int i = 1; i <= n; i++)
    {
        auto b = a;
        reverse(b.begin() + i, b.end());
        int sum = 0, mx = 0;
        for (int j = 1; j <= n; j++)
        {
            sum += j * b[j];
            mx = max(mx, j * b[j]);
        }
        if (sum - mx > ans)
        {
            ans = sum - mx;
            // cout << "ans=" << ans << endl;
            // for (int i = 1; i <= n; i++)
            //     cout << b[i] << ' ';
            // cout << endl;
        }
    }
    cout << ans << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

 

标签:892,const,int,Codeforces,long,typedef,ans,div2,define
From: https://www.cnblogs.com/crismiao/p/17626399.html

相关文章

  • Codeforces Round 892 (Div.2)
    A.UnitedWeStand题解赛时想复杂了题目要求我们保证数组\(c\)中的数不是数组\(b\)中任意一个数的因子我们考虑将最小值置于数组\(b\)即可constintN=2e5+10,M=4e5+10;intn;inta[N];voidsolve(){cin>>n;intmi=INF;for(inti......
  • Codeforces Round 874 G题解
    做不动那么多题了,来个GG就是问你一棵树能切成多少个大小为3的链,想了半天,想过dp啥的,但是后来发现这个贪心就好了,可以证明贪心找不到的,其他方法也找不到好久没复健了,这是第一次,感觉以后要多做题才可以#include<bits/stdc++.h>usingnamespacestd;constexprintlimit=(4e......
  • Codeforces Round 799 (Div. 4)(vp)
    CodeforcesRound799(Div.4)AMarathonvoidsolve(){vector<int>a(4);intgoal;cin>>goal;intans=0;for(inti=0;i<3;i++){intx;cin>>x;if(goal<x)ans++;}co......
  • Codeforces 1854E - Game Bundles
    都这么会乱搞的吗/xia随机生成若干\(<30\)的数直到它们当中和为\(60\)的子集个数\(>k\)为止。删去最后一个元素。然后考虑贪心确定\(>30\)的部分,具体方法是按照\(dp_{60-x}\)从大到小贪心选,如果剩余子集个数\(\gedp_{60-x}\)就在序列中加入\(x\)。如此随机化直到找......
  • CodeForces 1610F Mashtali: a Space Oddysey
    洛谷传送门CF传送门比较有启发性的题。首先,设\(a_u\)为与点\(u\)相连的边权和,答案的上界显然是\(\sum\limits_{i=1}^n[a_u\bmod2=1]\)。之后我们把P7816「Stoi2029」以父之名第一篇题解的做法搬过来,也就是:建一个虚点向原图度数为奇数的点连边权为\(1\)的边......
  • 【题解】Educational Codeforces Round 147(CF1821)
    自己做出来了A-E,F算是搞懂GF后第一道符合我这个菜鸡水平的实战,可惜的是根本没意识到可以GF。A.Matching题目描述:整数模板是每位均为数字或问号的字符串。如果可以用数字替换模板中的每个问号,从而获得该正整数(严格大于\(0\))的十进制表示形式,且不带任何前导零,则该正整数......
  • Codeforces Round 874 (Div. 3) 题解
    A.MusicalPuzzle字符串\(s\)的不同的长度为\(2\)的子串个数就是答案可以用set处理B.RestoretheWeather将\(a\)数组排序后,在\(b\)数组中找到第一个大于等于\(a_i-k\)的元素与\(a_i\)对应即可可以用multiset实现(用multiset自带的lower_bound()比较好,......
  • Codeforces Round 878 (Div. 3) 题解
    A.CipherShifer从头开始扫一遍即可,扫到两个相同的表示某一个字符的解密结束B.BinaryCafe首先,我们不妨把题意转换为有多少种不同的花钱方案因为每一种咖啡就是一个二进制有\(k\)位的数字的其中一位,而对于不同的方案,其二进制位不完全相同,则每一个方案对应的花费一定不同,......
  • 【题解】Educational Codeforces Round 148(CF1832)
    A.NewPalindrome题目描述:给你一个由小写字母组成的回文字符串,问你是否能在重排其之后构造出另一个与原串不同的回文字符串。多测,\(t\le1000,2\le|s|\le50\)题目分析:考虑其实就是前\(\lfloor\frac{n}{2}\rfloor\)个位置存在两种或以上的不同字符,因为这样直接交换对......
  • Codeforces 1857E:Power of Points 区间?
    1857E.PowerofPointsDescription:\(n\)个数:\(x_1,···,x_n\),从左向右扫,当\(s=x_i\)时,可以将这\(n\)个数分为若干个闭区间\([s,x_1],[s,x_2],···,[s,x_n]\)(当然如果\(x_i<s\),则区间形如\([x_i,s]\))对于每一个\(s\in(x_1,···,x_n),\)有一个整数\(p\),记\(f_......