• 暑假算法训练day2


    C. Coin Rows

    Alice 和 Bob 在一个 2 × m 2 \times m 2×m 的矩形上玩游戏,矩形的每一个格子上都有一个数 a i , j a_{i,j} ai,j
    Alice 和 Bob 一开始站在左上角格子 (1,1) 上,每个人都只能向下或者向右移动,直到移动到终点 (2,m) 上,经过一个格子时会取走格子上的数,赢得相应的得分
    Alice 首先开始移动,Bob 不能取走 Alice 已经取走的数
    Alice 期望最小化 Bob 的得分,Bob 则希望最大化自己的得分
    请输出 Bob 的最大得分
    思路:
    在这里插入图片描述
    枚举每一列作为Alice向下走的那一步,那么Bob的得分只能是右上角和左下角Alice并未走过的分数,对每个Alice向下走的 i i i ,求出Bob两种方式 m a x max max,再对所有 m a x max max m i n min min

    #include <bits/stdc++.h>
    using namespace std;
    const double pi = acos(-1.0);
    #define x first
    #define y second
    #define LL long long 
    #define int LL
    #define pb push_back
    #define all(v) (v).begin(),(v).end()
    #define PII pair<int,int>
    #define ll_INF 0x7f7f7f7f7f7f7f7f
    #define INF 0x3f3f3f3f
    #define debug(x) cerr << #x << ": " << x << endl
    #define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
    LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
    LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
    LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
    int _;
    int n;
    const int N=1e5+10;
    int a[3][N];
    int s[3][N];
    void solve()
    {
    	cin>>n;
    	for(int i=1;i<=2;i++)
    		for(int j=1;j<=n;j++)
    			cin>>a[i][j];
    	for(int i=1;i<=2;i++)
    	{
    		for(int j=1;j<=n;j++)
    		{
    			s[i][j]=s[i][j-1]+a[i][j];
    		}
    	}
    	int res=ll_INF;
    	for(int i=1;i<=n;i++)
    	{
    		int maxv=max(s[1][n]-s[1][i],s[2][i-1]);
    		res=min(res,maxv);
    	}
    	cout<<res<<endl;
    }
    signed main()
    {
        io;
     	cin>>_; 
     	while(_--)
        solve();
        return 0;
    }
    
    • 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

    D. Co-growing Sequence

    题目描述:

    思路:
    字典序最小,那么 b 1 = 0 b_1=0 b1=0,对于一个满足题意的数组,二进制下所有 a i − 1 X O R b i − 1 a_{i-1}XORb_{i-1} ai1XORbi1中的 1 1 1 a i X O R b i a_{i}XORb_{i} aiXORbi也得有,那么 b i b_i bi就是把没有补齐的 1 1 1补齐

    #include <bits/stdc++.h>
    using namespace std;
    const double pi = acos(-1.0);
    #define x first
    #define y second
    #define LL long long 
    #define int LL
    #define pb push_back
    #define all(v) (v).begin(),(v).end()
    #define PII pair<int,int>
    #define ll_INF 0x7f7f7f7f7f7f7f7f
    #define INF 0x3f3f3f3f
    #define debug(x) cerr << #x << ": " << x << endl
    #define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
    LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
    LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
    LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
    int _;
    int n;
    const int N=2e5+10;
    int a[N];
    int b[N];
    void solve()
    {
    	cin>>n;
    	int now;
    	for(int i=1;i<=n;i++)cin>>a[i];
    	for(int i=2;i<=n;i++)
    	{
    		int t=a[i];
    		now=a[i]|a[i-1];
    		b[i]=now-t;
    		a[i]^=b[i];
    	}
    	for(int i=1;i<=n;i++)cout<<b[i]<<' ';
    	cout<<endl;
    }
    signed main()
    {
        io;
     	cin>>_; 
     	while(_--)
        solve();
        return 0;
    }
    
    • 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
  • 相关阅读:
    OpenCV:解锁计算机视觉的魔法钥匙
    满足开闭原则的JDBCUtils~
    用js理解常用设计模式
    linux之/etc/skel目录
    电脑电源灯一闪一闪开不了机怎么办
    若依vue ruoyi-vue ant design版本使用
    LeetCode 731. My Calendar II【设计,有序映射,差分;线段树】中等
    linux parted 方式挂盘,支持大于4T盘扩容
    前端周刊第三十四期
    基于Java星空游戏购买下载平台设计实现(源码+lw+部署文档+讲解等)
  • 原文地址:https://blog.csdn.net/qq_52765554/article/details/125454242