首页 > 其他分享 >AtCoder Beginner Contest 365

AtCoder Beginner Contest 365

时间:2024-10-01 21:03:14浏览次数:7  
标签:AtCoder typedef Beginner int long 1e9 365 dp define

A - Leap Year

思路

模拟即可;

AC代码

    #include<bits/stdc++.h>
    #define endl '\n'
    #define int int long long
    #define pb push_back
    #define bs bitset
    using namespace std;
    typedef pair<char,int> PCI;
    typedef pair<int,int> PII;
    typedef priority_queue<int> PQ;

    const int N = 2e5+10, MAX = 1e9, INF = -1e9;

    int n;

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>n;
        if(n%4!=0)cout<<365<<endl;
        else{
            if(n%100!=0)cout<<366<<endl;
            else{
                if(n%400!=0)cout<<365<<endl;
                else cout<<366<<endl;
            }
        }
        
        return 0;
    }

B - Second Best

思路

模拟即可;

AC代码

    #include<bits/stdc++.h>
    #define endl '\n'
    #define int int long long
    #define pb push_back
    #define bs bitset
    using namespace std;
    typedef pair<char,int> PCI;
    typedef pair<int,int> PII;
    typedef priority_queue<int> PQ;

    const int N = 2e5+10, MAX = 1e9, INF = -1e9;

    int n;
    PII a[N];
    int e;

    bool cmp(PII a,PII b){
        return a.first>b.first;
    }

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>n;

        for(int i=1;i<=n;i++){
            cin>>e;
            a[i].first=e;
            a[i].second=i;
        }
        sort(a+1,a+1+n,cmp);
        cout<<a[2].second<<endl;

        return 0;
    }

C - Transportation Expenses

思路

其实二分\(x\)就可以了,我还使用了前缀和,最后的复杂度是\(O(nlogn+logxlogn)\);

AC代码

    #include<bits/stdc++.h>
    #define endl '\n'
    #define int int long long
    #define pb push_back
    #define bs bitset
    using namespace std;
    typedef pair<char,int> PCI;
    typedef pair<int,int> PII;
    typedef priority_queue<int> PQ;

    const int N = 2e5+10, MAX = 1e9, INF = -1e9;

    int n,m;
    vector<int> v;
    int sum=0;
    int e;
    int s[N];

    int counts(int x){
        int p=upper_bound(v.begin(),v.end(),x)-v.begin();
        return s[p-1]+(n-p+1)*x;
    }

    int f(int l,int r){
        while(l<r){
            int mid=(l+r+1)>>1;
            if(counts(mid)<=m)l=mid;
            else r=mid-1;
        }
        return l;
    }

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>n>>m;
        v.pb(0);s[0]=0;
        for(int i=1;i<=n;i++){
            cin>>e;
            sum+=e;
            v.pb(e);
        }

        sort(v.begin(),v.end());
        for(int i=1;i<=n;i++){
            s[i]=s[i-1]+v[i];
        }

        if(sum<=m)cout<<"infinite"<<endl;
        else{
            cout<<f(1,1e9+1)<<endl;
        }

        return 0;
    }

D - AtCoder Janken 3

思路

动态规划,很简单的转移;

AC代码

#include<bits/stdc++.h>
#define endl '\n'
#define int int long long
#define pb push_back
#define bs bitset
using namespace std;
typedef pair<char,int> PCI;
typedef pair<int,int> PII;
typedef priority_queue<int> PQ;

const int N = 2e5+10, MAX = 1e9, INF = -1e9;

int n;
char c;
int dp[N][4];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    memset(dp,0,sizeof(dp));
	for(int i=1; i<=n; i++) {
		cin>>c;
		if(c=='R') {
			dp[i][1]=max(dp[i-1][2],dp[i-1][3]);
			dp[i][2]=-10086;
			dp[i][3]=max(dp[i-1][2],dp[i-1][1])+1;
		}
		if(c=='S') {
			dp[i][2]=max(dp[i-1][1],dp[i-1][3]);
			dp[i][3]=-10086;
			dp[i][1]=max(dp[i-1][2],dp[i-1][3])+1;
		}
		if(c=='P') {
			dp[i][3]=max(dp[i-1][1],dp[i-1][2]);
			dp[i][1]=-10086;
			dp[i][2]=max(dp[i-1][1],dp[i-1][3])+1;
		}
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
    return 0;
}

t.b.c.

标签:AtCoder,typedef,Beginner,int,long,1e9,365,dp,define
From: https://www.cnblogs.com/oaths/p/18443303

相关文章

  • 题解:AtCoder Beginner Contest AT_abc373_d ABC373D Hidden Weights(格式美化版)
    题目传送门题目翻译给你一个NNN个点,MMM条边的有向图,其中边有边......
  • AtCoder Beginner Contest 365题解
    A-LeapYear按照题意模拟即可。codeB-SecondBest按照题意模拟即可。codeC-TransportationExpenses考虑当\(x\)增大时,\(\min(x,a_i)=x\)的项会越来越少。换言之,当\(x\)足够大时,\(ans=\suma_i\),若此时\(ans>M\)则说明无论补贴多少,这时答案都是一定的......
  • AtCoder Beginner Contest 371(ABCDE)
    A个人直接硬解,讨论情况也并不复杂代码:#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=1e6+10;voidsolve(){chara,b,c;cin>>a>>b>>c;if(a=='<'){if(c=='<......
  • 转载 https://blog.csdn.net/h1773655323/article/details/142098658#:~:text=%E7%94%
    在Ubuntu20.04上安装Python3.12:详细教程写bug如流水于2024-09-1014:41:34发布阅读量837收藏11点赞数4分类专栏:Python文章标签:ubuntupythonlinux版权Python专栏收录该内容53篇文章7订阅订阅专栏今天这篇文章将指导您如何在Ubuntu20.04上安装Python3.12......
  • 题解:AtCoder Beginner Contest AT_abc373_d ABC373D Hidden Weights
    题目传送门题目翻译给你一个NNN个点,MMM条边的有向图,其中边有边......
  • 腾讯企业邮箱(企业微信邮箱)迁移到microsoft 365(office 365)
    1.迁移前准备(腾讯企业邮箱)1.如果你是企业管理员,首先看一下企业邮箱后台,是否已关闭登陆安全2.登录要迁移的个人邮箱后台,关闭安全登录、开启IMAP服务和相关选项,以及为邮箱设置一个密码 2.开始迁移1.登录microsoft365管理后台(https://admin.exchange.micro......
  • 「比赛记录」AtCoder abc373 (9.28)
    CTH想看F题解,于是先发出来F.KnapsackwithDiminishingValues属于是翻译官方题解了首先我们设\(dp_{w,j}\)表示从权重为\(w\)或更小的物品中选总重为\(j\)的物品可以得到的最大幸福度。考虑\(dp\)的转移。我们把所有物品按照权重\(w\)分为多组,(每一组中所有物品......
  • O365和Keycloak结合SSO实现
    背景内部用keycloak实现SSO,近期引入了Office365,需要接入keycloak(saml协议),实现SSO。遇到的问题Office365按照官方文档配置后,负责keycloak的同学帮着调试好后,sso总是提示失败。总是提示找不到用户。按照官方文档https://learn.microsoft.com/en-us/entra/identity/hybrid/con......
  • AtCoder Beginner Contest 373
    这场咋这么简单A.September\(\text{diff11}\)给你\(12\)个字符串\(S_1\)到\(S_{12}\),问你有多少字符串满足\(|S_i|=i\)点击查看代码usingnamespacereader;strings[13];intmain(){ for(inti=1;i<=12;++i){ cin>>s[i]; } intans=0; for(inti=1;i<=12......
  • AtCoder Beginner Contest 373
    A-September题意给\(12\)个字符串,问长度等于标号的字符串个数。思路模拟。代码点击查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintmxn=1e6+5;voidsolve(){ intans=0; for(inti=0;i<12;i++) { ......