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

Codeforces Round 883 (Div. 3)

时间:2023-11-30 15:23:33浏览次数:39  
标签:883 return int Codeforces long cin while solve Div

Codeforces Round 883 (Div. 3)

A. Rudolph and Cut the Rope

题意:有一颗糖果在连在绳子上,求剪短多少根绳子,他能落地

思路:只要绳子长度比钉子高度大就不用减

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, res = 0;
    cin >> n;
    while (n--) {
        int a, b;
        cin >> a >> b;
        if (a > b) {
            res++;
        }
    }
    cout << res << "\n";
}

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

B. Rudolph and Tic-Tac-Toe

题意:井字棋判断谁赢谁输

思路:8种情况,判断就行

#include <bits/stdc++.h>

using namespace std;
char mp[4][4];

void solve() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> mp[i][j];
        }
    }
    for (int i = 0; i < 3; i++) {
        bool x = true, y = true;
        for (int j = 1; j < 3; j++) {
            if (x && mp[i][j] != mp[i][j - 1]) {
                x = false;
            }
            if (y && mp[j][i] != mp[j - 1][i]) {
                y = false;
            }
            if (!x && !y) break;
        }
        if (x && mp[i][0] != '.') {
            cout << mp[i][0] << "\n";
            return;
        }
        if (y && mp[0][i] != '.') {
            cout << mp[0][i] << "\n";
            return;
        }
    }
    bool w = true;
    for (int i = 1; i < 3; i++) {
        if (mp[i][i] != mp[i - 1][i - 1]) {
            w = false;
            break;
        }
    }
    if (w && mp[1][1] != '.') {
        cout << mp[1][1] << "\n";
        return;
    }
    w = true;
    for (int i = 1; i < 3; i++) {
        if (mp[i][2 - i] != mp[i - 1][3 - i]) {
            w = false;
            break;
        }
    }
    if (w && mp[1][1] != '.') {
        cout << mp[1][1] << "\n";
        return;
    }
    cout << "DRAW\n";
}

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

C. Rudolf and the Another Competition

题意:判断这个人在第几名

思路:优先级:题目数>罚时(重写cmp)老顽固真不喜欢运算符重载

#include <bits/stdc++.h>

using namespace std;
#define int long long
struct Stu {
    int num;//题数
    int time;//罚时
    int c;//那个b
};

bool cmp(Stu c, Stu b) {
    if (c.num != b.num) {
        return c.num > b.num;

    }
    if (c.time != b.time) {
        return c.time < b.time;
    }
    return c.c > b.c;
}

void solve() {
    int n, m, h;
    cin >> n >> m >> h;
    vector<Stu> a(n + 1);
    for (int i = 1; i <= n; i++) {
        vector<int> b(m + 1);
        for (int j = 1; j <= m; j++) cin >> b[j];
        sort(b.begin() + 1, b.end());
        int cnt = 0, sum = 0, cur = 0;
        for (int j = 1; j <= m; j++) {
            if (cur + b[j] <= h) {
                cnt++;
                cur += b[j];
                sum += cur;
            }
        }
        a[i] = {cnt, sum, 0};
        if (i == 1) a[i].c = 1;
    }
    sort(a.begin() + 1, a.end(), cmp);
    for (int i = 1; i <= n; i++) {
        if (a[i].c == 1) {
            cout << i << endl;
            return;
        }
    }
}

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

D. Rudolph and Christmas Tree

题意:有n个等腰三角形,有重叠,求他们的面积

思路:总面积-重叠的面积

#include <bits/stdc++.h>

using namespace std;
const int MAX = 2e5 + 10;
int a[MAX];

void solve() {
    int n;
    double h, d;
    cin >> n >> d >> h;
    double s = h * n * d / 2;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    double res = 0;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] + h > a[i + 1]) {
            res += (double) (a[i] + h - a[i + 1]) * (a[i] + h - a[i + 1]) * d / (2 * h);
        }
    }
    printf("%.6lf\n", s - res);
}

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

E1. Rudolf and Snowflakes (simple version)

题意:求n=k1+k2+..+k^x

思路:简单版直接爆爆爆爆力

#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve()
{
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        int sum = 1+i+i*i ;
        int temp = i*i ;
        if (sum > n) break;
        while (sum < n)
        {
            temp *= i;
            sum += temp;
        }
        if (sum == n)
        {
            cout << "YES\n" ;
            return;
        }
    }
    cout<<"NO\n";
}
signed main()
{
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

E2. Rudolf and Snowflakes (hard version)

他甚至爆unsigned long long 只能开int_128(shu)

题意:求n=k1+k2+..+k^x(变的是n的范围,所以暴力直接达咩)
$$
很明显等比数列求和:n=a_1*(1-k^x)/(1-q);
$$
思路:n<2e18最大也就2^64,x遍历[2,64],k遍历[2,1e9] (二分遍历)

二分板子:

while (l < r)
    {
        int mid = l + r >> 1;
        if (check(mid)) r = mid;    // check()判断mid是否满足性质
        else l = mid + 1;
    }
    return l;
#include <bits/stdc++.h>

using namespace std;
#define int long long

int check(int k, int x) {//k底数x指数
    __int128 cur = 1, res = 1;
    for (int i = 1; i <= x; i++) {
        cur *= k;
        res += cur;
        if (res >= 2e18) return 2e18;
    }
    return (int) (res);
}

void solve() {
    int n;
    cin >> n;
    for (int x = 2; x <= 63; x++) {
        int l = 2, r = 1e9;
        while (l < r) {
            int mid = (l + r) >> 1;
            int t = check(mid, x);
            if (t >= n)
                r = mid;
            else
                l = mid + 1;
        }
        if (check(l, x) == n) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

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

标签:883,return,int,Codeforces,long,cin,while,solve,Div
From: https://www.cnblogs.com/bbbbear/p/17867454.html

相关文章

  • Codeforces Round 911 (Div. 2)
    CodeforcesRound911(Div.2)基本情况A题秒了。B题条件没想明白,也不造点数据就无脑交,导致罚了不少时。B.LauraandOperations我先推出了,对于一个数,当另外两个数的个数之和为偶数时解可行,且这个数本身要能跟后面数替换。比如11223333就可以操作122333(1......
  • Codeforces Round 910 (Div. 2)
    https://codeforces.com/contest/1898C题可以造一个大小为4的环,然后再造一个来回,这样就解决了%4=0,%4=2的情况,而奇数的情况显然无解。#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<map>#include<vector>#include<set>#includ......
  • Codeforces Round 829 (Div. 1)A1. Make Nonzero Sum (easy version)(思维找规律)
    先考虑无解的情况:当n为奇数时无解相邻的两个元素一定可以变成0\[a[i]!=a[i+1]时,分成[i,i],和[i+1,i+1]\]\[a[i]=a[i+1]时,分成[i,i+1]\]这两种情况对答案的贡献都是0,当n为奇数时我们总会有一个没办法凑成0.#include<bits/stdc++.h>#definelsp<<1#......
  • Educational Codeforces Round 158 (Rated for Div. 2)
    A.LineTripThereisaroad,whichcanberepresentedasanumberline.Youarelocatedinthepoint\(0\)ofthenumberline,andyouwanttotravelfromthepoint\(0\)tothepoint\(x\),andbacktothepoint\(0\).Youtravelbycar,whichs......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    看到B官方题解写了一堆,而如果能注意到一些性质,几行就写完了题意:给一个A,B构成的字符串,可以将“AB”翻转成"BA",问最多可以进行多少次翻转?实际上在手动模拟以后发现,由于题目限制了每个位置只能翻转一次,所以情况简单了不少。只要还没过最后一个B,那么最后一个B之前的所有A就会被反......
  • Codeforces Round 911 (Div. 2) D
    CodeforcesRound911(Div.2)DD.SmallGCD题意定义\(f(a,b,c)\)为\(a,b,c\)中较小两个数的\(gcd\),给定数组\(a_{1...n}\),求\(\sum\limits_{i=1}^{n}\sum\limits_{j=i+1}^{n}\sum\limits_{k=j+1}^{n}f(a_i,a_j,a_k)\)题解显然可以先排序,不会影响结果,排完序后\(a_k\)就......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound7(Div.1+Div.2,Rated,Prizes!)A-JaggedSwaps思路:a2到an的数只要相邻为逆序都可以交换,只需要判断a1是否为1即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpai......
  • Codeforces Round 903 (Div. 3)
    CodeforcesRound903(Div.3)A.Don'tTrytoCount大概题意给你两个字符串a,b。a串可进行的操作为将整个a串复制到之前的a串后面(直接用a+a即可),然后看操作多少次可以让b串变为a串的子串如果不能就输出-1。#include<iostream>usingnamespacestd;stringa,b;voidsolve()......
  • Codeforces Round 894 (Div. 3)
    CodeforcesRound894(Div.3)A.GiftCarpet题意:判断一列一个字母有没有“vika”思路:挨个枚举每一列#include<bits/stdc++.h>usingnamespacestd;charmp[25][25];charx[]={'v','i','k','a'};voidsolve(){intm,n;cin>>......
  • Codeforces Round 911 (Div. 2) D. Small GCD
    题目链接:https://codeforces.com/contest/1900/problem/D对于已经排序好的数组\(a\),我们需要计算:\[\sum_{i=1}^n\sum_{j=i+1}^ngcd(a_i,a_j)*(n-j)\]由于\(\sum_{d|n}\phi(d)=n\),因此:\[\gcd(a_i,a_j)=\sum_{d|a_i,d|a_j}\psi(d)\]代入可得:\[\sum_{i=1}^n\su......