首页 > 其他分享 >Codeforces Round #814 (Div. 2)

Codeforces Round #814 (Div. 2)

时间:2022-12-25 19:34:56浏览次数:38  
标签:10 typedef int Codeforces long solve Div include 814

A

核心思路:这题没什么好说的直接面向样例编程。

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
int mod = 1e9 + 7;
const int N = 1e3+10;
void solve()
{
    LL n, m;
    cin >> n >> m;
    if ((n + m) % 2)
        cout << "Burenka" << endl;
    else
        cout << "Tonya" << endl;
}
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    
}

B

核心思路:咋一看这一题不知道怎么入手其实不需要慌我们先从最基本的情况入手。

我们其实可以从样例中发现一个很重要的规律:那就是我们构造的数对都是相差为1的奇偶数。

我们需要的是\((a+k)*b|4\).我们可以先列举最基本的情况:

k=1时
(1+1)*2=4
(3+1)*4=12
(5+1)*6=24

所以我们可以使用数学归纳法:k为奇数的时候,肯定是有解的。解就是那个数对

然后再来判断k为偶数的时候怎么办呢,什么时候有解,什么时候无解呢。

从样例知道10是有解的,所以我们来看他为什么是有解的.

其实很大的原因就是\((2+2+8)*3|4\),这是因为我们第一个凑出来的偶数已经很大了,所以即使后面是奇数也可以被整除。所以我们只需要保证k%4=2,那么我们肯定是可以凑出来4的倍数的,因为偶数最小也是2。

所以这道题就迎刃而解了。

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
int mod = 1e9 + 7;
const int N = 1e3+10;
void solve()
{
    int n, k;
    cin >> n >> k;
    if (k % 2)
    {
        cout << "YES" << endl;
        for (int i = 1;i <= n;i += 2)
        {
            cout << i << " " << i + 1 << endl;
        }
    }
    else if (k % 4 == 2)
    {
        cout << "YES" << endl;
        for (int i = 1;i <= n;i += 2)
        {
            if (i % 4==1)
            {
                cout << i + 1 << " " << i << endl;
            }
            else
                cout << i << " " << i + 1 << endl;
        }
    }
    else
        cout << "NO" << endl;
}
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    
}

C

核心思路:这里我们发掘一个很重要的性质:在a数组最大的数的后面的元素是怎么都不可以赢的。所以我们的回合可以定位在最大数的前面,因为最大数后面的回合都是他自己赢。这里的a数组中的元素是\(1\sim n\)哦。

有了这个思路之后,接下来该想着怎么去模拟呢。其实有个很烦的地方是那个询问,因为他问的是某个人在某个回合前赢的次数。所以我们采取离线询问,就是先把这个询问使用数组存起来,在逐渐访问。所以我们设置这个离线数组是有讲究的。我们开一个结构体使用两个变量来记录第几个访问和访问的人的编号.在使用ans来存储我们最终的答案。

知道这些细节就好做了.

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
int mod = 1e9 + 7;
const int N = 1e6+10;
int n, m, a[N];
struct Node
{
	int p, id;
};
vector<Node> v[N];
int ans[N], cnt[N];

void solve()
{
    cin >> n >> m;
    int pos = 0;

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] == n) pos = i;
        cnt[i] = 0;
        v[i].clear();
    }
    int round = max(0, pos - 2);
    for (int i = 1; i <= m; i++)
    {
        ans[i] = 0;
        int p, k;
        cin >> p >> k;
        if (k <= round)
            v[k].push_back({ p, i });
        else if (p != pos) k = round, v[k].push_back({ p, i });
        else if (p == pos)
        {
            ans[i] += k - round;//后面都是他赢.
            k = round, v[k].push_back({ p, i });
        }
    }

    int winner = 1;
    for (int i = 2; i <= round + 1; i++)
    {
        int time = i - 1;
        if (a[i] > a[winner])
        {
            winner = i;
            cnt[i] ++;
        }
        else cnt[winner] ++;

        for (auto it : v[time])
        {
            ans[it.id] += cnt[it.p];
        }
    }
    for (int i = 1; i <= m; i++)
        cout << ans[i] << endl;
}
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		solve();
	}
}

D

核心思路:这个主要是在与发现一个很重要的性质:如果一个区间的异或和是0,那么这个区间只需要进行len-1次操作就可以变成相同。这个是为什么呢,因为直接第一个第一个数异或上第二个然后一直异或上去就好了。

集合定义:\(dp[i]为以i结尾的序列需要操作的次数\)

集合划分:

  • 存在一个点j,[i,j]的区间异或和是0,那么这个状态就可以转移到dp[i]
  • 直接对a[i]这个点操作,所以dp[i-1]可以转移过来.(其实就是选不选对a[i]操作)
#include <bits/stdc++.h>
#define fi first    
#define se second    
#define endl '\n'
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
typedef long long LL;
using namespace std;
const int N = 1e5 + 10,M = N*2;
   
void solve() {
    int n;cin>>n;
    vector<int> a(n+1),dp(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    map<int,int> mp;
    mp[0] = 0;dp[0] = 0;
    for(int i=1;i<=n;i++)
    {
        a[i] ^= a[i-1];
        dp[i] = dp[i-1] + 1;
        if(mp.count(a[i])) dp[i] = min(dp[i],dp[mp[a[i]]]+i-mp[a[i]]-1);
        mp[a[i]] = i;
    }
    cout<<dp[n]<<'\n';
}
 
int main() 
{
    ios;
    int T=1;
    cin>>T;
 
    while(T -- ) {
        solve();
    }
 
    return 0;
}

标签:10,typedef,int,Codeforces,long,solve,Div,include,814
From: https://www.cnblogs.com/xyh-hnust666/p/17004425.html

相关文章

  • Codeforces Round #586 (Div. 1 + Div. 2) D
    D.AlexandJulian题链很容易发现我们要是两个数互相不构成奇环的话=(a+b)/gcd(a,b)为偶数我们发现如果ab为奇数的时候一定可以并且奇偶一定不同组但是发现24这种又......
  • Educational Codeforces Round 122 (Rated for Div. 2),C,D
    EducationalCodeforcesRound122(RatedforDiv.2),C,DCC这道题就是普通的暴力,但是我在做的过程中第10组数据出现了数据溢出的错误我的错误代码,我在vp的时候没觉得......
  • Codeforces Round #589 (Div. 2) D
    D.CompleteTripartite题链与其他题解不同我首先发现的是没有相连的一定是同一组那么我们直接对于整个数组遍历一遍将与1同组的搞出来要是下一个位置已经有组了我......
  • POJ 1014 Dividing
    POJ1014Dividing题意:多重背包问题,给出若干物品,求是否能分成价值相同的两堆思考:求出总和\(sum\)之后,如果\(sum\)是奇数则一定不可能,然后如果我们能凑出\(sum/......
  • Codeforces Round #770 (Div. 2)B,C
    CodeforcesRound#770(Div.2)B,C还是惨绝人寰的只做了一个题,ε=(´ο`*)))唉BB这一道题大意是是首先有一个d,然后有n个操作,从1到n,每一次我们都需要选择让d=d+a[i]还是d......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • 《Social Diversity and Social Preferences in Mixed-Motive Reinforcement Learning
    混合动机强化学习中的社会多样性与社会偏好总结:本质是在研究当智能体群体中的个体具有独特性质时在困境强化学习中对结果的影响。提出了一个社会价值偏向取向的概念来使......