abc365整理

A-AC

判断闰年,闰年输出: 366 366 366

否则输出: 365 365 365

code:

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long

const int P = 998244353;
const int Base = 3221225477;
const int INF = 0x3f3f3f3f3f3f3f3f;

const int N = 1e6 + 10, M = 2e6 + 10;

signed main()
{
	int n;
    cin >> n;
    if(n % 4 == 0 && n % 100 != 0 || n % 400 == 0 && n % 3200!= 0)
    {
    	cout <<"366";
	}
	else
	{
		cout <<"365";
	}
	return 0;
}

B-AC

求次大值在数组的第几位

操,屌丝翻译让我错了 2 2 2

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long

const int P = 998244353; 
const int INF = 0x3f3f3f3f3f3f3f3f; 

const int N = 1e6 + 10, M = 2e6 + 10; 
int a[N], b[N];
signed main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n;i ++)
	{
		cin >> a[i];
		b[i] = a[i];
	}

	sort(a + 1, a+n+1);
	int maxx = a[n-1];

	for(int i = 1; i <= n; i++)
	{
		if(maxx == b[i])
		{
			cout << i;
			return 0;
		}
	}
	return 0;
}




C

二分查找做🤣🤣🤣

如果一个地方合法,那他以下的都合法,上面的不合法

找到合法和不合法的分界点,找到那个范围( x ∼ y x \sim y xy

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long

const int P = 998244353; 
const int Base = 2281701377;
const int INF = 0x3f3f3f3f3f3f3f3f; 

const int N = 1e6 + 10, M = 2e6 + 10; 

int n, m;
int a[N];
int sum;
int ans;

int l, r;

bool check(int mid)
{
    int res = 0;
    for(int i=1; i<=n; i++)
    {
        res += min(a[i], mid);
    }
    return res <= m;
}

signed main()
{
    cin >> n >> m;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        sum += a[i];
        r = max(r, a[i]);
    }
    if(sum <= m)
    {
        cout << "infinite";
        return 0;
    }
    while(l <= r)
    {
        int mid = (l + r) / 2;
        if(check(mid))
        {
            ans = mid;
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    cout << ans;
	return 0;
}


D

动态规划( D P DP DP)做👈

题意:

你知道对方的出拳规律 ,我们可以赢几局

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long

const int P = 998244353; 
const int Base = 2281701377;
const int INF = 0x3f3f3f3f3f3f3f3f; 

const int N = 1e6 + 10, M = 2e6 + 10; 

int n;
char a[N];

int f[N][3];

signed main()
{
    cin >> n;
    cin >> a + 1;
    for(int i  = 1; i <= n; i++)
    {
        if(a[i] == 'R')
        {
            f[i][0] = max(f[i-1][1], f[i-1][2]);
            f[i][1] = max(f[i-1][0], f[i-1][2]) + 1;
        }
        if(a[i] == 'P')
        {
            f[i][1] = max(f[i-1][0], f[i-1][2]);
            f[i][2] = max(f[i-1][0], f[i-1][1]) + 1;
        }
        if(a[i] == 'S')
        {
            f[i][2] = max(f[i-1][1], f[i-1][0]);
            f[i][0] = max(f[i-1][1], f[i-1][2]) + 1;
        }
    }
    cout << max(max(f[n][0],f[n][1]), f[n][2]);
	return 0;
}
  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值