2019浙江省赛部分题解

2019 浙江省赛部分题解(The 16th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple) Problem A http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4100 题意: 以连通块中元素个数为权值,建立线段树,维护三个变量,分别是cnt(这样的连通块的数量),sum(连通块的总的点数),pfh(各连通块之间点数的平方和)(注意不是和的平方) cnt代表连通块数量,tot_ret代表当前状态下的图,在不增长连... 阅读详情

B

题解

https://blog.youkuaiyun.com/Cassie_zkq/article/details/89607552

#include <bits/stdc++.h>
using namespace std;
#define FOR0(a,b) for(ll i = a; i < b; ++i)
#define FORE(a,b) for(ll i = a; i <= b; ++i)
typedef long long ll;
typedef pair<ll,ll> pii;
const ll maxn = 1e5+5;

vector<ll> v[maxn];
ll a[maxn],b[maxn];
ll gcd(ll a, ll b) {
    return b == 0? a : gcd(b,a%b);
}
int main() {
    ll T;
    scanf("%lld", &T);
    while(T--) {
        ll n;
        ll x,y;
        for(int i = 1; i <= 100000; ++i)
            v[i].clear();
        scanf("%lld%lld%lld", &n, &x, &y);
        for(ll i = 1; i <= n; ++i) {
            scanf("%lld", &a[i]);
            b[i] = a[i];
            v[a[i]].push_back(i);
        }
        sort(b+1,b+1+n);
        ll tot = unique(b+1,b+1+n)-b-1;
        ll ox = 0, oy = 0;
        for(ll i = 1; i <= n; ++i) {
            ox += i*a[i];
            oy += i*a[i]*a[i];
            // cout << a[i] << endl;
        }
        // cout << ox <<" " << oy << endl;
        ll ans = 0;
        if(x-ox == 0) {
            if(y != oy) {
                puts("0");
                continue;
            } 
            for(ll i = 1; i <= tot; ++i) {
                ll t = v[b[i]].size();
                ans += t*(t-1)/2;
                // v[b[i]].clear();
            }
            cout << ans << endl;
        } else {
            // cout << x-ox <<" "<< y-oy << endl;
            if(gcd(x-ox, y-oy) != x-ox) {
                puts("0");
            }else {
                ll t = (y-oy)/(x-ox);
                // cout << t << endl;
                for(ll i = 1; i<= n; ++i) {
                    ll ai = a[i], aj = t-ai;
                    if(aj == ai) continue;
                    ll j = i-(x-ox)/(aj-ai);
                    if(j <= i) continue;
                    // cout << ai <<" " << aj << " " << j << endl;
                    // if(ai == aj) continue;
                    if(a[j] == aj) ans++;
                }
                cout << ans << endl;
            }
        }
    }
    return 0;
}

C

题解

当一个数出现 > n/2 次,那肯定是Impossible。否则必定有解。

3 2 1 5 4 4 4 4 7
手动模拟这个例子,很快可以得出
3 2 1 5 4 4 4 4 7
1 3 2 4 5 7 x x x
我们发现此时只有4能填,但是这个位置又不能填4,那么就得找一个位置去填这个4,很明显,在这个位置之前的我们按照贪心思路填的是最优的,没有到万不得已绝对不会去改变它,所以我们找此刻位置之后的能填4的,序列变成
3 2 1 5 4 4 4 4 7
1 3 2 4 5 7 x x 4
此时都后面能填的都填了,没有办法了,已经到了万不得已的情况了,就只能动前面的了,贪心的想,肯定是动越靠后越优,并且此时上方和下方都不能是4。所以我们可以取3 2来填,并且这个3 2应该按字典序最小的填(不按字典序也可以,往下看就知道了)。 序列变成
3 2 1 5 4 4 4 4 7
1 4 4 4 5 7 2 3 4
这种情况满足了条件,但并没有满足最小,此时对于4这些位置我们并不是按贪心思路填下去的,所以应该再把4的这些位置重排序一下,序列变成
3 2 1 5 4 4 4 4 7
1 4 4 4 2 3 5 7 4
这便是最优解。

代码

#include <bits/stdc++.h>
using namespace std;
#define FOR0(a,b) for(int i = a; i < b; ++i)
#define FORE(a,b) for(int i = a; i <= b; ++i)
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e5+5;

int cnt[maxn], a[maxn], ans[maxn];
set<int> vis;
vector<int> va[maxn];
vector<int> vb[maxn];
int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        int n;
        vis.clear();
        scanf("%d", &n);
        memset(cnt,0,sizeof cnt);
        bool flag = true;
        for(int i = 0; i < n; ++i) {
            scanf("%d", &a[i]);
            cnt[a[i]]++;
            if(cnt[a[i]] > n/2) flag = false;
            vis.insert(a[i]);
            ans[i] = 0;
        }
        if(!flag) {
            puts("Impossible");
            continue;
        }

        vector<int> v1,v2;
        for(int i = 0; i < n; ++i) {
            set<int> :: iterator it = vis.begin();
            
            if(*it == a[i] && vis.size() == 1) {
                for(int j = i+1; j < n; ++j) {
                    if(a[j] != a[i]) {
                        ans[j] = a[i];
                        cnt[a[i]]--;
                    }
                }
                for(int j = i; j < n; ++j) {
                    if(ans[j] == 0 && a[j] == a[i]) {
                        v1.push_back(j);

                    }
                }
                for(int j = i-1; j >= 0; --j) {
                    if(cnt[a[i]] == 0) break;

                    if(ans[j] != a[i] && a[i] != a[j]) {
                        v2.push_back(ans[j]);
                        ans[j] = a[i];
                        cnt[a[i]]--;
                    }
                }
                for(int j = 0; j < v1.size(); ++j) {
                    ans[v1[j]] = v2[j];
                }
                vis.erase(it);
                v1.clear(); v2.clear();
                break;
            } else {
                if(*it == a[i]) {
                    ++it;
                }
                ans[i] = *it;
                cnt[*it]--;
                if(cnt[*it] == 0)
                    vis.erase(it);
            }
        }
        for(int i = 0; i < n; ++i) {
            va[a[i]].push_back(i);
            vb[a[i]].push_back(ans[i]);
        }
        for(int i = 1; i <= n; ++i) {
            if(va[i].size() == 0) continue;
            sort(va[i].begin(), va[i].end());
            sort(vb[i].begin(), vb[i].end());
            for(int j = 0; j < va[i].size(); ++j)
                ans[va[i][j]] = vb[i][j];
            va[i].clear(); vb[i].clear();
        }
        for(int i = 0; i < n; ++i)
            if(i == 0) printf("%d", ans[i]);
            else printf(" %d", ans[i]);
        puts("");
    }
    return 0;
}

E

zoj 4101

题解

从左到右遍历,找出不满足从最左端开始的非降序列的值中的最大值val,以及最先出现的位置pos,对于 < val的值都需要一次操作放到最前面,对于=val的,在pos后面出现的都需要一次操作放到最前面。

#include <bits/stdc++.h>
using namespace std;
#define FOR0(a,b) for(int i = a; i < b; ++i)
#define FORE(a,b) for(int i = a; i <= b; ++i)
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+5;

int a[maxn],b[maxn];
int n;
int find(int x) {
	int l = 1, r = n, ans = 0;
	while(l <= r) {
		int mid = (l+r)>>1;
		if(a[mid] <= x) {
			l = mid+1;
			ans = mid;
		} else 
			r = mid-1;
	}
	return ans;
}
int main() {
	int T;
	scanf("%d", &T);
	while(T--) {
		scanf("%d", &n);
		for(int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			b[i] = a[i];
		}
		int pre = 0;
		int mx = 0;
		int pos = n;
		for(int i = 1; i <= n; ++i) {
			if(a[i] >= pre) {
				pre = a[i];
			} else {
				if(mx < a[i]) {
					mx = a[i];
					pos = i;
				}
			}
		}
		sort(a+1,a+1+n);
		int ct = 0;
		int ans = 0;
		ans = find(mx-1);

		for(int i = pos; i <= n; ++i) {
			if(mx == b[i]) {
				ct++;
			}
		}
		cout << ans + ct << endl;
	}
	return 0;
}

K

zoj 4110

题解

考虑可以经过一次翻转的情况
即s和t中只有一段[l,r]是不相同的,并且这一段经过翻转之后要一模一样,否则就无解。

[l,r]是必须翻转的,但是可以向两边扩散,条件就是 s l − i = = s r + i s_{l-i} == s_{r+i} sl−i​==sr+i​。

分情况讨论:

  1. s == t,那么对于每个字符其最长的回文子串的半径就是对答案的贡献。采用马拉车可以O(n)算出。
  2. s != t,若可行,那么直接暴力从l,r向两边扩展。

代码

#include <bits/stdc++.h>
using namespace std;
#define FOR0(a,b) for(int i = a; i < b; ++i)
#define FORE(a,b) for(int i = a; i <= b; ++i)
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=2000010;
char str[maxn];//原字符串
char str2[maxn];
char tmp[maxn<<1];//转换后的字符串
int Len[maxn<<1];
//转换原始串
int INIT(char *st)
{
    int i,len=strlen(st);
    tmp[0]='@';//字符串开头增加一个特殊字符,防止越界
    for(i=1;i<=2*len;i+=2)
    {
        tmp[i]='#';
        tmp[i+1]=st[i/2];
    }
    tmp[2*len+1]='#';
    tmp[2*len+2]='$';//字符串结尾加一个字符,防止越界
    tmp[2*len+3]=0;
    return 2*len+1;//返回转换字符串的长度
}
//Manacher算法计算过程
ll MANACHER(char *st,int len)
{
     int mx=0,po=0;
     ll ans=0;//mx即为当前计算回文串最右边字符的最大值
     for(int i=1;i<=len;i++)
     {
         if(mx>i)
         Len[i]=min(mx-i,Len[2*po-i]);//在Len[j]和mx-i中取个小
         else
         Len[i]=1;//如果i>=mx,要从头开始匹配
         while(st[i-Len[i]]==st[i+Len[i]])
         Len[i]++;
         if(Len[i]+i>mx)//若新计算的回文串右端点位置大于mx,要更新po和mx的值
         {
             mx=Len[i]+i;
             po=i;
         }
         ans += Len[i]/2;
     }
     return ans;
 }

int main() {
	int T;
	scanf("%d", &T);
	while(T--) {
		scanf("%s", str);
		scanf("%s", str2);
		if(strcmp(str,str2) == 0) {
			int len = INIT(str);
			printf("%lld\n", MANACHER(tmp,len));
		} else {
			int l = -1, r = -1;
			int len = strlen(str);
			for(int i = 0; i < len; ++i) {
				if(str[i] != str2[i]) {
					if(l == -1)
						l = i;
					r = i;
				}
			}
			// cout << l << " " << r << endl;
			bool flag = true;
			for(int i = l; i <= r; ++i) {
				// cout << str[i] << " "<< str2[r-i+l] << endl;
				if(str[i] != str2[r-i+l]) {
					flag = false;
					break;
				}
			}
			if(flag == false) {
				puts("0");
				continue;
			}
			int cnt = 1;
			for(int i = l-1, j = r+1; i >= 0 && j < len && str[i] == str[j]; --i, ++j) cnt++;
			printf("%d\n", cnt);
		}

	}
	return 0;
}
2022CCPC浙江省赛题解ABCGILM 阅读详情

相关推荐

2019浙江省程序设计竞赛赛后总结+题解

目录 【总结】 【题解】 【...】 啊终于回来惹 因为太菜所以先来做个赛后总结再回去。 【总结】 前十分钟内我和hmj1A了两道手速题GF,感觉是一个好的开始然后开始陷入自闭期...卡在E题和I题qaq,我按和cc讨论的做法E题wa了两发,然后开始思考做法的问题出在哪里,hmj读懂I题后和cc找大数板子(根本没必要大数啊我靠,队友好傻啊呜呜呜),嫌太长开始写java,...

菜鸡成长史 1141

2019 第十六届浙江省赛部分题解

A:Vertices in the Pocket DreamGrid has just found an undirected simple graph with n vertices and no edges (that's to say, it's a graph with n isolated vertices) in his right pocket, where the vertice...

qq_41529799的博客 1572

蓝桥杯省赛 C/C++ ABC组题解(第四届 ~ 第十二届)

第十届蓝桥杯 题号 C++ A组 C++ B组 C++ C组 试题A 平方和 组队 求和 试题B 数列求值 年号字串 矩形切割 试题C 最大降雨量 数列求值 年号字串 试题D 迷宫 数的分解 质数 试题E RSA解密 迷宫 最大降雨量 试题F 完全二叉树的权值 特别数的和 旋转 试题G 外卖店优先级 完全二叉树的权值 外卖店优先级 试题H ...

六级不考550+不改名 1万+

2019年第16届ICPC浙江省省赛 解题报告

A Vertices in the Pocket 线段树+二分,待补 B Element Swapping 如果(i,j)是答案,那么容易得到 两式相除得到a[i]+a[j],然后针对右式是否为0的情况讨论一下,再根据第一个式子判断一下。 代码: #include<bits/stdc++.h> #define ll long long #define ...

LSD20164388的博客 2269

浙江省历年高等数学竞赛试题

工科类的试卷(有答案跟详细解释)只有08-10年的,其余的比较杂,都是在网站上收集,从02年-10年,有数学系的,有文科类的等等。

Unity游戏开发实战:用Flow Field实现RTS百人军团流畅寻路(附完整代码)

本文深入探讨了在Unity中利用流场寻路技术解决RTS游戏大规模单位移动性能瓶颈的实战方案。通过解析从Dijkstra算法生成成本场、积分场到最终向量场的核心原理,并结合分块、缓存及与DOTS/ECS架构集成的优化策略,实现了百人军团的流畅群体寻路。文章提供了完整的代码示例,助力开发者构建高性能的RTS寻路系统。

weixin_28363123的博客 587

2019 16th浙江省省赛部分题解

B -Element Swapping DreamGrid has an integer sequenceand he likes it very much. Unfortunately, his naughty roommate BaoBao swapped two elementsand() in the sequence when DreamGrid wasn't at...

why932346109的博客 3206

S32K3 MCAL配置 【MCU、PORT、DIO】

1、s32k3时钟源可由PLL, FXOSC, FIRC, SIRC, and SXOSC五种时钟源生成,可按照手册推荐配置。目标是在在S32K344板子上点亮红色LED灯,需要配置的有MCU、PORT、DIO模块。MCU最主要的是时钟配置,要翻看芯片手册,理解时钟树。1、通用配置中,没有什么特殊需求按照demo配置就好。1、配置MC_CGM mux 0 clocks时钟。1、外部晶振配置按照实际项目原理图进行配置。1、外部晶振配置,按照实际项目配置。1、PLL时钟按照手册进行配置。

weixin_43741076的博客 3243

2019 浙江省赛 ACM 部分题解(E H I K)

练习 链接。 E Sequence in the Pocket 大意 :给定n个数,每次可以选定一个数放到这n个数的最前面,问 经过最少多少次 操作 可以形成一个 严格非递减 的序列(既在每一个数的右侧都不会出现比他小的数)。 思路 : 从右向左看,先找到最大的数,然后找到次大的,再找第三大的。。。一直找到最左端 这是会找到 第 cnt 大的数,输出n-cnt 即可。 DreamGrid has...

qq_43559193的博客 723

Linux文件操作四剑客

① /^(d{2}|d{4})-((0([1-9]{1}))|(1[1|2]))-(([0-2]([1-9]{1}))|(3[0|1]))$/ // 年-月-日 yyyy-MM-dd / yy-MM-dd 格式。⑥“^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$” //正浮点数。

wuds_158的博客 1609

CentOS8静默安装Oracle11.2.0.1

背景 新安装oracle,用静默安装方式就不需要安装图形界面了,省时省力。 前期准备工作与图形化安装一样,如创建用户|用户组、环境变量、内核参数、创建目录等. 可参考图形化安装,链接:https://blog.youkuaiyun.com/heroicpoem/article/details/104229369 环境 平台 版本 操作系统 centOS 8 Oracle 11gR2 1.响应文件 响应文件的内容就是图形化安装时手工设置的选项内容。 解压后,database/response/db

heroicpoem的专栏 4518

2019年浙江省第十六届省赛部分题解--The 16th Zhejiang Provincial Collegiate Programming Contest

F、Abbreviation WA+3(。。。 第一发:CE,交成了C!!! 第二发:scanf("%d",&t);while(t--)写成了while(~scanf("%d",&t))!!! 第三发:输出换行错误!!! E、Sequence in the Pocket 题意: DreamGrid has just found an integer sequence...

AAAAAAAC的博客 1460

Codev与Zemax相互转化

Codev与Zemax相互转化

weixin_72050316的博客 1043

2021浙江省赛题解(A,C,F,G,J,L,M)

2021浙江省赛题解(A,C,F,G,J,L,M) A.League of Legends 题解 签到题 直接求和判断一下 注意会爆intintint以及相等的情况。 代码 #include <bits/stdc++.h> #define PI atan(1.0)*4 #define rp(i,s,t) for (register int i = (s); i <= (t); i++) #define RP(i,t,s) for (register int i = (t); i >=

mumei的博客 4556

使用 Simulink 搭建一个地震信号反射系数反演与滤波联合仿真的系统模型

《Simulink地震信号处理仿真指南》摘要:本文详细介绍了使用Simulink进行地震信号反射系数反演与滤波联合仿真的完整流程。从创建模型、生成含噪合成地震记录(包含子波卷积与随机反射系数),到设计滤波模块(带通/小波/自适应滤波)和实现反演算法(Wiener-Hopf方程/RLS方法),最后通过可视化模块分析结果。教程涵盖理论准备、7个实施步骤、优化建议及实际应用场景,为地震勘探、地质调查等领域提供标准化的信号处理仿真方案,特别适合需要掌握地震信号反演与实时滤波技术的工程人员学习。

amy_mhd的博客 113

为什么 CL_DEMO_OUTPUT 不能用于生产用途:不仅是 demo 标签那么简单

摘要:CL_DEMO_OUTPUT 虽能快速展示ABAP数据,但存在严重生产风险:1) 官方定位为示例工具,不承诺兼容性与支持;2) 非Released API,云环境直接不可用;3) 依赖SAP GUI,缺乏日志关键特性;4) 存在版本漂移、类型限制、性能隐患及安全缺口。典型事故案例包括后台Job崩溃、Gateway链路污染和云迁移失败。生产环境应改用结构化日志(如SLG1)或稳定API输出,避免将调试工具误作工程方案。(149字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 131

Sequence in the Pocket(2019浙江省省赛)(找规律)

Sequence in the Pocket(找规律) Time Limit: 2000 ms Memory Limit: 65536 KB Description DreamGrid has just found an integer sequence a1,a2,…,ana_1, a_2, \dots, a_na1​,a2​,…,an​ in his right pocket. As Drea...

画船听雨眠 457

Android插件化和组件化面试题及参考答案

如何使用 Gradle 来管理 Android 项目中的模块依赖? Gradle 是一个强大的构建工具,在 Android 项目中管理模块依赖主要通过以下方式。 首先,在项目的根目录下的 build.gradle 文件中,需要配置仓库。一般会添加如 Google 的 Maven 仓库和 JCenter 等,例如在 repositories 部分添加: repositories { google() jcenter() } 对于模块依赖,在每个模块(例如 app

大模型大数据攻城狮的专栏 1184

2025 浙江省赛题解(部分)

补提链接: https://qoj.ac/contest/2021?v=1<1>题目大致含义:操控一个机器人, 要求从起点到达终点然后返回起点,并且此过程中每个位置都要达到指定的次数。每次操作可以向右(视为'R')或者向左走一格(视为'L'),问是否存在返回到起点的结果,如果存要求输出字典序最小的方案,不能则输出Impossible .数据范围:测试总的位置数为, 对应位置数的次数和为 <2>思路: 从抽象角度看待次数变化:观察发现每个位置次数消耗值由相邻位置贡献。(1)不妨设当前位置要达到的次数为

2403_88622568的博客 481

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

浙江省赛部分题解

Sequence in the Pocket DreamGrid has just found an integer sequencein his right pocket. As DreamGrid is bored, he decides to play with the sequence. He can perform the following operation any numbe...

curry___的博客 468

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

2018 浙江省赛

目录 A.Peak B - King of Karaoke J - CONTINUE...? L - Doki Doki Literature Club M - Lucky 7 A.Peak 【题意】 给出的数组的元素大小,是否符合只有一个先上升在下降的趋势 #include <cstdio> #include <algorithm> #includ...

欢迎访问方偲的博客 520

Camera2Demo

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

2015ACM浙江省省赛部分题解

The 12th Zhejiang Provincial Collegiate Programming Contest总体感觉题目有大概7道不涉及算法的题目。听群里讨论,现场赛有队伍一小时ac了7道题目。不过对于本弱,还是挺艰难的。A    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3869Ace of AcesTim

chaideyipi 3219

2019各省省选试题选做及简要题解

有链接的表示详细题解的坑填了 NOI2019 Day1T1 回家路线 Day1T2 机器人 Day1T3 序列 Day2T1 弹跳 Day2T2 斗主地 Day2T3 I 君的探险 APIO2019 CTS2019 Day1T1 随机立方体 Day1T2 珍珠 Day1T3 无处安放 Day2T1 田野 Day2T2 重复 Day2T3 氪金手游 十二省联考2019 Day1T1 异或粽...

weixin_30568715的博客 652

第六届浙江省赛题解(部分)

第六届浙江省赛题解 A. Second-price Auction 题目链接 题目大意 有n个投标者,投标最高的获得物品,需要支付第二投标者的价格. 解题思路 使用结构体,保存投标的价格和一开始的排序. 然后根据投标价格排序,使用sort就可以了 AC代码 #include&lt;cstdio&gt; #include&lt;cstring&gt; #incl...

无知而狂妄 368

浙江省11届省赛部分题解

ZOJ 3776A题: #include #include #include #include #include #include #include #include using namespace std; #define N 1005 int n, m; int main(){ int T;scanf("%d",&T); int i, j; while(T--){ scanf("%

九野的博客 2045
上一篇: 【字符串算法】马拉车算法
下一篇: 【数学期望】期望dp
Link_Ray
博客等级 码龄9年 44粉丝 156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值