Codeforces Round #340 (Div. 2) (617A,617B,617C,617D(Constructive ),617E(莫队算法))

基于Python的Codeforces竞赛数据抓取与分析实战 数据抓取与分析是理解在线平台生态的核心技术。其原理在于通过自动化脚本模拟浏览器行为,从目标网站获取公开数据,并利用数据处理库进行清洗、统计与可视化。这项技术的价值在于能将海量、非结构化的信息转化为可量化的洞察,极大地提升研究、复盘与决策的效率。在算法竞赛领域,它常被应用于分析题目难度趋势、高频考点分布以及选手行为模式。本文以Codeforces平台为例,详细讲解了如何构建一个完整的分析工具链,涵盖从合规抓取、指标计算到报告生成的全过程,并重点探讨了如何通过Python的requests、pandas等库实现 阅读详情

比赛的时候由于入了一道题的坑,而且一直没爬出来。。。

Elephant

题目连接:

http://codeforces.com/contest/617/problem/A

解题思路:

It's optimal to do the biggest possible step everytime. So elephant should do several steps by distance 5 and one or zero step by smaller distance. Answer equals to 

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
    int x;
    scanf("%d",&x);
    if(x%5)
        printf("%d\n",x/5+1);
    else
        printf("%d\n",x/5);
    return 0;
}

Chocolate

题目连接:

http://codeforces.com/contest/617/problem/B

解题思路:

We are given array which contains only ones and zeroes. We must divide it on parts with only one 1.

Tricky case: when array contains only zeroes answer equals to 0.

In general. Between two adjacent ones we must have only one separation. So, answer equals to product of values posi - posi - 1 whereposi is position of i-th one.

弱英语差,没看到这句话:You are asked to calculate the number of ways he can do it. 

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long ll;
int a[110];

int main(){
    int n;
    while(~scanf("%d",&n)){
        for(int i = 0; i < n; i++)
            scanf("%d",&a[i]);
        int i;
        for(i = 0; i < n; i++){
            if(a[i] == 1)
                break;
        }
        if(i == n){
            printf("0\n");
            continue;
        }
        ll cnt = 1,ans = 1;
        for(; i < n; i++){
            if(a[i] == 1){
                ans *= cnt;
                cnt = 1;
            }
            else
                cnt++;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Watering Flowers

题目连接:

http://codeforces.com/contest/617/problem/C

解题思路:

First radius equals to zero or distance from first fountain to some flower. Let's iterate over this numbers. Second radius equals to maximal distance from second fountain to flower which doesn't belong to circle with first radius. Now we should choose variant with minimalr12 + r22.

AC代码(n^2):

#include <iostream>
#include <vector>
#define INF 1e18
using namespace std;

typedef long long ll;

ll square(int x){
    return (ll)x * x;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    int n, x1, y1, x2, y2;
    while(cin >> n >> x1 >> y1 >> x2 >> y2){
        vector<pair<ll, ll> > dist(n);
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            dist[i].first = square(x - x1) + square(y - y1);
            dist[i].second = square(x - x2) + square(y - y2);
        }
        dist.push_back({0, 0});

        ll result = INF;
        for(int i = 0; i <= n; i++){
            ll r1 = dist[i].first;
            ll r2 = 0;
            for(int j = 0; j <= n; j++){
                if(dist[j].first > r1){
                    r2 = max(r2, dist[j].second);
                }
            }
            result = min(result, r1 + r2);
        }
        cout << result << endl;
    }
    return 0;
}

AC代码(nlogn):

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

ll square(int x) {
    return x * (ll) x;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    int n, x1, y1, x2, y2;
    while(cin >> n >> x1 >> y1 >> x2 >> y2){
        vector< pair<ll, ll> > dist(n);
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            dist[i].first = square(x - x1) + square(y - y1);
            dist[i].second = square(x - x2) + square(y - y2);
        }

        sort(dist.begin(), dist.end());
        vector<ll> maxsuf(n + 1);
        for (int i = n - 1; i >= 0; i--) {
            maxsuf[i] = max(maxsuf[i + 1], dist[i].second);
        }

        ll result = min(dist[n - 1].first, maxsuf[0]);
        for (int i = 0; i < n; i++) {
            ll r1 = dist[i].first;
            ll r2 = maxsuf[i + 1];
            result = min(result, r1 + r2);
        }
        cout << result << endl;
    }
    return 0;
}

Polyline

题目连接:

http://codeforces.com/contest/617/problem/D

解题思路:

Answer equals to one if all coordinates x or y of points are same.

When answer equals to two? Let's iterate over all pairs of points. Let first point in pair is beginning of polyline, second point is end. Only one or two such polylines with answer two exist. If third point is on the polyline it belongs to rectangle with corners in first two points. We can just check it.

Else answer equals to three. We can build vertical lines which contains the most left and the most right point and horizontal line through third point. If we erase some excess rays we will get polyline.

AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int x[3], y[3];

bool is_between(int a, int b, int c) {
    return min(a, b) <= c && c <= max(a, b);
}

bool judge(int i, int j, int k) {
    return (x[k] == x[i] || x[k] == x[j]) && is_between(y[i], y[j], y[k]) ||
           (y[k] == y[i] || y[k] == y[j]) && is_between(x[i], x[j], x[k]);
}

int main(){
    for(int i = 0; i < 3; i++)
        scanf("%d%d",&x[i],&y[i]);

    if(x[0] == x[1] && x[1] == x[2] || y[0] == y[1] && y[1] == y[2]){
        puts("1");
    }else if(judge(0,1,2) || judge(0,2,1) || judge(1,2,0)){
        puts("2");
    }else{
        puts("3");
    }
    return 0;
}


XOR and Favorite Number

题目连接:

http://codeforces.com/contest/617/problem/E

解题思路:

We have array a.

Let's calculate array pref (pref[0] = 0, ).

Xor of subarray a[l...r] equals to .

So query (l, r) is counting number of pairs i, j (l - 1 ≤ i < j ≤ r) .

Let we know answer for query (l, r) and know for all v cnt[v] — count of v in a[l - 1...r]. We can update in O(1) answer and cnt if we move left or right border of query on 1. So we can solve problem offline in  with sqrt-decomposion (Mo's algorithm).

AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
const int blocks = 300;

struct Query{
	int l, r, id;
	bool operator < (const Query& other) const{
		return l / blocks < other.l / blocks || (l / blocks == other.l / blocks && r < other.r);
	}
};

int n, m, k;
Query q[100000];
ll ans[100000];
int s[100001];
int cnt[1 << 20];
ll cur;

void add(int x){
	cur += cnt[x ^ k];
	cnt[x]++;
}

void del(int x){
	cnt[x]--;
	cur -= cnt[x ^ k];
}

int main(){
    while(~scanf("%d%d%d",&n,&m,&k)){
        for (int i = 1; i <= n; i++){
            scanf("%d", &s[i]);
            s[i] ^= s[i - 1];
        }
        for (int i = 0; i < m; ++i){
            scanf("%d%d",&q[i].l,&q[i].r);
            q[i].id = i;
        }
        sort(q,q+m);
        int l = 1, r = 0;
        for(int i = 0; i < m; ++i){
            while(q[i].l - 1 > l)
                del(s[l++]);
            while(q[i].l - 1 < l)
                add(s[--l]);
            while(q[i].r > r)
                add(s[++r]);
            while(q[i].r < r)
                del(s[r--]);
            ans[q[i].id] = cur;
        }
        for (int i = 0; i < m; ++i){
            printf("%lld\n", ans[i]);
        }
    }
	return 0;
}


Subdivision Methods for Geometric Design - A Constructive Approach 计算机图形学中关于 细分表面、几何处理的一本好书 立即下载

相关推荐

Matlab实战:从零搭建弹道导弹六自由度仿真模型(附完整代码)

本文详细介绍了如何使用Matlab从零搭建弹道导弹六自由度仿真模型,涵盖仿真环境配置、核心运动方程实现、气动力建模及仿真结果分析。通过完整代码示例,帮助读者掌握弹道导弹六自由度仿真的关键技术,适用于航空航天工程和复杂系统建模领域。

x8y9z0的博客 947

Codeforces 2026上半年赛事深度复盘:从比赛筛选到高效训练指南

在算法竞赛领域,系统性复盘是提升实力的核心。其原理在于通过分析大量比赛数据,识别高质量题目与有效训练路径,从而将有限时间价值最大化。对于Codeforces这类高频赛事平台,选手常面临“打哪些比赛、复盘哪些题”的困惑。本文基于2026年上半年超过60场常规Round的实战数据,从题目质量、难度曲线、出题人风格等维度进行横向对比,旨在解决信息筛选与价值判断问题。通过建立难度坐标系和规划个人训练路径,帮助不同Rating区间的选手识别“信号”与“噪音”,高效利用比赛资源,洞察出题趋势,实现针对性突破。

weixin_33857230的博客 435

基于文件通信的QMT量化交易信号桥接方案设计与实现

在量化交易系统开发中,进程间通信(IPC)是连接不同计算模块、实现策略逻辑与交易执行解耦的关键技术。其核心原理在于允许运行于独立环境或进程的程序安全、可靠地交换数据。文件系统通信作为一种经典的IPC方法,因其实现简单、跨平台兼容性好且数据可持久化,在非高频场景下具有重要技术价值。它尤其适用于需要将外部复杂计算环境(如配备丰富数据科学库的Python环境)与专用交易终端(如迅投QMT)集成的应用场景。通过约定文件路径与数据格式,外部程序可将包含交易指令的JSON信号文件写入特定目录,而交易终端通过轮询或监听机

weixin_28678151的博客 417

CodeForces 617E XOR and Favorite Number(莫队)

题意: 给你n个数,m次询问,询问给你(l,r),问你满足l ≤ i ≤ j ≤ r, ai^(ai+1)^...aj = k的区间数。 思路:因为又是区间又是没修改的询问,很容易想到莫队,但是怎么O(1)转移呢,可以利用异或的前缀和,具体思路可 以看官方题解: We have array a. Let's calculate array pref (pref[0] =

CillyB的博客 446

YOLOv8知识蒸馏实战:用BCKD和LD在自制数据集上分别提点1.63%和1.69%的保姆级教程

本文详细介绍了在YOLOv8模型上应用知识蒸馏技术(BCKD和LD方法)的实战教程,通过自制数据集实现性能提升1.63%和1.69%。内容涵盖环境配置、模型选择、BCKD和LD的具体实现及调参技巧,适合目标检测领域的开发者和研究者。

weixin_29082143的博客 245

运放+三极管恒流源电路设计实战:从原理到仿真一步到位(附Multisim文件)

本文详细解析了运放与三极管构建恒流源电路的核心原理,重点阐述了负反馈机制如何实现精准的电流控制。通过Multisim仿真实战,从电路搭建、参数计算到负载调整率与动态响应分析,一步步指导设计过程,并提供常见故障的调试技巧与PCB设计要点,帮助工程师从理论平稳过渡到可靠实践。

7z8x2c4v6b9的博客 711

Codeforces Round 915 (Div. 2) A-F(补题&补写法)

即一棵大小为n的根id=1的树,变为大小为n的根id=2的树(或变为根id=3的树)时,称一个位置x是good的,当且仅当所有ypx,其实就是,将(x,px)看成是二维平面点的时候,左侧的点都在左下方,右侧的点都在右上方。所以,可能产生贡献的位置对,只有2*n个,暴力检查这2*n个,能快速算贡献改变量即可。因为,将(i,pi)看成是二维平面点的时候,左侧的点都在左下方,右侧的点都在右上方,即x/2上取整,x/2下取整,(x-1)/2上取整,(x-1)/2下取整,

小衣同学的博客 3074

Hierarchical Flow Partition(Top-down&&Bottom-up)

hierarchy flow是将设计切分成多个block,分别处理单个block,然后完成后,将它们进行拼接以完成最终的chip。一般划分为三个阶段:chip planning;physical budget就是pin assignmenthierarchy flow实现的方法有两种,一种是top-down,另一种是bottom-up,无论是哪种,都是都要通过flatten的方法分别全局范围进行优化实现。

qq_39493558的博客 3070

Codeforces 1088 Div1+2(ABC1C2DEF)

CF1088Div1+2

2402_89326161的博客 437

微信商家转账报错“当前使用用户过多,请稍后重新确认收款”解决方案

当前使用用户过多,请稍后重新确认收款”这个错误,其实就是典型的参数误处理导致的假报错。记住一句话就行👇JSAPI 场景下的package参数不要做 UrlEncode。如果你也遇到这个问题,希望这篇文章能帮你少踩一个坑。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 784

026:vue+threeJS 设置地面铺砖的效果

BoxGeometry 是 Three.js 中用于创建立方体或长方体的几何体类。它允许你指定立方体的宽度、高度、深度以及这三个方向上的分段数,从而控制立方体的细分程度。width: 立方体的宽度(沿 x 轴方向)。height: 立方体的高度(沿 y 轴方向)。depth: 立方体的深度(沿 z 轴方向)。widthSegments: 可选参数,指定立方体在 x 轴方向上的分段数,默认值为 1。heightSegments: 可选参数,指定立方体在 y 轴方向上的分段数,默认值为 1。

大剑师兰特的GIS世界 645

Codeforces Round 915(Div.2) A~F

给出一个n×m的网格,你需要将网格上所有点均填满水,当一个格子同时满足以下两个条件时,格子中也会被填满水:该格子的左边或右边已经被填满水了该格子的上面或下面已经被填满水了一次操作可以给一个格子填满水,问至少几次操作才能将所有网格填满。

Code_Shark的博客 1332

Altera FPGA与高速ADS4249和DAC3482的LVDS接口设计

引言:本文以TI的ADS4249(ADC)和DAC3482(DAC)之间的接口为例,介绍Altera FPGA与ADC/DAC之间的DDR LVDS接口设计以及时序约束详细设计。本文介绍的实例可方便扩展到具有类似接口格式的其他高速数据转换器设计。

FPGA_Designer 1899

Codeforces Round #719 (Div. 3) 1520

math #include <bits/stdc++.h> using namespace std; #define FI first #define SE second #define MP make_pair #define PB push_back #define rep(i, a, b) for(int i=(a); i<(b); i++) #define per(i, a, b) for(int i=(b)-1; i>=(a); i--) typedef long long

m0_53091571的博客 95

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Codeforces Round #346 (Div. 2) (659A,659B,659C,659D(几何叉乘),659E(并查集))

Round House 题目链接: http://codeforces.com/problemset/problem/659/A 解题思路: The answer for the problem is calculated with a formula ((a - 1 + b)  n + n)  n + 1. Such solution has complexity

piaocoder 1857

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

April Fools Day Contest 2016 (656A,656B,656C,656D,656E,656F)

Da Vinci Powers 题目链接: http://codeforces.com/problemset/problem/656/A 解题思路: This problem asked to figure out an integer sequence from two samples and problem title. It turned out to be surprising

piaocoder 1437

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Codeforces Round #323 (Div. 2) (583A,583B,582A,582B)

1.Asphalting Roads 题目链接: http://codeforces.com/problemset/problem/583/A 解题思路: To solve the problem one could just store two arrays hused[j] and vused[j] sized n and filled with false initial

piaocoder 1192

Codeforces Round #340 (Div. 2) (629A,629B,629C(排列组合,动态规划),629D(线段树))

Far Relative’s Birthday Cake 题目链接: http://www.codeforces.com/problemset/problem/629/A 解题思路: Consider that we have rowi chocolates in the i'th row and coli chocolates in the i'th column.

piaocoder 1177

Codeforces Round #326 (Div. 2) (588A,588B,587A)

1.Duff and Meat 题目链接: http://codeforces.com/problemset/problem/588/A 解题思路: Idea is a simple greedy, buy needed meat for i - th day when it's cheapest among days 1, 2, ..., n. So, th

piaocoder 1061

Codeforces Round #329 (Div. 2) (593A,593B,593C,593D)

2Char 题目链接: http://codeforces.com/problemset/problem/593/A 解题思路: For each letter will maintain the total length of words (cnt1ci), which found it was alone, and for each pair of letters wi

piaocoder 990

Codeforces Round #324 (Div. 2) (584A,584B(排列组合),584C(构造),584D(哥德巴赫猜想),584E(置换群))

1.Olesya and Rodion 题目链接: http://codeforces.com/problemset/problem/584/A 解题思路: Two cases: t = 10 and t ≠ 10. If t = 10 then there are two cases again :). If n = 1 then answer is

piaocoder 971

Codeforces Round #325 (Div. 2) (586A,586B,585A,585B)

1.Alena's Schedule 题目链接: http://codeforces.com/problemset/problem/586/A 解题思路: To solve this problem one should remove all leading and trailing zeroes from array and then calculate the nu

piaocoder 963

8VC Venture Cup 2016 - Elimination Round (626A,626B,626C(二分),626D(概率))

Robot Sequence 题目连接: http://codeforces.com/problemset/problem/626/A 解题思路: We can simulate Calvin’s path on each substring, and check if he returns to the origin. Runtime: O(n3) AC代码: #i

piaocoder 942

Codeforces Round #317 (Div. 2) (572A Arrays,572B Order Book)

1.572A Arrays 题目链接: http://codeforces.com/problemset/problem/572/A 解题思路: 取第一个数列的第k个数,然后倒着取第二个数列的第m个数,比较即可。。。 AC代码: #include #include #include using namespace std; int a[100005]; int b[10

piaocoder 872

Codeforces Round #365 (Div. 2) (703A,703B(容斥),703C(几何),703D(树状数组))

Mishka and Game 题目链接: http://codeforces.com/problemset/problem/703/A 解题思路: In this problem you had to do use the following algo. If Mishka wins Chris in the current round, then increase variable

piaocoder 800
上一篇: BestCoder Round #69 (div.2)(hdu5610,hdu5611,hdu5612(动态规划))
下一篇: Codeforces Round #340 (Div. 2) (618A,618B,618C)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值