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

SMU Summer 2023 Contest Round 2

时间:2023-08-03 12:56:56浏览次数:53  
标签:Summer Contest int SMU 50 num ans ll s1

Problem - A Treasure Hunt

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 1e5 + 50, M = 5e3 + 50, mod = 9901, MAX_N = 6e3 + 50, INF = 0x3f3f3f3f;
const double PI = 3.1415926;
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)

int x, x2, y, y2, a, b;
int main () {
    IOS;
    cin >> x >> y >> x2 >> y2;
    cin >> a >> b;
    if(abs(y - y2) % b != 0 || abs(x - x2) % a != 0)
        cout << "No" << endl;
    else {
        int cnt1 = 0, cnt2 = 0;
        int n = abs(x - x2), m = (y - y2);
        cnt1 = n / a, cnt2 = m / b;
        if(abs(cnt1 - cnt2) % 2 == 0)
            cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Problem - B Makes And The Product

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 1e5 + 50, M = 3e5 + 50, mod = 9901, MAX_N = 6e3 + 50, INF = 0x3f3f3f3f;
const double PI = 3.1415926;
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
ll a[M], n;
map<ll, int> mp;
ll C[N][10];

int main () {
    IOS;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    sort (a + 1, a + 1 + n);
    ll ans = 0;
    C[1][0] = C[1][1] = 1;
    for (int i = 2; i < N; i++) {
        C[i][0] = 1;
        for (int j = 1; j < 6; j++)
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]);
    }
    if (a[1] != a[2] && a[1] != a[3] && a[2] != a[3]) {
        ans = mp[a[1]] * mp[a[2]] * mp[a[3]];
    } else if (a[1] == a[2] && a[2] == a[3]) {
        int num = mp[a[1]];
        ans = C[num][3];
    } else if (a[1] == a[2]) {
        int num = mp[a[1]];
        ans = C[num][2];
        ans *= 1ll * mp[a[3]];
    } else if (a[2] == a[3]) {
        int num = mp[a[2]];
        ans = C[num][2];
        ans *= 1ll * mp[a[1]];
    } else if (a[1] == a[3]) {
        int num = mp[a[1]];
        ans = C[num][2];
        ans *= 1ll * mp[a[2]];
    }
    cout << ans << endl;
    return 0;
}

Problem - C Really Big Numbers

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 1e5 + 50, M = 3e5 + 50, mod = 9901, MAX_N = 6e3 + 50, INF = 0x3f3f3f3f;
const double PI = 3.1415926;
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)

ll n, s;

ll cal (ll x) {
    ll res = 0;
    while (x) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

bool check (ll x) {
    if (x - cal (x) >= s) return 1;
    return 0;
}

int main () {
    IOS;
    cin >> n >> s;
    ll l = 1, r = 1e18;
    ll ans = -1;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        if (check (mid)) {
            ans = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    if (ans > n || ans == -1)
        cout << 0 << endl;

    else cout << n - ans + 1;
    return 0;
}

Problem - D Imbalanced Array(单调栈)

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 1e6 + 50, M = 3e3 + 50, mod = 9901, MAX_N = 6e3 + 50, INF = 0x3f3f3f3f;
const double PI = 3.1415926;
#define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
ll num[N], la[N], ra[N], res, n;

int main () {
    IOS;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> num[i];
    stack<int> s1, s2;
    for (int i = 0; i < n; ++i) {
        while (!s1.empty () && num[i] > num[s1.top ()])
            s1.pop ();
        if (!s1.empty ()) la[i] = s1.top ();
        else la[i] = -1;
        s1.push (i);
    }
    for (int i = n - 1; i >= 0; --i) {
        while (!s2.empty () && num[i] >= num[s2.top ()])
            s2.pop ();
        if (!s2.empty ()) ra[i] = s2.top ();
        else ra[i] = n;
        s2.push (i);
    }
    for (int i = 0; i < n; ++i)
        res = res + num[i] * (ra[i] - i) * (i - la[i]);
    while (!s2.empty ()) s2.pop ();
    while (!s1.empty ()) s1.pop ();
    for (int i = 0; i < n; ++i) {
        while (!s1.empty () && num[i] < num[s1.top ()])
            s1.pop ();
        if (!s1.empty ()) la[i] = s1.top ();
        else la[i] = -1;
        s1.push (i);
    }
    for (int i = n - 1; i >= 0; --i) {
        while (!s2.empty () && num[i] <= num[s2.top ()])
            s2.pop ();
        if (!s2.empty ()) ra[i] = s2.top ();
        else ra[i] = n;
        s2.push (i);
    }
    for (int i = 0; i < n; ++i)
        res = res - num[i] * (ra[i] - i) * (i - la[i]);
    cout << res << endl;
    return 0;
}

标签:Summer,Contest,int,SMU,50,num,ans,ll,s1
From: https://www.cnblogs.com/Lazyboyjdj/p/17603020.html

相关文章

  • SMU Summer 2023 Contest Round 3
    Problem-A-CurriculumVitae#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+50,M=5050,mod=9901,MAX_N=1e3+50,INF=0x3f3f3f3f;#defineintlonglong#defineldlongdouble#defineIOSios_base::sync_with_stdio(false)......
  • 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&......