• Good Bye 2019


    A.Card Game

    题目大意:两个人都有共有n张卡牌,每张卡牌上都有一个数xi,没有两张牌上的数相同,且xi不小于1不大于n。每次两个人选出一张牌来,牌上数字大的人赢得此局,如果谁最后手上拥有所有的n张牌,那么他取得胜利。

    分析:只要判断数字为n的牌在谁的手里即可。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int t,n,k1,k2,x;
        cin>>t;
        while(t--){
            cin>>n>>k1>>k2;
            int f = 0;
            for(int i=0;i<k1;i++){
                cin>>x;
                if(x==n) f=1;
            }
            for(int i=0;i<k2;i++){
                cin>>x;
                if(x==n) f=2;
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        return 0;
    }

    B.Interesting Subarray

    题目大意:问你是否能找到一个连续子序列,使得这段子序列里最大值减最小值大于等于这段子序列的长度。

    分析:只用比较相邻的两个数即可。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=2e5+7;
    int a[maxn];
    int main() {
        int t, n;
        cin >> t;
        while (t--) {
            cin >> n;
            for (int i = 1; i <= n; i++)
                cin >> a[i];
            bool f = false;
            int l = -1, r = -1;
            for (int i = 1; i <= n - 1; i++) {
                if (abs(a[i] - a[i + 1]) >= 2) {
                    f = true;
                    l = i;
                    r = i + 1;
                }
            }
            if (f) {
                cout << "YES" << endl;
                cout << l << " " << r << endl;
            } else {
                cout << "NO" << endl;
            }
        }
        return 0;
    }

    C. Make Good

    题目大意:让你再找几个ai,使得a1+a2+...+an=2*(a1^a2^...^an)。

    分析:就直接构造一个最简单的方法出来就行了,因为添加的元素个数没有限制到最少。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+7;
    typedef long long ll;
    ll a[maxn];
    int main() {
        int t, n;
        cin >> t;
        while (t--) {
            cin >> n;
            for (int i = 1; i <= n; i++)
                cin >> a[i];
            ll l = a[1], r = a[1];
            for (int i = 2; i <= n; i++) {
                l += a[i];
                r ^= a[i];
            }
            //l+x/2 = 2*(r^x)   2*l+x=4*(r^x)
            //1/2*l+x/4 = r^x
            cout << 2 << endl;
            cout << r << " " << l + r << endl;
        }
        return 0;
    }
  • 相关阅读:
    python字符串操作
    python学习【一】基础入门
    markdown 编辑器
    jenkins学习笔记-安装
    算法
    python 修改文件内容
    python基础,python第四课
    python基础,python第三课
    python基础,python第二课
    python基础,python第一课
  • 原文地址:https://www.cnblogs.com/SwiftAC/p/12118098.html
Copyright © 2020-2023  润新知