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

【张量分解(二)】CP分解 一、CP分解 1.1 定义 CP分解就是将一个张量分解成多个单秩张量的和。例如,给定一个三阶张量X∈RI×J×K\mathcal{X}\in\mathbb{R}^{I\times J\times K}X∈RI×J×K,则CP分解可以写为 X≈∑r=1Rar∘br∘cr\mathcal{X}\approx\sum_{r=1}^{R}\textbf{a}_r\circ\textbf{b}_r\circ... 阅读详情

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 countM by 1. Otherwise (if Chris wins Mishka) increase variable countC. After that you had to compare this values and print the answer.

AC代码:

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    while(~scanf("%d",&n)){
        int cnt1 = 0,cnt2 = 0;
        int x,y;
        for(int i = 0; i < n; ++i){
            scanf("%d%d",&x,&y);
            if(x > y)
                ++cnt1;
            else if(x < y)
                ++cnt2;
        }
        if(cnt1 > cnt2)
            puts("Mishka");
        else if(cnt1 < cnt2)
            puts("Chris");
        else
            puts("Friendship is magic!^^");
    }
    return 0;
}


Mishka and trip

题目链接:

http://codeforces.com/problemset/problem/703/B

解题思路:

Let's look at the first capital. Note that the total cost of the outgoing roads is c[id1] · (sum - c[id1]), where sum — summary beauty of allcities. Thus iterating through the capitals we can count the summary cost of roads between capitals and all the other cities. But don't forget that in this case we count the roads between pairs of capitals twice. To avoid this on each step we should update sum = sum - c[idcur] , where idcur is the position of current capital. In the end we should add to the answer the cost of roads between "non-capital" neighbour cities.

Complexity — O(n).

算法思想:

题解是O(nlogn)的,其实我们只需要求出前缀和,然后先求出每个首都城市x,对答案的贡献:c[x] * others即可。O(n).

AC代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
const int N = 100005;
int c[N];
bool vis[N];

int main(){
    int n,k;
	while(~scanf("%d%d",&n,&k)){
        memset(vis,false,sizeof(vis));
        ll sum = 0;
        for(int i = 1; i <= n; ++i){
            scanf("%d",&c[i]);
            sum += c[i];
        }
        ll visc = 0,ans = 0;
        for(int i = 1; i <= k; ++i){
            int x;
            scanf("%d",&x);
            visc += c[x];
            ans += c[x]*(sum-visc);
            vis[x] = true;
        }
        for(int i = 1; i <= n; ++i){
            if(vis[i] || vis[i+1])
                continue;
            ans += c[i]*c[i+1];
        }
        if(!vis[1] && !vis[n])
            ans += c[1]*c[n];
        printf("%lld\n",ans);
	}
	return 0;
}


Chris and Road

题目链接:

http://codeforces.com/problemset/problem/703/C

解题思路:

Imagine that the bus stands still and we move "to the right" with a constant speed v. Then it's not hard to see that movement along the liney = (u / v) · (x  -  t0) is optimal, where t0 — time in which we begin our movement. In this way answer is t = t0 + (w / u).

If t0 = 0, then we start our movement immediately. In this case we need to check that our line doesn't intersect polygon (either we can cross the road in front of a bus, or the bus is gone).

Otherwise we need to find such minimal t0 that our line is tangent to the polygon. It can be done with binary search.

Complexity — O(n log n).

算法思想:

我们可以先考虑人直接过去,而车撞不到人的情况;然后再考虑人等车先过,人再过的情况即可。

AC代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 10005;
int n,w,v,u;
int x[N],y[N];

bool pre(){
    for(int i = 0; i < n; ++i)
        if(ll(x[i])*u < ll(y[i])*v)
            return false;
    return true;
}

double solve(){
    double ret = w*1.0/u;
    for(int i = 0; i < n; ++i)
        ret = max(ret, x[i]*1.0/v + (w-y[i])*1.0/u);
    return ret;
}

int main(){
    while(~scanf("%d%d%d%d",&n,&w,&v,&u)){
        for(int i = 0; i < n; i++)
            scanf("%d%d",&x[i],&y[i]);
        if(pre()){
            printf("%.6lf\n",w*1.0/u);
            return 0;
        }
        printf("%.6lf\n",solve());
    }
    return 0;
}


Mishka and Interesting sum

题目链接:

http://codeforces.com/problemset/problem/703/D

解题思路:

Easy to see, that the answer for query is XOR-sum of all elements in the segment xored with XOR-sum of distinct elements in the segment. XOR-sum of all numbers we can find in O(1) using partial sums. As for the XOR-sum of distinct numbers... Let's solve easier problem.

Let the queries be like "find the number of distinct values in a segment". Let's sort all the queries according to their right bounds and iterate through all elements of our array. We also need to make a list last, where last[value] is the last position of value on the processed prefix of array. Assume we are at position r. Then the answer for the query in the segment [l,  r] (l ≤ r) is , where cnt[i] = 1 iflast[ai] = i and 0 otherwise. It's easy to store and update such values in cnt. When moving to the next position we have to make the following assignments: cnt[last[ai]] = 0, cnt[i] = 1, last[ai] = i. To get described sum in O(log n) we can use segment tree (or Fenwick tree) instead of standard array.

Now let's turn back to our problem. Everything we have to do is to change assignment cnt[i] = 1 to cnt[i] = ai and count XOR-sum instead of sum. Now we can solve this problem in O(n log n).

题目大意:

给你n个数,然后m次查询,每一次查询输出所在给定区间内出现偶数次数的数的异或值,如果只有一个出现偶数次数的数,则直接

输出该数,如果没有出现偶数次数的数,则直接输出0。

算法思想:

和求一个区间内不同元素个数的做法一样。树状数组存的是不同元素的前缀异或和。用map标记数a[i]最近的出现的下标。其实就是

先求出这个区间的(异或和),然后再异或上这个区间不同数的异或和(即由树状数组来完成的)。

AC代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1000005;
map<int,int> mp;
vector<int> que[N];
int n,m;
int a[N];
int l[N],r[N];
ll res[N],bit[N];
ll ans[N];

int lowbit(int x){
    return x&(-x);
}

void update(int x, ll val){
	for(int i = x; i <= n; i += lowbit(i))
		bit[i] ^= val;
}

int sum(int x){
	ll res = 0;
	for(int i = x; i > 0; i -= lowbit(i))
		res ^= bit[i];
	return res;
}

int main(){
	while(~scanf("%d",&n)){
        mp.clear();
        memset(res,0,sizeof(res));
        for(int i = 0; i <= n; ++i)
            que[i].clear();
        for(int i = 1; i <= n; ++i){
            scanf("%d",&a[i]);
            res[i] = (res[i-1]^a[i]);
        }
        scanf("%d",&m);
        for(int i = 0; i < m; ++i){
            scanf("%d%d",&l[i],&r[i]);
            que[l[i]].push_back(i);
            ans[i] = res[r[i]]^res[l[i]-1];
        }
        for(int i = n; i >= 1; --i){
            int x = a[i];
            if(mp.count(x))
                update(mp[x],x);
            update(i,x);
            mp[x] = i;
            for(int j = 0; j < que[i].size(); ++j){
                int id = que[i][j];
                ans[id] ^= sum(r[id]);
            }
        }
        for(int i = 0; i < m; ++i)
            printf("%lld\n", ans[i]);
	}
	return 0;
}


IDCNBSAIS-财务报表功能范围取值管理费用、销售费用、研发费用排除指定科目的实现 研究了很多方法,没有办法实现,只在营业费用增加一个冲抵项解决,也咨询了外部顾问说要建立自建表。限于需要马上修正后面只能用了最最low的办法处理了一下。公司遇到的一个问题,目前报表有些项目是按照功能范围取值的,发现取多了。IDCNBSAIS-财务报表功能范围取值管理费用、销售费用、研发费用排除指定科目的实现。最后结果是正确的,但是总觉得有更好的办法,不知道有没有高人可以指点一下?建立一个调整项的目录,在每个节点做了调整。除了研发费用做了冲抵在以下每个节点都做了冲抵。为财务报表定义表格结构。 阅读详情

相关推荐

基于51单片机的电压表【0-20V,ADC0832,4051,自动量程】(仿真)

自动换挡式数字电压表就是一个基于单片机的能自动切换量程的数字电压表,其作用是在使用低位的AD转换实现高精度电压测量,可以测量0~20V的电压,并且具有0~0.2V(待测电玉低于0.2V时),0~2V(待测电压低于2V时)和0~20V三个量程自动匹配测量,当待测电压值发生变化时,电压表可以根据输入电压情况自动选择合适的量程进行测量,并且把测量结果显示出来。(2)实现电压表精度测试,最高精度要求0.01V;(1)实现0~20V分3档式电压表;

qq_63964231的博客 1497

Codeforces Round 703 (Div. 2)(A~D)

Codeforces Round 703 (Div. 2)(A~D)

m0_62289613的博客 406

ROS2多线程处理RTSP视频流避坑指南:OpenCV解码丢帧问题解决方案

本文针对ROS2中处理RTSP视频流时OpenCV解码丢帧的常见问题,提供了专业的解决方案。通过深入分析单线程模型的瓶颈,提出并详细拆解了基于生产者-消费者多线程模型的健壮实现方案,有效分离数据采集与处理,从而显著提升视频流的稳定性和流畅度。

weixin_29199873的博客 167

Codeforces Round #703 (Div. 2)(A ~ F)超高质量题解【每日亿题2 / 19】

Codeforces Round #703 (Div. 2)(A、B、C、D、E、F)超高质量题解 A. Shifting Stacks B - Eastern Exhibition C1 - Guessing the Greatest (easy version) C2 - Guessing the Greatest (hard version) D - Max Median E - Paired Payment F - Pairs of Paths

繁凡さん的博客 4062

2023全国职业技能大赛 网络系统管理 服务部署 Linux部分--基础配置

服务器和客户端基本配置如下表,各虚拟机已预装系统。一、关闭防火墙和Selinux。七、需要使用到的命令详解。三、修改root密码。

weixin_62926639的博客 998

JAX/JAXlib GPU 加速版本安装教程(CUDA)

本文介绍了在Windows WSL2+Ubuntu22.04环境下配置JAX/JAXlib GPU加速版本的详细步骤。使用RTX 4060显卡,安装CUDA 12.4和cuDNN 8.9.7驱动,通过Miniconda创建Python 3.9虚拟环境。具体步骤包括:安装Miniconda、配置CUDA环境变量、安装cuDNN驱动、下载并安装JAX/JAXlib。最后通过测试代码验证GPU加速功能,成功检测到GPU并完成矩阵运算。整个过程配有详细命令和截图说明,适合需要搭建JAX GPU开发环境的用户参考。

猿小白的博客 625

Codeforces Round #703 (Div. 2)

题目链接 Here A题 因为是任意次数加,所以可以0,1,2,3…0,1,2,3\dots0,1,2,3… 具体看代码 代码 #include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <cstring> #include <cmath> #include <unordered_map> using nam

qq_46264636的博客 1300

Python爬虫实战:全面采集国家自然科学基金项目数据的全流程指南

国家自然科学基金委员会(NSFC)支持基础研究、应用基础研究,是我国科研投入的核心项目之一。公开的项目数据包括项目名称、负责人、资助金额、年度、单位等,具备极高科研和数据分析价值。requests:基础HTTP请求库,简单直观:异步HTTP请求库,适合大规模并发:HTML解析,提取数据:处理JavaScript渲染网页pandas:数据分析与清洗:数据库存储:重试机制实现。

2201_76125261的博客 753

Codeforces Round #703 (Div. 2) (自闭场)

A. Shifting Stacks 这题我能记很久,直接给我打自闭了,从开赛一直到了最后,我就一个菜鸡 题意非常简单,给你n个数,让你把他们构造成递增的,然后只能从后往前,你直接想就行了,直接构造0 1 2 3 4 5 6 7 8 9…n如果可以的话,就是yes,不可以的话就是no 然后上我第一遍的代码 #include <bits/stdc++.h> #define int long long #define BUFF ios::sync_with_stdio(false), cin.t

godhandsjoker的博客 2658

包成功安装tiny-cuda-nn,记录安装过程中的问题解决,附带pytorch3d安装【踩坑指南】

该包可以显著提高NeRF训练速度,是和NeRFstudio等框架中,必须使用的。本文提供tiny-cuda-nn可以安装的完整包的下载链接,可以直接上传到项目中安装。附带笔者遇到的问题的解决方案。

zik的博客 7029

基于Python实现人脸识别相似度对比

随着人工智能技术的不断进步,人脸识别成为了一种广泛应用的技术。人脸相似度对比是其中的一个重要应用场景,可以用于人脸搜索、身份验证等方面。本文将介绍如何使用Python实现人脸相似度对比。

商务合作 / 项目定制 / 学习交流。个人vx:lovely_wml 9808

Codeforces Round #703 (Div. 2)补题

前言 一题自闭,掉大分。 题目 A 注意只能后移不能前移即可。 B 之前学长讲过一维推广到二维的情况,赛时也回想到了,但是没想到曼哈顿距离也能推广。算是个结论吧。 一维:奇数取中位数,偶数取两个中位数之间的任何位置都可以。 AC代码: /* * @Author: hesorchen * @Date: 2020-11-26 09:12:46 * @LastEditTime: 2021-02-19 15:31:36 * @Description: 栽种绝处的花 */ #include <bi

陈颜的博客 1211

Ollama + OpenCLAW 在 Windows 系统的完整部署指南

Windows 部署优先选 WSL2,避免原生环境的权限/兼容性问题;网络问题通过“离线包+国内镜像”解决,版本问题通过升级 Node.js 解决;内存不足可切换轻量模型或增大 WSL2 内存分配;核心链路:Ollama(模型管理)→ Gateway(网关)→ OpenCLAW TUI(交互),各组件启动正常即可稳定使用。

lpfasd123的博客 2824

【解题报告】Codeforces Round #365 (Div. 2)

简略的解题报告。

TRiddle的博客 689

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Codeforces Round #365 (Div. 2) C

链接:http://codeforces.com/problemset/problem/703/C 分析: 这题其实是个大水题,只要短短的几行就可以搞定的, 首先需要直觉判断一点,就是只要判断最左边的点和最下面的点 以及和他们相邻边的右边的点 第二部我们就需要判断人与这两个边有没有交点,如果人与上面的有交点,那么人肯定就需要在下面的那条边等待 等待的时间是 max(x - y*1.0*v/...

weixin_30340353的博客 74

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

codeforces 702div3 题解

前天打了codeforces703div3的比赛,这场比赛我一个小时做出了前6题,第7题在场内因为看错了题意,很遗憾没能AK,从200名掉到了800多名,在算排名的人里面排了200多名,涨了差不多100分吧。我codeforces有两个账号, 一个1800分,一个1600多分。今天的cf我没有打,先休息一天吧,下周在继续冲击更高的目标。 G题:(单调栈 + 二分 + 数学推导) 前面六个题都很基础,就不讲解了,重点讲一下G题吧。 G题是让你求一个长度为n的循环序列至少多少项的前缀和大于等于x。 n是2000

Einsteinme的博客 514

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #703 Div2 D. Max Median 二分答案

Codeforces Round #703 Div2 D. Max Median 二分答案题意思路Code(78MS) 传送门:https://codeforces.com/contest/1486/problem/D 题意 给一个长度为n的数组,在里面找若干个长度≥k的区间,问这些区间中最大的中位数是多少。给一个长度为n的数组,在里面找若干个长度\ge k的区间,问这些区间中最大的中位数是多少。给一个长度为n的数组,在里面找若干个长度≥k的区间,问这些区间中最大的中位数是多少。 中位数,请输出最大值。\r

狙击美佐的博客 385

Codeforces Round #703 (Div. 2) 题解

倒序补题法

Irving0323的博客 1585

Codeforces Round #703 (Div. 2) D. Max Median

题意:给一个长度为n的序列,对于一个区间长度不小于k的子区间,中位数为这个区间排序后的第(k+1)/2个数字。现在求所有的长度不小于k的子区间,中位数的最大值是多少。 思路:首先要想到,对于一个中位数,在这题中,对于偶数长度,取的中位数是靠左边的那个,那么大于等于中位数的就有一半以上。 所以大于等于中位数的个数要比小于中位数的个数多。 利用这点,那么其实我们可以在On复杂度判断出来一个数字是不是 ≤中位数。 可以判断一个数是不是≤中位数? 那么我们是不是可以去二分? 其实这是有单调性的。 判断一个数字是不是

菜鸡的学习记录 1410

拓扑排序练习题

A题:HDU1285    题解传送门        拓扑排序模板,注意输出格式,最后没有空格 B题:POJ 2367    题解传送门         也是模板题,注意题意:第i行中的每个数字j表示j是i的后代。利用这条信息建图。每行输入以0结束 C题:UVA 10305  题解传送门         模板题。。注意输入停止条件是while(cin&gt;&gt;n&gt;&gt;m&amp...

执念 3829

平常水题 - CodeForces - 703C(二分 + 几何)

C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output And while Mishka is enjoying her trip...

dreams___的博客 627

Codeforces Round #703 (Div. 2) C interactive problem

这场div2被这个交互题打的头皮发麻。 20分钟我AC了AB两题,那是觉得这场要飞天,但开到C题的时候就懵逼了,题目是什么意思?输入是什么意思?输出又是什么鬼?%%%%% 因为这是本蒟蒻第一次写交互题,所以写这种题需要注意的点我完全不知道,于是乎出现了这个诡异的一幕:其他人拼命输出,而我却在学习what is interactive problem? 废话不多说,直接上题。 题目如下: 注释: 交互题,顾名思义就是一种通过不断给出信息,然后通过程序利用信息,最后得到答案的过程。 其不同于传统的题目,这种

weixin_50547586的博客 428

树的统计Count

题目:树的统计Count #include <vector> #include <cstdio> #include <string> #include <cstring> //#include <sstream> //#include <string.h> #include <iostream> //#includ...

多一些不为什么的坚持 647

Codeforces Round #703 (Div. 2)反思加想法

Codeforces Round #703 (Div. 2)反思加想法 题号Codeforces Round #703 (Div. 2)反思加想法ABC1&C2DE(稍后)F(稍后) A 判断总和是否大于(n-1)*n/2即可 ,本题因为忘了输入全部数据导致错了两次QAQ。 #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<vect

weixin_54560676的博客 264

Codeforces Round #703 (Div. 2)A,B,C1,C2,D

最难过的一场比赛,但也是非常有意义的一场比赛。我会永远铭记。 梦想不会止步于1500,所有打不倒我的终将使我变得更强。相信未来的我会感谢现在努力的我,正步履不停。

tcy今天长胖了吗的博客 449

Codeforces Round #703 (Div. 2)B. Eastern Exhibition

B. Eastern Exhibition 解题思路 这是个思维题想要到达各个点距离最小,首先你可以发现在二维空间里,x轴坐标与y轴坐标是互不干扰的,那么降一个维度考虑,在x轴坐标上存在多少个点到各点之间距离之和最小,在y轴坐标上存在多少个点到各点之间距离之和最小,因为x轴坐标与y轴坐标是互不干扰的,所以组合一下乘起来,那么怎么求在x轴坐标与y轴坐标有多少距离之和最小的点的个数呢,当n为奇数时取x轴坐标与y轴坐标中位数的那个点最小,奇数个数的中位数只有一个所以只存在一个点到各个点距离之和最小,偶数时中位数

菜菜的博客 198
上一篇: BestCoder Round #85 (hdu5776,hdu5777,hdu5776)
下一篇: BestCoder Round #85 (hdu5804,hdu5805,hdu5806,hdu5807)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值