2021-10-11

Codeforces Round #750 (Div. 2)

A.Luntik and Concerts

因为a, b, c大于零,设总时间为s,所以通过1,2,3可以合成1~s中的任意一个数,本题只要考虑s的奇偶,若为 奇数,输出1,若为偶数,输出0。

// Problem: Luntik and Concerts
// Contest: Codeforces
// URL: http://m2.codeforces.com/contest/1582/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;
    LL sum = a * 1 + b * 2 + c * 3;
    if(sum % 2 == 0) puts("0");
    else puts("1");
}

int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    return 0;
}

B.Luntik and Subsequences

本题只要看0的个数和1的个数,我们可以少选任何一个1,同时选0 ~cnt0个0,cnt0是0的个数,所以答案是 1的个数乘上2^cnt0。

// Problem: Luntik and Subsequences
// Contest: Codeforces
// URL: http://m2.codeforces.com/contest/1582/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

int n;
int a[10010];

void solve()
{
	cin >> n;
	for(int i = 1; i <= n; i ++ ) cin >> a[i];
	int cnt0 = 0, cnt1 = 0;
	LL sum = 0;
	for(int i = 1; i <= n; i ++ )    
	{
		if(a[i] == 0) cnt0 ++;
		if(a[i] == 1) cnt1 ++;
		sum += a[i];
	}
	LL ans = 0;
	// if(sum == 1) ans ++;
	ans += pow(2,cnt0) * (cnt1) *1LL;
	cout << ans << endl;
	
}

int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    return 0;
}

C.Grandma Capa Knits a Scarf

本题可以暴力遍历26个英文字母,遍历的时候先把这个英文字母全删了,看他是不是回文串,如果是的话就可行,然后双指针遍历需要删除的个数,遍历26次取最小值就行。
注意ss = ss + s[i]ss += s[i] 的时间复杂度不同,因为这个TLE了好多次。

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

int n;
string s;

bool ishuiwen(string ss)
{
    for(int k = 0; k < ss.length() / 2; k ++ )
    {
        if(ss[k] != ss[ss.length() - k - 1]) return false;
    }
    return true;
}

void solve()
{
    cin >> n >> s;
    s = " " + s;
    int ans = 0x3f3f3f3f;
    for(int i = 'a'; i <= 'z'; i ++ )
    {
        string ss;
        for(int j = 1; j <= n; j ++ )
        {
            if(s[j] != i)
            {
                ss += s[j];
            }
        }
        if(ishuiwen(ss))
        {
            int cnt = 0;
            int idx1 = 1, idx2 = n;
            while(idx1 < idx2)
            {
                if(s[idx1] != s[idx2])
                {
                    cnt ++;
                    if(s[idx1] == i)   idx1 ++;
                    else idx2 --;
                }else{
                    idx1 ++;
                    idx2 --;
                }
            }
            ans = min(cnt, ans);
        }
    }
    if(ans == 0x3f3f3f3f) cout << -1 << endl;
    else cout << ans << endl;
}

int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    // system("pause");
    return 0;
}

D.Vupsen, Pupsen and 0

对于n为偶数而言,我们可以让b[i] = a[i + 1]b[i + 1] = -a[i]
对于n为奇数而言,我们可以对前n - 3个元素进行类似操作,对于后面三个进行讨论,如果后面三个和为0,则b[i]的后面三个是相同的数就行,若不为0,就找到两个和不为0的合并进行一次类似偶数的操作就行。

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

int n;
int a[100010];

void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i ++ ) cin >> a[i];
    if(n % 2 == 0){
        for(int i = 1; i <= n; i ++ )
        {
            if(i % 2 == 0) cout << a[i - 1] << " ";
            else cout << -1 * a[i + 1] << " ";
        }
        cout << endl;
    }else{
        for(int i = 1; i + 3 <= n; i ++ )
        {
            if(i % 2 == 0) cout << a[i - 1] << " ";
            else cout << -1 * a[i + 1] << " ";
        }
        int x, y;
        if(a[n - 2] + a[n - 1] + a[n] == 0){
            cout << 1 << " " << 1  << " " << 1 << endl;
            return;
        }
        if(a[n - 2] + a[n - 1] != 0)
        {
            x = a[n - 2] + a[n - 1];
            y = a[n];
            cout << y << " " << y << " "<< " " <<  -1 * x << endl;
        }else if(a[n - 1] + a[n] != 0){
            x = a[n - 1] + a[n];
            y = a[n - 2];
            cout << -1 * x << " " << y << " " << y << endl;
        }else{
            x = a[n - 2] + a[n];
            y = a[n - 1];
            cout << y << " " << -1 * x << " " << y << endl;
        }
    }
}

int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值