The 19th Zhejiang Provincial Collegiate Programming Contest 2022浙江省赛 (A/B/C/G/L/I)

2023-11-07

https://codeforces.com/gym/103687
题解在cf旁边的Tutorial那里

A - JB Loves Math

本来是按照数的奇偶分类讨论,一直wa2,跑了个对拍
如果错了,可以考虑这几个样例。
在这里插入图片描述

由于x、y固定,所以只能考虑相差的奇偶性,而不是a、b本身的奇偶性 可以证明大转小一定能通过2步完成(+1凑奇偶 - 偶)
而小转大在相差为偶数时最少通过两步转化,关键在于凑偶数

例: 1851 6963
-> 5112 x 所以考虑拆分
-> 2556 + 2556 x
-> 2555 + 2555 + 2 x
-> 2557 + 2557 - 4 √
只能凑为 奇数 + 奇数 - 偶数(因为两个奇数必须相同)

int main() {
	IOS;
    int t;
    cin >> t;
    while(t--){
        int a, b;
        cin >> a >> b;
        int res = 0;
        if(a == b)
            res = 0;
        else if(a > b){
            if((a - b) % 2 == 0)
                res = 1;
            else
                res = 2;
        }
        else {
            if((b - a) % 2)
                res = 1;
            else if((b - a) / 2 % 2)
                res = 2;
            else
                res = 3;
        }
        cout << res << endl;
    }
    return 0;
}

B - JB Loves Comma

还特地判了结尾不加’,'结果wa掉,根本不用判

int main() {
	IOS;
	string s;
	cin >> s;
	if(s.find("cjb") == string::npos){
		cout << s;
	}
	else {
		while(1){
			int id = s.find("cjb");
			if(id == -1 || s.size() == 0)
				break;
			string temp = s.substr(0, id + 3);
			cout << temp;
			s = s.substr(id + 3, s.size());
				cout  << ',';
		}
		cout << s;
	}
	return 0;
}

C - JB Wants to Earn Big Money

水题

int main() {
	IOS;
	int n, m, k;
	cin >> n >> m >> k;
	int ans = 0;
	for (int i = 0; i < n; ++i){
		int t;
		cin >> t;
		if(t >= k)
			++ans;
	}
	for (int i = 0; i < m; ++i){
		int t;
		cin >> t;
		if(t <= k)
			++ans;
	}
	cout << ans;
	return 0;
}

G - Easy Glide

G比L好想,还是没想出来哈。想到贪心,求所有点到起点和终点的距离,然后选代价最小的,卡在了如何选择两两之间代价最小的情况,因为中间有点会断掉(超过3s)

朴素dij…

错麻了,一直wa6 -> wa34,存一下,到时候再来改
服了,这破精度

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include<climits>
#define IOS ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
using namespace std;

const int maxx = 1e4 + 5;
const int maxn = 1e6 + 5;

#define N 10000100
#define ll long long
#define endl '\n'
const ll  mod = 998244353;
#define test printf("--------------------------\n");
#define re(a) memset((a), 0, sizeof((a)))
#define remax(a) memset((a), 0x3f3f3f3f, sizeof((a)))
#define PII pair<int, int>

pair<ll, ll> p[maxn];
double v1, v2;
ll n;
double t[1100][1100]; //每一个点到每一个点的用时
vector<ll> v[maxn];

void dij(int j){
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
    q.push({0, 0});
    double dist[1100];
    bool vis[1100];
    re(vis);
    fill(dist, dist + 1100, LLONG_MAX);
    dist[0] = 0;
    while(!q.empty()){
        int now = q.top().second;
        q.pop();
        if(vis[now])
            continue;
        vis[now] = true;
        for(auto w : v[now]){
            if(dist[w] > dist[now] + t[now][w]){
                dist[w] = dist[now] + t[now][w];
                q.push({dist[w], w});
            }
        }
    }
    printf("%f", dist[n + 1]);
}

double timee(int i, int j){//i -> j
	ll tem = 1ll * (p[i].first - p[j].first) * 1ll * (p[i].first - p[j].first) + 1ll * (p[i].second - p[j].second) * 1ll * (p[i].second - p[j].second);
	double temp = sqrt(tem);//长度
	double tt;
	if(i == 0 || i == n + 1){//没有加速功能
		tt = temp / v1;
	}
	else {
		double te = temp - 3.0 * v2;
		if(te > 0) {
			tt = 3.0 + te / v1;
		}
		else
			tt = temp / v2;
	}
	return tt;
}
int main() {
	IOS;
    cin >> n;
	for (int i = 1; i <= n; ++i){
		cin >> p[i].first >> p[i].second;
	}
	cin >> p[0].first >> p[0].second;
	cin >> p[n + 1].first >> p[n + 1].second;
	cin >> v1 >> v2;
    for (int i = 0; i <= n + 1; ++i){
        for (int j = 0; j <= n + 1; ++j){
            if (i == j)
                continue;
            t[i][j] = timee(i, j);//i -> j
            v[i].push_back(j);
        }
    }
	dij(0);
	return 0;
}

L - Candy Machine

犹豫了下不可能这么简单吧果然wa9
又去翻译了题,考虑过一个一个放进去,小的一定可以加在这个子集里,马上推翻

从子集里挑选比子集平均数大的数,题反复没读懂…
这题只有二分+前缀和做法

先贪选取整个集合,再更新,可以证明去掉一个最大数一定可以使整体变小,能选取的数可能会更多;找截取部分大于平均数的下标,算能选多少个

ll a[maxn];
int main() {
	IOS;
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a + 1, a + 1 + n);
	ll ans = 0, j = 0;
	ll avr = sum / n;
	ans = n - (upper_bound(a + 1, a + 1 + n, avr) - (a + 1));
	for (int i = n; i > 1; --i) {
		sum -= a[i];
		avr = sum / (i - 1);
		//cout << avr << " ";
		j = i - (upper_bound(a + 1, a + i, avr) - (a + 1)) - 1;
		//cout << j << endl;
		ans = max(ans, j);
	}
	cout << ans;
	return 0;
}

#M - BpbBppbpBB
第一判断:连通图( + 判格子形状),但存在一点问题
一看题解,啊解方程?!

I - Barbecue

觉得应该是先找回文串在哪然后减去回文长度%2判,但是,该去补马拉车了
好厉害,这题用hash处理只需要o(1)
https://www.cnblogs.com/Uninstalllingyi/p/11191045.html
O(1)字符hash板子题

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include<cmath>
#include<stack>
#include<queue>
#define IOS ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
using namespace std;

const int maxx = 1e4 + 5;
const int maxn = 1e6 + 5;

#define N 10000100
#define ll long long
#define endl '\n'
const ll  mod = 998244353;
#define test printf("--------------------------\n");
#define re(a) memset((a), 0, sizeof((a)))
#define remax(a) memset((a), 0x3f3f3f3f, sizeof((a)))
#define PII pair<int, int>
vector<int> v;

#define ull unsigned long long
ull p = 13331;
ull hash_a[maxn], hash_b[maxn], power[maxn];

void init(string s, int len){
    hash_a[0] = 0, hash_b[0] = 0, power[0] = 1;
    for (int i = 1; i <= len; ++i){
        hash_a[i] = hash_a[i - 1] * p + (s[i] - 'a');
        hash_b[i] = hash_b[i - 1] * p + (s[len - i + 1] - 'a');
        power[i] = power[i - 1] * p;
    }
}

bool part_judge(int l, int r, int len){
    ull ta = hash_a[r] - hash_a[l - 1] * power[r - l + 1];
    ull tb = hash_b[len - l + 1] - hash_b[len - r] * power[r - l + 1];
    return ta == tb;
}

int main() {
	IOS;
	// freopen("P1908_6.in","r",stdin);//读入数据
	// freopen("P1908.out","w",stdout); //输出数据
    int len, q;
    cin >> len >> q;
    string s;
    cin >> s;
    s = " " + s;
    init(s, len);
    for (int i = 1; i <= q; ++i){
        int l, r;
        cin >> l >> r;
        if(part_judge(l, r, len)){
            cout << "Budada" << endl;
        }
        else {
            if((r - l + 1) % 2){
                cout << "Putata" << endl;
            }
            else {
                cout << "Budada" << endl;
            }
        }
    }
        return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

The 19th Zhejiang Provincial Collegiate Programming Contest 2022浙江省赛 (A/B/C/G/L/I) 的相关文章

随机推荐

  • 软件测试流程/需求分析之软件需求概述

    今天重点从四个方面来和大家对需求阶段需求分析做一个讲解 阅读测试文档 参与需求评审 测试需求分析 提取功能点 去做这些对应的事情之前 我们要先了解到底什么是需求 需求评审我们要从哪些点去评审 我们要去提取功能点要怎么样去进行提取 回忆测试流
  • 使用ffmpeg将mkv,rmvb转换成mp4

    cmd输入ffmpeg version 检查ffmpeg安装版本 1 进入mkv rmvb所在的文件夹 2 转换mkv ffmpeg i inputname mkv c v copy c a copy outputname mp4 转换rm
  • 几种优化算法(求最优解)

    几种优化算法 先简单备注下 今后接触到再看 参考资料 http blog sina com cn s blog 6a1bf1310101hhta html
  • SpringBean管理

    一 什么是SpringBean 在Spring中将管理对象称为 Bean Bean是由一个SpringIOC容器实例化 组装和管理的对象 也就是说 Bean并不是由我们程序员编写的 而是在程序运行过程中 由Spring通过反射机制生成的 S
  • 串口通信开发

    一开始做串口通信开发时 觉得并不难 无非就是发送 然后等一会 再接收就完事了 其实里面的水很深 特别是在各种设备都有的情况下 我们在整个开发过程中 遇到了以下的几个主要问题 1 设备出现严重的延迟 2 接收过程出现数据粘包或截断 3 多设备
  • 华为OD机试-目录删除

    Online C compiler to run C program online include
  • 解决错误:Plugin with id 'com.android.application' not found

    本文转载地址 https blog csdn net qq 26819733 article details 50935632 Error 1 0 Plugin with id com android application not fou
  • C++中的转移字符

    C 中转移字符 顺序 描述 表示 单引号 字节0x27 ASCII编码 双引号 字节0x22 ASCII编码 问号 字节0x3f ASCII编码 反斜线 字节0x5c ASCII编码 a 可听见钟 字节0x07 ASCII编码 b 退格 字
  • 深度学习方法在道路提取、图像检索上的几篇文章阅读笔记

    关于全卷积神经网络的upsampling还没有搞清楚 如果你有合适的资料或者好方法 欢迎评论交流 深度学习方法在道路提取上的应用1 传统方法 A review of road extraction from remote sensing i
  • Siebel Open UI

    阅读原文 http blog sina com cn s blog 70ea5c9101017qi4 html Open UI最常提到的特性是 W3C标准兼容 可在任何符合标准的浏览器上使用 可跨多种形式的因素 客户端JavaScript框
  • ESP32上实现LVGL的界面显示

    提示 文章写完后 目录可以自动生成 如何生成可参考右边的帮助文档 文章目录 前言 一 元器件 二 导入库 三 调试TFT eSPI 四 调试LVGL 总结 前言 基于Vscode中的 PlatformIO平台arduino框架 使用1 8
  • nrm安装报错,解决方案

    nrm安装报错 下方为错误信息 C Users kefu gt nrm version internal validators js 124 throw new ERR INVALID ARG TYPE name string value
  • vue-codemirror设置输入自定义提示效果

    概要 提示 通过使用 vue codemirror 4 0 6 实现输入提示 类似于vscode提示效果 效果图 实现原理 1 得到光标位置 定义提示内容 handleShowHint 获取输入框实例 const cmInstance th
  • 列表和元组

    1序列概述 序列是Python中最基本的数据结构 序列中的每个元素都分配一个数字 它的位置 或索引 第一个索引是0 第二个索引是1 依此类推 Python中 常见序列有列表 元组 字符串 序列可以进行的操作 有索引 切片 加 乘 检查成员
  • yolact模型测试(一)

    YOLACT时2019新出的用于实例分割的深度学习模型 在一番环境配置后成功复现了yolact 针对改进版的YOLACT 我还未尝试 下面简单的测试了yolact模型中对mask的处理 当然限于时间精力的有限 本文是针对一个博主的一篇文章
  • Hibernate之@Id详解

    给实体的一个属性标识为数据库表中的主键时 可以使用 Id public class Student private Integer id Id public Integer getId return id public void setId
  • Android studio中Custom View使用方法

    Android studio的好处 这里就不错过多的说明了 studio中内置了很多的模版可供使用 大大的简化了工作量 在实际开发中 android自带的各类控件可能无法满足我们的需求 这就需要我们自定义控件 下面介绍一下Custom Vi
  • google 浏览器出现 ERR_PROXY_CONNECTION_FAILED 无法访问网络

    1 问题 早上来公司突然发现谷歌浏览器访问所有的东西都出现 ERR PROXY CONNECTION FAILED 网络不可用的提示 这一串的单词的意思是 代理连接失败 真的是一脸懵逼 经过一番百度后发现是网络代理作的妖 2 解决方法 其实
  • 安卓移动应用开发之从零开始写程序6

    实验六 记事本小项目的实现 一 由于项目相对来说比较中等 所以我分为两个实验来介绍给大家 本次实验实现最终效果图如下 实现除保存按钮外的按钮监听以及界面的布局文件 主界面 显示笔记的内容和编辑的时间 里面有一个添加按钮 添加笔记界面 返回按
  • The 19th Zhejiang Provincial Collegiate Programming Contest 2022浙江省赛 (A/B/C/G/L/I)

    https codeforces com gym 103687 题解在cf旁边的Tutorial那里 A JB Loves Math 本来是按照数的奇偶分类讨论 一直wa2 跑了个对拍 如果错了 可以考虑这几个样例 由于x y固定 所以只能