当前位置:   article > 正文

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

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();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 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();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71

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();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

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();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/55109
推荐阅读
相关标签
  

闽ICP备14008679号