Codeforces Round #750 (Div. 2) 记录

Codeforces Round #750 (Div. 2) 记录

A.Luntik and Concerts

  • 思路
  • 经验教训
  • AC代码
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
#include <list>
#include <numeric>

#define int long long
using namespace std;
typedef long long ll;
//const int maxn = 1e6 + 5;
//int a[maxn];
//int b[maxn];


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int t;cin>>t;
    for (int i = 0; i < t; ++i) {
        int a,b,c;cin>>a>>b>>c;
        int sum = a+b*2+c*3;
        sum%2==0?cout<<0<<'\n':cout<<1<<'\n';
    }

}

B.Luntik and Subsequences

  • 思路

    • 手画一下,可以很容易发现题意所求子序列个数只跟0与1有关
    • 再手画一下可以发现0,1满足的数量关系
  • 经验教训

    • 2^60 数量级如果直接 1<<60会溢出,应该采用**(ll)1<<60**,或者pow(2,60)
  • AC代码

#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
#include <list>
#include <numeric>

#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
int a[maxn];
int b[maxn];

int ari_seq(int n){
    return (1+n)*n/2;
}
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int t;cin>>t;
    for (int i = 0; i < t; ++i) {
        int n;cin>>n;
        int cnt1 = 0,cnt0 = 0;
        for (int j = 0; j < n; ++j) {
            int x;
            cin>>x;
            if (x==1) cnt1++;
            else if (x==0) cnt0++;
        }
        int k = (ll)1<<cnt0;
        cout<<k*cnt1<<'\n';

    }

}

C.Grandma Capa Knits a Scarf

  • 思路
    • 遍历小写的a到小写的z,看看能不能如果只删除该字母能否构成回文串,如果可以最少需要删除多少个字母
    • 每一次遍历ans = min(ans,cnt)(ans初始取一个很大的数)
  • 经验教训
    • 判断时间复杂度!遍历a到z其实只是o(26n),完全合法,自己最开始想着遇到第一个不相同字母才决定取哪个字母作为symbol,但那样就很复杂,需要一堆奇怪的判断,直接遍历非常省事!
  • AC代码
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
#include <list>
#include <numeric>

#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
int a[maxn];
int b[maxn];

int ari_seq(int n) {
    return (1 + n) * n / 2;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        int n;
        string s;
        cin >> n >> s;

        char symbol = '.';
        int can_or_not = 0;
        int ans = 1e8;
        for (char j = 'a'; j <= 'z'; ++j) {
            int left = 0, right = s.size() - 1;
            int cnt = 0;
            int flag = 0; // flag=0就是可以成为回文串,flag=1就是不能成为回文串
            while (left <= right) {
                if (s[left] != s[right]) {
                    while (s[left] != s[right]) {
                        if (s[left] == j) {
                            left++;
                            cnt++;
                        }
                        else if (s[right] == j) {
                            right--;
                            cnt++;
                        } else{
                            flag = 1;
                            break;
                        }
                    }
                } else{
                    left++;right--;
                }
                if (flag==1) break;
            }
            if (!flag) ans = min(cnt,ans);
        }
        if (ans==1e8) cout<<-1<<'\n';
        else cout<<ans<<'\n';
    }

}

D.Vupsen, Pupsen and 0

  • 思路

    • 如果总数为偶数个,直接交叉取反
    • 如果总数为奇数个,想让前三个乘积和为0,再交叉取反
    • 为什么需要3个if?为了防止某两项之和为0(不可能三项两两之和都为0)
  • 经验教训

  • AC代码

    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <vector>
    #include <set>
    #include <cmath>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <cstring>
    #include <list>
    #include <numeric>
    
    #define int long long
    using namespace std;
    typedef long long ll;
    const int maxn = 1e5 + 5;
    int a[maxn];
    int b[maxn];
    
    int ari_seq(int n) {
        return (1 + n) * n / 2;
    }
    
    signed main() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        std::cout.tie(0);
        int t;
        cin >> t;
        for (int i = 0; i < t; ++i) {
            int n;
            cin >> n;
            for (int j = 0; j < n; ++j) {
                cin >> a[j];
            }
            if (n % 2 == 0) {
                for (int j = 0; j < n; ++j) {
                    if (j % 2 == 0) cout << a[j + 1] << " ";
                    else cout << -a[j - 1] << " ";
                }
            } else {
                if ((a[0] + a[1]) != 0) {
                    cout<<a[2]<<" "<<a[2]<<" "<<-(a[0]+a[1])<<" ";
                } else if ((a[1] + a[2]) != 0) {
                    cout<<-(a[1]+a[2])<<" "<<a[0]<<" "<<a[0]<<" ";
                } else if ((a[0] + a[2]) != 0) {
                    cout<<a[1]<<" "<<-(a[0]+a[2])<<" "<<a[1]<<" ";
                }
                for (int j = 3; j < n; ++j) {
                    if (j % 2 != 0) cout << a[j + 1] << " ";
                    else cout << -a[j - 1] << " ";
                }
            }
            cout<<'\n';
        }
    
    }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值