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杯第十六届华中科技大学程序设计邀请赛)的更多相关文章

  1. Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again

    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...

  2. Minieye杯第十五届华中科技大学程序设计邀请赛网络赛D Grid(简单构造)

    链接:https://ac.nowcoder.com/acm/contest/560/D来源:牛客网 题目描述 Give you a rectangular gird which is h cells ...

  3. H-Modify Minieye杯第十五届华中科技大学程序设计邀请赛现场赛

    题面见 https://ac.nowcoder.com/acm/contest/700#question 题目大意是有n个单词,有k条替换规则(单向替换),每个单词会有一个元音度(单词里元音的个数)和 ...

  4. Minieye杯第十五届华中科技大学程序设计邀请赛网络赛 部分题目

    链接:https://pan.baidu.com/s/12gSzPHEgSNbT5Dl2QqDNpA 提取码:fw39 复制这段内容后打开百度网盘手机App,操作更方便哦 D    Grid #inc ...

  5. “纽劢科技杯”第十六届同济大学程序设计竞赛暨上海邀请赛同步赛 J-张老师的游戏

    传送门 题目描述     在空闲时间,张老师习惯性地和菜哭武玩起了取石子游戏,这次的游戏规则有些不同,在他们面前有n堆石子,其中,第i堆石子的个数为a[i],现在制定规则如下:     从张老师开始, ...

  6. 埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛 C序列变换

    链接:https://www.nowcoder.com/acm/contest/91/C来源:牛客网没有账号的同学这样注册,支持博主 题目描述 给定两个长度为n的序列,ai, bi(1<=i&l ...

  7. K-序列(埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛)

    题目描述 给一个数组 a,长度为 n,若某个子序列中的和为 K 的倍数,那么这个序列被称为“K 序列”.现在要你 对数组 a 求出最长的子序列的长度,满足这个序列是 K 序列.  输入描述: 第一行为 ...

  8. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十六):容器部署项目

    容器部署项目 这一章我们引入docker,采用docker容器的方式部署我们的项目. 首先需要有一个linux环境,并且安装 java 和 maven 以及 docker 环境,这个教程多如牛毛,不再 ...

  9. 在Spring Boot中使用 @ConfigurationProperties 注解 (二十六)

    @ConfigurationProperties主要作用:就是绑定application.properties中的属性 java代码 @Configuration public class DataS ...

  10. &quot;浪潮杯&quot;第六届ACM山东省省赛山科场总结

    从空间拷过来的.尽管已经过去一个月了.记忆犹新 也算是又一次拾起这个blog Just begin 看着一群群大牛还有队友男神的省赛总结都出了 我最终也耐不住寂寞 来做个流水账抒抒情好了 第一次省赛 ...

随机推荐

  1. Jupyter QtConsole 配置,2023 年了你还在使用 QtConsole 吗?

    目录 Jupyter QtConsole 配置,2023 年了你还在使用 QtConsole 吗? Jupyter QtConsole 的安装 设置字体 启动时自动加载需要的库包 更新:2023 年 ...

  2. [iOS]Size Class不同尺寸适配的是什么样的机型(实验向)

    Size Class的定义可以翻阅网友的博客,本文不再赘述http://blog.csdn.net/yongyinmg/article/details/39315829 http://blog.csd ...

  3. java并发的发布和订阅测试

    现在编码的时候,为了处理消息,大家动不动就上个重器,例如MQ之类的.但很多时候,并不是那么有必要,因为数据量和并发其实远远不够. 可以替代的方案非常多,其中一个是java.util.concurren ...

  4. Markdown常用语法详解

    背景知识 什么是html html是一种网页标记语言.我们平常见到的那么好看的网页就是通过html语言来编写的. html语言举例: <h1>hello world</h1> ...

  5. 如何在Zynq-7000上烧写PL Image

    由 技术编辑archive1 于 星期六, 06/28/2014 - 10:05 发表 作者:hqin, Xilinx处理器专家FAE 在Zynq-7000上编程PL大致有3种方法: 用FSBL,将b ...

  6. ubuntu16 python2 安装M2Crypto报错

    正文 pip2 install M2Crypto # 报错: # unable to execute 'swig': No such file or directory # error: comman ...

  7. Java uuid生成随机32位

    import java.util.UUID; /** * @ClassName:UuidUtils * @Description:uuid工具类 * @Author:chenyb * @Date:20 ...

  8. Oracle 递归拼接字段

    效果 sql SELECT LISTAGG(T.NAME, ' / ') WITHIN GROUP(ORDER BY LEVEL DESC) AS RESULT FROM S_WORK_RESOURS ...

  9. 《探索Python Requests中的代理应用与实践》

    requests加代理 高匿API代理 此处使用的小象代理:1元100个,便宜,可以购买尝试加下代理 存活期1到2分钟 import time import requests from lxml im ...

  10. vue --version 显示的却是vue cli的版本号,为什么?

    vue --version 显示的却是vue cli的版本号,为什么? 如果您在运行 vue --version 命令时显示的是 Vue CLI 的版本号,而不是 Vue.js 的版本号,那可能是因为 ...