首页 > 其他分享 >SMU Summer 2023 Contest Round 3

SMU Summer 2023 Contest Round 3

时间:2023-08-03 12:56:44浏览次数:54  
标签:Summer cout Contest int SMU cin long ans define

Problem - A - Curriculum Vitae

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 50, M = 5050, mod = 9901, MAX_N = 1e3 + 50, INF = 0x3f3f3f3f;
#define int long long
#define ld long double
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)

int n, A[M], dp[M], ans = 0;

signed main () {
    IOS;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < n; i++) {
        dp[i] = 1;
        for (int j = 0; j < i; j++) {
            if (A[i] >= A[j]) {
                dp[i] = max (dp[i], dp[j] + 1);
            }
        }
        ans = max (ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}

Problem - B - Math Show

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 50, M = 5050, mod = 9901, MAX_N = 1e3 + 50, INF = 0x3f3f3f3f;
#define int long long
//#define ld long double
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)

int n, k, m, a[M];
int ans, s, t, cnt, sum;

void init () {
    cin >> n >> k >> m;
    for (int i = 1; i <= k; i++) {
        cin >> a[i];
        s += a[i];
    }
}

signed main () {
    IOS;
    init ();
    sort (a + 1, a + k + 1);
    for (int i = 0; i <= n; i++) {
        t = s * i;
        if (t > m) break;
        sum = t, cnt = (k + 1) * i;
        for (int j = 1; j <= k; j++) {
            for (int r = i + 1; r <= n; r++) {
                cnt++;
                sum += a[j];
                if (sum > m) {
                    cnt--;
                    j = k + 1;
                    break;
                }
            }
        }
        ans = max (ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Problem - C - Four Segments

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 50, M = 5050, mod = 9901, MAX_N = 1e3 + 50, INF = 0x3f3f3f3f;
#define int long long
//#define ld long double
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
int num[N], s[N];

int sum (int l, int r) {
    return s[r] - s[l];
}

int n, a, k, pos, b, c, ans, cnt;

void init () {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> num[i];
        s[i] = s[i - 1] + num[i];
    }
}

signed main () {
    IOS;
    init ();
    ans = -INF;
    for (int i = 0; i <= n; i++) {
        k = s[i];
        pos = i;
        for (int j = i; j <= n; j++) {
            if (s[j] < k) {
                pos = j;
                k = s[j];
            }
            cnt = sum (0, i) - sum (i, pos) + sum (pos, j) - sum (j, n);
//            cout << cnt << endl;
            if (cnt >= ans) {
                a = i, b = pos, c = j;
                ans = cnt;
            }
        }
    }
    cout << a << " " << b << " " << c << endl;

    return 0;
}

Problem - D - Monitor

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 50, M = 600, mod = 9901, MAX_N = 1e3 + 50, INF = 0x3f3f3f3f;
//#define int long long
//#define ld long double
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)

int n, m, k, q, s[M][M];
long long a[M][M], x, y;

void init () {
    cin >> n >> m >> k >> q;
    for (int i = 0; i < q; i++) {
        cin >> x >> y >> a[x][y];
        a[x][y]++;
    }
}

bool check (int mid) {
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            if (a[i][j] && a[i][j] <= mid) s[i][j] = 1;
            else s[i][j] = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
    for (int i = k; i <= n; ++i)
        for (int j = k; j <= m; ++j) {
            int t = s[i][j] - s[i - k][j] - s[i][j - k] + s[i - k][j - k];
            if (t == k * k)
                return 1;
        }
    return 0;
}

signed main () {
    IOS;
    init ();
    int l = 0, r = 1e9 + 10;
    while (l < r) {
        int mid = (l + r) >> 1;
        if (check (mid)) r = mid;
        else l = mid + 1;
    }
    if (check (r)) cout << r - 1 << endl;
    else cout << -1 << endl;
    return 0;
}

Problem - F - Random Query

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 50, M = 600, mod = 9901, MAX_N = 1e3 + 50, INF = 0x3f3f3f3f;
#define int long long
#define ld long double
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)

int n, a[N], k[N], ans;

signed main () {
    IOS;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--) {
        if (k[a[i]] == 0) {
            ans += i * (n - i + 1);
        } else
            ans += i * (k[a[i]] - i);
        k[a[i]] = i;
    }
    cout << fixed << setprecision (6) << (ld) (ans * 2 - n) / (n * n);
    return 0;
}

标签:Summer,cout,Contest,int,SMU,cin,long,ans,define
From: https://www.cnblogs.com/Lazyboyjdj/p/17603021.html

相关文章

  • The 10th Shandong Provincial Collegiate Programming Contest
    The10thShandongProvincialCollegiateProgrammingContestK-HappyEquation思路:a,x的奇偶性相同(因为都对偶数取模),且打表得出a为奇数时,答案为1。(¿)a为偶数时,令a=t1*2q  → ax=t1x*2qx若axmod2p为0,则qx>=p,x>=p/q;由于q>=1(a为偶数),则x>=p;x与a同为偶数,令x'=t2*2k→x'a......
  • AtCoder Beginner Contest 165
    AtCoderBeginnerContest165https://atcoder.jp/contests/abc165C-ManyRequirementsdfs#include<bits/stdc++.h>usingnamespacestd;constintN=15,M=55;intn,m,q,ans;inta[M],b[M],c[M],d[M],A[N];voiddfs(intx){if(x>......
  • AtCoder Beginner Contest 312
    A-Chord#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);strings;cin>>s;if(s=="ACE")cout<<"Yes\n";e......
  • [UNIQUE VISION Programming Contest 2023 Summer(AtCoder Beginner Contest 312) - A
    UNIQUEVISIONProgrammingContest2023Summer(AtCoderBeginnerContest312)-AtCoderA-Chord(atcoder.jp)#include<bits/stdc++.h>#defineendl'\n'usingnamespacestd;intmain(){vector<string>str{"ACE",&qu......
  • Atcoder-Beginner-Contest-312 A~Ex
    \(Atcoder-Beginner-Contest-312\)AB过于简单,在此略去。\(C-Invisible\)\(Hand\)题意:给定长为\(n\)的数组\(a\),长为\(m\)的数组\(b\),找到最小的非负整数\(x\),使得\(\sum_{i=1}^n[a_i\lex]\ge\sum_{i=1}^m[b_i\gex]\)题解:容易发现,随着\(x\)的增大,右式单调不升,左......
  • (AtCoder Beginner Contest 312)
    (AtCoderBeginnerContest312)A-Chord#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128typedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,string>PSS;constintN......
  • SMU Summer 2023 Contest Round 7
    SMUSummer2023ContestRound7A.TwoRivalStudents答案不能大于\(n-1\);如果竞争对手之间的当前距离小于\(n-1\),我们总是可以将这个距离增加一个交换数;即答案等于\(min(n-1,|a-b|+x)\)。#include<bits/stdc++.h>#defineintlonglongusingnamespac......
  • SMU Summer 2023 Contest Round 6
    SMUSummer2023ContestRound6A.ThereAreTwoTypesOfBurgers从0枚举到汉堡的最大个数,取最大值#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;signedmain(){ios::sync_with_stdio(false);cin.tie(nullptr);intT;cin>>......
  • AtCoder Beginner Contest 311
    AtCoderBeginnerContest311FirstABC思路:找到第一个a,b,c都出现的位置#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128typedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,string&......
  • AtCoder Beginner Contest 311
    A-FirstABC#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongint32_tmain(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);intn;strings;cin>>n>>s;set<char>c......