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就可以解决