首页 > 其他分享 >Educational Codeforces Round 11

Educational Codeforces Round 11

时间:2023-01-04 18:46:42浏览次数:60  
标签:11 std Educational int Codeforces long ans using include

Educational Codeforces Round 11

https://codeforces.com/contest/660

A. Co-prime Array

\(1\) 与任何数的 \(gcd\) 都为 \(1\),直接在不符合条件的两点间塞就可以了

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1005;
int a[N], n, ans;
bool vis[N];

void solve () {
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    for (int i = 2; i <= n; i++) {
        if (__gcd (a[i-1], a[i]) != 1)  vis[i-1] = true, ans ++;
    }
    cout << ans << endl;
    for (int i = 1; i <= n; i++) {
        cout << a[i] << ' ';
        if (vis[i])     cout << "1 ";
    }
}

signed main () {
    solve ();
}

B. Seating On Bus

仔细读题,注意细节。

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve () {
    int n, m;
    cin >> n >> m;
    if (m <= 2 * n) {
        for (int i = 1; i <= m; i++)    cout << i << ' ';
        return ;
    }
    for (int i = 1; i <= 2 * n; i++) {
        if (i + 2 * n <= m)     cout << i + 2 * n << ' ';
        cout << i << ' ';
    }
}

signed main () {
    solve ();
}

C. Hard Process

此题有很多做法。
这里用双指针主要是考虑从暴力转移,区间 \([l,r]\) 范围内 \(0\) 的个数,\(\leq k\),不难发现这是一个区间和问题,故可以用双指针来维护,和这题 D - Enough Array 很类似

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> pii;
const int N = 3e5 + 5;
int n, k, a[N];

void solve () {
    cin >> n >> k;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    int l = 1, r = 1, sum = 0, ans = 0, ansl, ansr;
    while (r <= n) {
        sum += !a[r]; //0的个数
        if (sum > k)        sum -= !a[l ++];
        if (r - l + 1 > ans) {
            ans = r - l + 1;
            ansl = l, ansr = r;
        }
        r ++;
    }
    cout << ans << endl;
    for (int i = ansl; i <= ansr; i++)  a[i] = 1;
    for (int i = 1; i <= n; i++)    cout << a[i] << ' ';
}

signed main () {
    solve ();
}

D. Number of Parallelograms

利用平行四边形对角线互相平分的性质,记录两点之间的中点,即可最简化代码。

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> pii;
const int N = 2005;
pii p[N];
int n, ans;

void solve () {
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> p[i].first >> p[i].second;
    map<pii, int> mp;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            mp[{p[i].first + p[j].first, p[i].second + p[j].second}] ++;
        }
    }
    for (auto i : mp) {
        ans += (i.second - 1) * i.second / 2;
    }
    
    cout << ans << endl;
}

signed main () {
    solve ();
}

E. Different Subsets For All Tuples

F. Bear and Bowling 4

标签:11,std,Educational,int,Codeforces,long,ans,using,include
From: https://www.cnblogs.com/CTing/p/17025712.html

相关文章

  • C++11:move函数将左值强制转换为右值
    通过学习C++11移动构造函数我们知道,C++11标准中借助右值引用可以为指定类添加移动构造函数,这样当使用该类的右值对象(可以理解为临时对象)初始化同类对象时,编译器会优先选择......
  • 11G RAC环境GRID目录及文件错误权限的修复
    111.2.0.4环境测试1.1 测试前的资源状态下面查看一下测试前的资源状态,确保每个资源的状态都是正常的。[grid@rac112042~]$crsctlstatusresource-t-----------------......
  • redis部署手册_20221129
    1.软件版本及下载Keepalived:https://www.keepalived.org/download.htmlRedis下载地址:https://redis.io/download/本次安装版本:Redis:7.0.5Keepalived:2.2.72.主......
  • 阿里云可观测 11 月功能快报&优惠快讯
    ......
  • FreeSWITCH学习笔记11 - 基本功能与实现
    11.1、批量创建用户11.2、用FreeSWITCH实现IVR11.2.1、最简单的菜单                    11.2.2、默认IVR简介11.3、按时间进行路由  ......
  • 11G RAC环境GRID目录及文件错误权限的修复
    最近一段时间,遇到几个项目由于种种原因导致GRID_HOME目录或者下面的文件的权限被修改,出现CRS不能正常的启动。在启动ora.mdnsd的时,一直在STARTING。此故障原来模拟过几次都......
  • 万万没想到,除了香农计划,Python3.11竟还有这么多性能提升!
    众所周知,Python3.11版本带来了较大的性能提升,但是,它具体在哪些方面上得到了优化呢?除了著名的“香农计划”外,它还包含哪些与性能相关的优化呢?本文将带你一探究竟!作者:Beshr......
  • 1.4 vp Codeforces Round #838 (Div. 2)
    A-DivideandConquer题意:给出序列a,设b为a中元素总和。你可以选择a中任意元素,将它除以二(向下取整)。问最少需要多少次可以使b为偶数思路:将a划分为奇偶两个集合。a中偶数......
  • windows使用/服务(6)Win11 打开 IE 浏览器
    windows11系统使用基于Chromium内核的Edge浏览器,IE浏览器直接被取代,使用以下方案可以调用IE浏览器但是还是兼容不是很好有些基于IE开发的网站的功能依然兼容不友好,需......
  • 调整 Windows 11 任务栏位置
    原文链接:如何调整Windows11任务栏位置、对齐方式,及自定义任务栏(sysgeek.cn)将Windows11任务栏调到桌面顶部、左边或右边如果只将任务栏图标「靠左」和「居中」对......