首页 > 其他分享 >【LGR-200-Div.4】洛谷入门赛 #27 A-H题解

【LGR-200-Div.4】洛谷入门赛 #27 A-H题解

时间:2024-09-14 22:48:42浏览次数:1  
标签:__ 200 typedef 27 int 题解 cin long define

A

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        if(c+d>a+b) cout << "Yes";
        else cout << "No";
    }
    system("color 04");
    return 0;
}

B

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        int t,t1,t2,d,d1,d2;
        cin >> t >> d >> t1 >> d1 >> t2 >> d2;
        int ans=inf;
        if(d1>=d){
            ans=max(0ll,t1-t);
        }
        if(d2>=d){
            ans=min(ans,max(0ll,t2-t));
        }
        cout << (ans==inf?-1:ans) << '\n';
    }
    system("color 04");
    return 0;
}

C

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        int n;
        double m;
        cin >> n >> m;
        int ans=inf;
        auto get=[&](int l,int r)->int{
            return (r-l+1)*(l+r)/2;
        };
        int sum=get(1,n);
        auto check=[&](int i)->bool{
            return 100.0*i/sum>=m;
        };
        int l=1,r=n+1;
        while(l<r){
            int mid=l+r>>1;
            if(check(mid)) r=mid;
            else l=mid+1;
        }
        cout << (l<=n?l:-1) << '\n';
    }
    system("color 04");
    return 0;
}

D

注意r范围,至少需要开到2e6,也不能太大

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        int x,y,w,k;
        cin >> x >> y >> w >> k;
        auto check=[&](int t)->bool{
            int ans=0;
            for(int i=1;i<=t;i++){
                ans+=i/w;
            }
            if(t>=x){
                ans+=(t-x+1)*y;
            }
            return ans>=k;
        };
        int l=0,r=5e6;
        while(l<r){
            int mid=l+r>>1;
            if(check(mid)) r=mid;
            else l=mid+1;
        }
        cout << l << '\n';
    }
    system("color 04");
    return 0;
}

E

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        int n,m;
        cin >> n >> m;
        vector<vector<int>> p(n+1,vector<int>(n+1));
        while(m--){
            int op,a,b,c;
            cin >> op >> a >> b >> c;
            if(op==1){
                p[a][b]+=c;
            }
            else p[a][b]-=c;
            int ans=0;
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    ans=max(ans,p[i][j]);
                }
            }
            cout << ans << '\n';
        }
    }
    system("color 04");
    return 0;
}

F

考虑第i个字母\(a_i\)可以和前面i-1个字母哪些可以构成好的子串,显然是前i-1个字母中\(a_i\)的个数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        string s;
        cin >> s;
        int n=s.size();
        int ans=0;
        map<char,int> cnt;
        for(int i=0;i<n;i++){
            ans+=cnt[s[i]];
            cnt[s[i]]++;
        }
        cout << ans+n << '\n';
    }
    system("color 04");
    return 0;
}

G

n位的数字找到p的倍数,如果n*9<p则,不可能找到p的倍数,则直接输出最小的n位整数即1个1,n-1个0,反之,从后到前依次填p,如果说\(1<=p<=9\),则直接填p,否则填9,因为不能包含前导0,判断一下第一位是不是为0,如果为0,则将这一位变成1,然后从小到大找到\(ans[i]!=0\)的位置index,使得ans[index]--

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        int n,p;
        cin >> n >> p;
        if(n*9<p){
            cout << 1 ;
            for(int i=1;i<n;i++) cout << 0;
            continue;
        }
        vector<int> ans(n+1);
        for(int i=n;i>=1;i--){
            if(p>=0&&p<=9){
                ans[i]=p;
                p=0;
            }
            else ans[i]=9,p-=9;
        }
        if(!ans[1]){
            ans[1]=1;
            for(int i=2;i<=n;i++){
                if(ans[i]){
                    ans[i]--;
                    break;
                }
            }
        }
        for(int i=1;i<=n;i++) cout << ans[i];
    }
    system("color 04");
    return 0;
}

H

计算出一开始\(a>b\)的数量cnt1,\(a<b\)的数量cnt2,则相等的元素有\(d=n-cnt1-cnt2\),分情况讨论,如果\(cnt1>cnt2\),则直接输出0,如果\(cnt1<=cnt2\),优先使\(ai==bi\)的\(ai\)增加1,这样贡献是1,定义\(now=cnt2-cnt1+1\)为cnt1>cnt2需要更改的平局数,如果\(now<=d\)则直接输出now,否则,将\(ai<bi\)的所有位置记录下来,并记录将\(ai>bi\)需要的最小值为多少,进行排序。如果说当cnt1==cnt2时,我们只需要将ai等于bi即可以使得cnt2--,从则满足\(cnt1>cnt2\)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll  P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
    return rand()%r+l;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int __=1;
//    cin >> __;
    while(__--){
        int n;
        cin >> n;
        vector<int> a(n+1),b(n+1);
        for(int i=1;i<=n;i++) cin >> a[i];
        for(int i=1;i<=n;i++) cin >> b[i];
        int cnt1=0,cnt2=0;
        for(int i=1;i<=n;i++){
            if(a[i]>b[i]) cnt1++;
            else if(a[i]<b[i]) cnt2++;
        }
        if(cnt1>cnt2){
            cout << 0 << '\n';
        }
        else{
            int d=(n-cnt2-cnt1); //平局数
            int now=cnt2-cnt1+1;
            if(now<=d){
                cout << now << '\n';
            }
            else{
                vector<int> c;
                for(int i=1;i<=n;i++){
                    if(a[i]<b[i]) c.push_back(b[i]-a[i]+1);
                }
                ranges::sort(c);
                cnt1+=d;
                int i=0,ans=d;
                while(cnt1<=cnt2){
                    if(cnt1==cnt2){
                        ans+=c[i++]-1;
                        break;
                    }
                    ans+=c[i++];
                    cnt1++;
                    cnt2--;
                }
                cout << ans << '\n';
            }
        }
    }
    system("color 04");
    return 0;
}

标签:__,200,typedef,27,int,题解,cin,long,define
From: https://www.cnblogs.com/stability/p/18414786

相关文章

  • 题解 [ABC371G] Lexicographically Smallest Permutation(中文/English)
    本题解提供英文版,位于示例代码之后。Englishversionofthiseditorialisprovidedafterthesamplecode.官方题解竟然用Python来算高精度lcm,我来提供一个可以避免一切大整数运算的方法。考察\(u\getsP_u\)这张图的每个置换环。为了使答案字典序最小,显然需要从前往后......
  • MAST20018 – Discrete Mathematics and Operations Research
    MAST20018 – Discrete Mathematics and Operations ResearchAssignment 3Upload to Gradescope by 5pm Wed 18th September 2024Question 1In assignment 1, you considered the following project with 8 activities, labelled A to H:......
  • MAST20029 Engineering Mathematics
    MAST20029EngineeringMathematics,Semester22024Assignment2SubmitasinglepdffileofyourassignmentontheMAST20029websitebefore9amonMonday16thSeptember.•Thisassignmentisworth5%ofyourfinalMAST20029mark.•Assignmentsmustbenea......
  • MAST20004 Probability
    MAST20004ProbabilitySemester2,2024Assignment3:QuestionsDue4pm,Wednesday18SeptemberImportantinstructions:(1)Thisassignmentcontains4questions,twoofwhichwillberandomlyselectedtobemarked.Eachmarkedquestionisworth10points......
  • 国考排名上升超200名!广医四院数字化升级推动运营与效益双飞跃
    广州医科大学附属第四医院(以下简称广医四院),始建于1949年,是一所集医疗、教学、科研、预防、保健、康复为一体的三级综合性医院,是增城区规模最大、综合实力最强的公立医院。近年来,随着基础建设的不断完善,学科和专科发展持续加强,人才队伍结构不断优化,科研教学工作稳步推进,广医四院实现......
  • P9891 [ICPC2018 Qingdao R] Repair the Artwork 题解
    所求即为选择的区间恰好包含所有\(a_i=2\)的位置的方案数。设所有\(a_i=2\)的位置\(i\)组成集合\(S\),考虑容斥被选中的位置是\(S\)的子集的方案数\(g(S)\)。设\(T\)为\(S\)的子集,\(T\)的贡献\(f(T)\)为:选中的位置都在\(T\)的子集中的方案数乘容斥系数\(......
  • P2294 [HNOI2005] 狡猾的商人 两种做法
    贪心#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=1e3+100;intn,m;structNODE{ intl,r,val; booloperator<(constNODE&h)const { if(l!=h.l) returnl>h.l; returnr>h.r; }};priority_queue......
  • GEE :利用MODIS土地分类数据监测指定区域2001-2024年农作物的时序面积
    目录简介数据函数ee.Image.pixelArea()Noarguments.Returns: Image代码结果简介利用MODIS土地分类数据监测指定区域2001-2024年农作物的时序面积数据MODIS/061/MCD12Q1是一个由美国国家航空航天局(NASA)和美国地质调查局(USGS)联合开发的遥感数据产品。它是MODIS(M......
  • [题解]CF542A Place Your Ad Here
    思路首先因为电视台比广告多一个信息,所以通常来说枚举电视台是更有前途的。因此枚举每一个电视台,考虑所有广告的贡献。对于一个电视台,\(c_i\)是定值,也就是找到所有广告与电视台所表示区间交得最多的那一个。假设枚举的电视台控制了\([L,R]\)区间,则广告\([l,r]\)会有三种方......
  • Luogu P10179 水影若深蓝 题解 [ 绿 ] [ 并查集 ] [ 构造 ]
    水影若深蓝:挺好的一道并查集构造题。观察不难发现“距离为\(2\)”这个条件我们可以通过黑白染色实现,我们把他们的中转点染成与他们相反的颜色,把这两个距离为\(2\)的点染成相同颜色。这个染色问题就很并查集。于是我们用并查集维护相同的种类。显然,当图上只有一个连通块的......