SMU Spring 2023 Contest Round 1(MINEYE杯第十六届华中科技大学程序设计邀请赛)
B. Contest Preparation
对n<=m和n==0时特判一下
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 1e5 + 10, mod = 1e6;
//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
int ans;
/*
*/
void solve()
{
cin >> n >> m;
if( !n ){
cout << 0 << endl;
return;
}
if(n > 0 && n <= m){
cout << 2 << endl;
return ;
}
cout << (n * 2 + m - 1) / m << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
cin >> Ke_scholar;
//cin.ignore();
while(Ke_scholar--)
solve();
return 0;
}
D. Difference
参考题解:D Difference (二分 + 单调队列) - Yaqu - 博客园 (cnblogs.com)
由于答案数据范围较大,可以考虑二分答案,要求一个区间的最大最小值,可以采用单调队列,对于每一个要求[l,r]值肯定大于[l-1,r],其max-min也一定大于后一个区间,所以我们可以对于固定的r去找他满足条件的左端点的最右值相加给ans就能得到大于等于k的区间数.
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 1e5 + 10, mod = 1e9 +7; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
int ans;
void solve()
{
cin >> n >> k;
vector<int> v(n + 1);
for(int i = 1;i <= n ;i ++){
cin >> v[i];
}
auto check = [&](int x){
deque<int> dqmin,dqmax;
int l = 1, ans = 0;
for(int i = 1;i <= n;i ++){
while(!dqmin.empty() && v[dqmin.back()] >= v[i])
dqmin.pop_back();
dqmin.push_back(i);
while(!dqmax.empty() && v[dqmax.back()] <= v[i])
dqmax.pop_back();
dqmax.push_back(i);
while(l <= i && (v[dqmax.front()] - v[dqmin.front()]) * (i - l + 1) >= x){
if(dqmax.front() == l)
dqmax.pop_front();
if(dqmin.front() == l)
dqmin.pop_front();
l++;
}
ans += l - 1;
}
return ans >= k;
};
int l = 1, r = 1e18,mid;
while(l <= r){
mid = (l + r) >> 1;
if(check(mid))
l = mid + 1;
else
r = mid - 1;
}
cout << r << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar ;
while(Ke_scholar--)
solve();
return 0;
}
K. Triangles
对于每一个格子被对角线平分后都能有两个个三角形(开始初始的为1,最后乘2即可),由于数据范围较小,可以直接双for去dp一下
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 510, mod = 1e6;
//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
int ans;
int f[N][N];
/*
*/
void solve()
{
cin >> n;
for(int i = 0;i < n;i ++){
int x,y;
cin >> x >> y;
f[x][y] = 1;
}
for(int i = 0;i < N;i++){
for(int j = 0; j < N;j++){
if(f[i][j])
f[i][j] += f[i - 1][j - 1];
}
}
int ans = 0;
for(int i = 0;i < N;i ++)
for(int j = 0;j < N;j ++)
ans += f[i][j];
cout << ans * 2 << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar;
//cin.ignore();
while(Ke_scholar--)
solve();
return 0;
}
M. XOR Almost Everything
当n为偶数时,一定可以全变为0,当n为奇数时,就将所有数异或起来,若为0,则YES,否则NO.
推倒:
我们可以先通过n次操作把数组全变成相同的一个数,我们下标从i=0取到i=n-1,y就选arr[i]。为什么这样可以使得数组变成相同的一个数?因为这样就相当于使得数组中的每一个数,将除了自己以外的元素都进行了异或运算。这样得到的一个数就是arr[0]^arr[1]^arr[2]……^arr[n-1]。这样每个数都会是相同的,而且这个数就是这个式子得到的结果。
异或运算有两个性质:异或自己就相当于把自己变成0;异或同一个数两次就相当于没异或。
我们再取下标i=0到i=n-1进行操作,y就取arr[0]^arr[1]^arr[2]……^arr[n-1],即现在数组都相同的那个数,这样会使得数组每个元素进行了n-1次运算,当n-1是偶数时,相当于没异或,数组的值不变;当n-1是奇数时,相当于每个元素都异或了一下自身,变成0.
所以当n-1是奇数时,我们必然能把数组变成全是0;而n-1是偶数时,数组的值不会改变,除非arr[0]^arr[1]^arr[2]……^arr[n-1]等于0,这样在一开始把数组变成相同的时候数组就全是0了,其余情况都不能把数组变成0.
原题解:HUSTPC 2022:M、XOR Almost Everything - 掘金 (juejin.cn)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 1e5 + 10, mod = 1e6;
//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
int ans,a[N];
/*
*/
void solve()
{
cin >> n;
for(int i = 1;i <= n; i++){
cin >> a[i];
ans ^= a[i];
}
if(ans == 0 || n % 2 == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar;
//cin.ignore();
while(Ke_scholar--)
solve();
return 0;
}
SMU Spring 2023 Contest Round 1(MINEYE杯第十六届华中科技大学程序设计邀请赛)的更多相关文章
- Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again
Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...
- Minieye杯第十五届华中科技大学程序设计邀请赛网络赛D Grid(简单构造)
链接:https://ac.nowcoder.com/acm/contest/560/D来源:牛客网 题目描述 Give you a rectangular gird which is h cells ...
- H-Modify Minieye杯第十五届华中科技大学程序设计邀请赛现场赛
题面见 https://ac.nowcoder.com/acm/contest/700#question 题目大意是有n个单词,有k条替换规则(单向替换),每个单词会有一个元音度(单词里元音的个数)和 ...
- Minieye杯第十五届华中科技大学程序设计邀请赛网络赛 部分题目
链接:https://pan.baidu.com/s/12gSzPHEgSNbT5Dl2QqDNpA 提取码:fw39 复制这段内容后打开百度网盘手机App,操作更方便哦 D Grid #inc ...
- “纽劢科技杯”第十六届同济大学程序设计竞赛暨上海邀请赛同步赛 J-张老师的游戏
传送门 题目描述 在空闲时间,张老师习惯性地和菜哭武玩起了取石子游戏,这次的游戏规则有些不同,在他们面前有n堆石子,其中,第i堆石子的个数为a[i],现在制定规则如下: 从张老师开始, ...
- 埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛 C序列变换
链接:https://www.nowcoder.com/acm/contest/91/C来源:牛客网没有账号的同学这样注册,支持博主 题目描述 给定两个长度为n的序列,ai, bi(1<=i&l ...
- K-序列(埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛)
题目描述 给一个数组 a,长度为 n,若某个子序列中的和为 K 的倍数,那么这个序列被称为“K 序列”.现在要你 对数组 a 求出最长的子序列的长度,满足这个序列是 K 序列. 输入描述: 第一行为 ...
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十六):容器部署项目
容器部署项目 这一章我们引入docker,采用docker容器的方式部署我们的项目. 首先需要有一个linux环境,并且安装 java 和 maven 以及 docker 环境,这个教程多如牛毛,不再 ...
- 在Spring Boot中使用 @ConfigurationProperties 注解 (二十六)
@ConfigurationProperties主要作用:就是绑定application.properties中的属性 java代码 @Configuration public class DataS ...
- "浪潮杯"第六届ACM山东省省赛山科场总结
从空间拷过来的.尽管已经过去一个月了.记忆犹新 也算是又一次拾起这个blog Just begin 看着一群群大牛还有队友男神的省赛总结都出了 我最终也耐不住寂寞 来做个流水账抒抒情好了 第一次省赛 ...
随机推荐
- 洛谷 P4343 自动刷题机
题目链接:自动刷题机 思路 二分典题,两个二分判断出可能的最大值和最小值.需要注意当删掉y行代码后,当前代码行数小于0时需要将代码行数重新赋值为0,然后需要注意二分的n最大值的边界,因为x[i]的最大 ...
- 用 Python 绘制现金流量图
目录 用 Python 绘制现金流量图 Python 实现 实现原理 具体代码 使用示例 1:根据现金流量表绘制现金流量图 使用示例 2:绘制等额.等差.等比序列现金流量图 等额序列现金流量图 等差序 ...
- opc da 服务器数据 转 profinet IO项目案例
1 案例说明 1. 在OPC DA服务器上运行OPC DA client软件查看OPC DA服务器的相关参数. 2. 配置VFBOX网关参数,使用网关采集OPC DA服务器数据 ...
- Kubernetes(三)实战入门
实战入门 本章介绍如何在kubernetes集群中部署一个nginx服务,并能够对其进行访问. 1. Namespace Namespace主要作用是实现多套环境的资源隔离或者多租户的资源隔离. 默认 ...
- .NET Core WebApi接口ip限流实践
.NET Core WebApi接口ip限流实践 前言 之前一直想实现接口限流,但一直没去实现,然后刚好看到一篇文章是基于AspNetCoreRateLimit 组件的限流策略.这个组件不做多的介绍, ...
- Linux内核:regmap机制
背景 在学习SPI框架的时候,看到了有一个rtc驱动用到了regmap,本想通过传统方式访问spi接口的我,突然有点不适应,翻了整个驱动,愣是没有找到读写spi的范式:因此了解了regmap以后,才发 ...
- Linux 应用案例开发手册——基于Zynq-7010/20工业开发板
目 录 1 开发案例说明 4 2 Linux 常用开发案例 4 2.1 tl_led_flash 案例 4 2.2 tl_key_test 案例 7 2.3 tl_can_echo 案例 11 2.4 ...
- 面试题:Linux 系统基础提问 (一)
Linux系统中如何管理用户和组? Linux系统中用户和组的管理通常包括以下几个方面: 1.创建用户和组: 使用useradd和groupadd命令创建新用户和新组. 2.修改用户和组信息: 使用u ...
- InvocationTargetException和UndeclaredThrowableException异常介绍
今天来介绍了两个陌生又熟悉的异常类,熟悉是因为我们经常会遇到它们,陌生是好像又从来不知道它们是做什么的 假定读者已经清楚了Java的异常分类: 一是程序不能处理的错误(Error), 二是程序应该避免 ...
- AI生成前端组件的价值思考
想法来源 这个想法来源于我自己的需求,我自己首先就是最精准的目标用户,在这个AI时代,我希望AI可以帮我尽量多地干活. 结合自己的日常独立开发情况,发现花在调前端组件样式上的时间很多,因此思考能不能让 ...