Toyota Programming Contest 2024#8(AtCoder Beginner Contest 365)A-D

Toyota Programming Contest 2024#8(AtCoder Beginner Contest 365) - AtCoder

A:Leap Year


思路:

直接枚举判断就可以

#include<bits/stdc++.h>
using namespace std;

#define fir first
#define sec second
#define endl "\n"   

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const int N = 1e5 + 10, M = N * 2, mod = 1e9 + 7, inf = 0x3f3f3f3f, P = 131;

void solve()
{
    int y;
    cin >> y;
    if(y%4!=0) cout<<365;
    else if(y%4==0 && y%100!=0) cout<<366;
    else if(y%100==0 && y%400!=0) cout<<365;
    else cout<<366;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while(t --)
        solve();

    return 0;
}

B:Second Best




思路:

这个是让输出第二大值的位置,而不是第二大的值。直接结构体排序就可以
 

#include<bits/stdc++.h>
using namespace std;

#define fir first
#define sec second
#define endl "\n"   

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const int N = 110, M = N * 2, mod = 1e9 + 7, inf = 0x3f3f3f3f, P = 131;

struct Node{
    int id;
    int x;
}a[N];
bool cmp(Node b,Node c){
    return b.x<c.x;
}
void solve()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i].x;
        a[i].id=i;
    }
    sort(a+1,a+1+n,cmp);
    cout<<a[n-1].id;

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while(t --)
        solve();

    return 0;
}

C:Transportation Expenses 


思路:

经典二分答案

#include<bits/stdc++.h>
using namespace std;

#define fir first
#define sec second
#define endl "\n"   

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const int N = 2e5+10, M = N * 2, mod = 1e9 + 7, inf = 0x3f3f3f3f, P = 131;
ll a[N];
ll sum1,sum,n,m;
void solve()
{
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        sum1+=a[i];
    }
        ll l=0,r=m;
        while(l<r){
            ll mid=(l+r)/2;
            for(int i=1;i<=n;i++){
                sum+=min(mid,a[i]);
            }
            if(sum<=m) l=mid+1;
            else r=mid;
            sum=0;
        }
        if(sum1<=m) cout<<"infinite";
        else cout<<r-1;

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while(t --)
        solve();

    return 0;
}

D:一个DP就可以解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值