Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))

这场其实有难度。(还是自己菜)

文章目录

A题

  • 思路

直接按照题意暴力,搞,但是不能只判断是否奇数或者偶数没有 c h a n g e change change 了。要全部判断 m m p mmp mmp,卡了半个小时

  • 代码(错误)
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}
int a[N];
#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
map<ll,bool> vis;

void solve()
{
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long cnt=1;
    long long ans=0;
    while(1){
        bool flag=0;
        if(cnt&1){
            for(int i=1;i<n;i+=2){
                if(a[i]>a[i+1]) {
                    swap(a[i],a[i+1]);
                    flag=1;
                }
            }
        }
        else{
            for(int i=2;i<n;i+=2){
                if(a[i]>a[i+1]){
                    swap(a[i],a[i+1]);
                    flag=1;
                }
            }
        }
        if(flag){
            ans++;
        }
        else break;
        cnt++;
    }
    cout<<ans<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}
  • AC代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}
int a[N];
#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
map<ll,bool> vis;

void solve()
{
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long cnt=1;
    long long ans=0;
    while(1){
        bool flag=0;
        for(int i=1;i<n;i++){
            if(a[i]>a[i+1]) {
                flag=1;
            }
        }
        if(cnt&1){
            for(int i=1;i<n;i+=2){
                if(a[i]>a[i+1]) {
                    swap(a[i],a[i+1]);
                    
                }
            }
        }
        else{
            for(int i=2;i<n;i+=2){
                if(a[i]>a[i+1]){
                    swap(a[i],a[i+1]);
                   
                }
            }
        }
        
        if(flag){
            ans++;
        }
        else break;
        cnt++;
    }
    cout<<ans<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}

B题

  • 思路

a a a 为较小的那一个,设 t t t = a + b 2 \frac{a+b}{2} 2a+b

①、 a + b a+b a+b 为偶数。

分别讨论

其中一个人 break的场次总共break的场次
0a-0+t-0=a+t
1a-1+t-1=a+t-2
2a-2+t-2=a+t-2*2
aa-a+t-a=t-a

②、 a + b a+b a+b 为奇数

a a a 的场次为 t t t时,和上面一样;当 a a a 的场次为 t + 1 t+1 t+1

其中一个人 break的场次总共break的场次
0a-0+t+1-0=a+t+1
1a-1+t+1-1=a+t-1
2a-2+t+1-2=a+t-3
aa-a+t+1-a=t+1-a
  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}
int a[N];
#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
map<ll,bool> vis;

void solve()
{
    int a,b;cin>>a>>b;
    // if(a==b){
    //     cout<<(a+b)/2+1<<endl;
    //     for(int i=0;i<=(a+b);i+=2){
    //         cout<<i<<" ";
    //     }
    //     cout<<endl;return;
    // }
    if(a>b) swap(a,b);
    int sum=(a+b);
    if(sum%2==0){
        cout<<a+1<<endl;
        for(int i=sum/2-a;i<=a+sum/2;i+=2){
            cout<<i<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<2*a+2<<endl;
        int tx=sum/2;
        for(int i=tx-a;i<=tx+1+a;i++){
            cout<<i<<" ";
        }
        cout<<endl;
    }
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}

C题

  • 思路

贪心搞,处理出每个洞的最小需求,然后遍历比较求出所有的最小需求

  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}
int a[N];
#define PII pair<ll,ll>
#define x first
#define y second
#define PB push_back
map<ll,bool> vis;

void solve()
{
    int n;cin>>n;
    vector<ll> vec[n+1];
    vector<PII> ans;
    for(int i=1;i<=n;i++){
        int k;cin>>k;
        for(int j=1;j<=k;j++){
            int tx;cin>>tx;
            vec[i].push_back(tx);
        }
        for(int j=k-2;j>=0;j--){
            vec[i][j]=max(vec[i][j+1]-1,vec[i][j]);
        }
        ans.push_back({vec[i][0]+1,k*1ll});
    }
    sort(ans.begin(),ans.end());
    ll anss = ans[0].x;
    ll tans = anss + ans[0].y;
    ll pat=ans[0].y;
    for(int i=1;i<ans.size();i++){
        if(tans>ans[i].x){
            tans+=ans[i].y;
        }
        else{
            anss=min(anss+ans[i].x-tans,ans[i].x-pat);
            tans=ans[i].x+ans[i].y;
        }
        pat+=ans[i].y;
    }
    cout<<anss<<endl;

}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}

D题

好像是个数论分块,加dp,稍后补上。

#include<cstdio>
const int N=2e5+10;
int n,mod;
long long ans,dp[N];
int main()
{
	scanf("%d%d",&n,&mod);
	dp[1]=1;ans=1;
	for(int i=2;i<=n;i++)
	{
		dp[i]=ans;
		for(int l=2,r;l<=i;l=r+1)
		{
			r=i/(i/l);
			dp[i]=(dp[i]+dp[i/l]*(r-l+1))%mod;
		}
		ans=(dp[i]+ans)%mod;
	}
	printf("%lld",dp[n]);
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯狂的码泰君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值