SMU Spring 2023 Contest Round 4(第 21 届上海大学程序设计联赛 春季赛)
A. Antiamuny wants to learn binary search
签到题.

#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 = 1e9 + 10, mod = 1e9 +7; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<char, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/* */
string s;
vector<PII> a,ans;
int f(int l,int r,int x) { // l <= x <= r
int cnt = 0;
while(l <= r) {
cnt++;
int mid = (l + r) / 2;
if (mid == x) break;
if (mid < x) l = mid + 1;
else r = mid - 1;
}
return cnt;
}
void solve()
{
cin >> n >> m >> k;
cout << f(n,m,k) << 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;
}
B. Bespread with chequers
用dp数组来代表n列时的方案总数,可以发现n是偶数时,dp[n] = dp[n - 1] + 1, 奇数时dp[n] = dp[n - 1] - 1,别忘了取模.

#include<bits/stdc++.h> #define int long long
#define endl '\n'
#define fi first
#define se second using namespace std; const int N = 1e6 + 10,mod = 1e9 + 7; int n, m, x;
int dp[N];
void init(){
dp[1] = 1;
for(int i = 2;i < 1e6 + 10;i ++){
if(i & 1)
dp[i] = (2 * dp[i - 1] % mod - 1) % mod;
else
dp[i] = (2 * dp[i - 1] % mod + 1) % mod;
}
} void solve() {
cin >> n;
cout << dp[n] % mod << endl;
} int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int h_h;
init();
cin >> h_h;
//h_h = 1;
for(int i=1;i<=h_h;i++)solve();
return 0;
}
C.Converse the string
即就是对字符串s遍历一遍,用s[i]和字符串ans的首字符比较,字典序小的放前面,反之放后面.

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 1e6+10, mod = 1e9 + 7; //typedef long long ll;
typedef pair<int,int> PII;
int n,m,t,k;
map<int,int> mp;
priority_queue<int> QQ;
deque<int> Q;
void solve() {
string s;
cin >> s;
deque<char> ans,ori;
for(auto i : s)
if(ans.empty())
ans.push_back(i);
else{
if(i <= ans.front()){
ans.push_front(i);
}
else{
ans.push_back(i);
}
}
for(auto i : ans){
cout << i ;
}
cout << 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;
}
/* */
G.Golden jade matrix checker
二维前缀和,对给出x,y矩阵,去原矩阵中找他的和即可,大于等于0的直接输出No即可.

#include<bits/stdc++.h> #define int long long
#define endl '\n'
#define fi first
#define se second using namespace std; const int N = 2010;
const int M = 20; int a[N][N]; void solve() {
int n, m, x, y;
cin >> n >> m >> x >> y;
vector<vector<int>> s(n + 1,vector<int> (m + 1,0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
}
if (s[n][m] <= 0) {
cout << "NO" << endl;
return;
}
for(int i = 1;i <= n - x + 1;i ++){
for(int j = 1;j <= m - y + 1;j++){
int dx = i + x, dy = j + y;
int res = s[dx - 1][dy - 1] - s[dx-1][j - 1] - s[i - 1][dy-1] + s[i - 1][j - 1];
if(res >= 0){
cout << "NO" << endl;
return ;
}
}
}
cout << "YES" << endl;
} int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int h_h;
cin >> h_h;
//h_h = 1;
while (h_h--)solve();
return 0;
}
H.How to know the function
很容易能找出,只有n为0时一次即可,其余次数均可以2次求出,记得开longlong.

#include<bits/stdc++.h>
#define endl '\n'
using namespace std; const int N = 501;
long long n,m,x;
char mp[N][N];
int main(){
int T;
cin>>T;
while(T--){
cin >> n;
if( n == 0){
cout << 1 << endl;
}
else {
cout << 2 << endl;
}
}
return 0;
}
J. Juxtaposed brackets
由定义可知,每个()里最多包含两个并列的括号,被括号包含的括号算是一个,例如(()()),外面的括号就是包含了两个并列的,而((()))这样只算包含了一个,如此,我们可以开一个数组去记录每一个括号内包含了多少个并列的括号,其中不对称,或者左扩右扩不相等的都可以做个标记,之后输出NO即可,对付符合要求的,再对数组进行遍历,若有大于2的则说明有括号包含了2个以上的并列括号,输出NO.

#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 = 1e9 + 10, mod = 1e9 +7; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<char, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/* */
string s;
vector<PII> a,ans;
void solve()
{
string s;
cin >> s;
bool f = false;
vector<int> a(s.size());
stack<int> st;
for(int i = 0;i < s.size();i ++){
if(s[i] == '('){
st.push(i);
}
else if(st.empty()){
f = true;
break;
}
else {
st.pop();
if(st.size())
a[st.top()]++;
}
if(st.empty() && i < s.size() - 1){
f = true;
break;
}
}
for(auto i : a){
if(i > 2){
f = true;
break;
}
}
if(f || st.size()){
cout << "NO" << endl;
}
else
cout << "YES" << 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;
}
SMU Spring 2023 Contest Round 4(第 21 届上海大学程序设计联赛 春季赛)的更多相关文章
- (更新中)"华为杯" 武汉大学21级新生程序设计竞赛 非官方题解
"华为杯" 武汉大学21级新生程序设计竞赛 https://ac.nowcoder.com/acm/contest/31620#question D.和谐之树 思路:披着线段树外皮 ...
- Spring Cloud Alibaba学习笔记(21) - Spring Cloud Gateway 自定义全局过滤器
在前文中,我们介绍了Spring Cloud Gateway内置了一系列的全局过滤器,本文介绍如何自定义全局过滤器. 自定义全局过滤需要实现GlobalFilter 接口,该接口和 GatewayFi ...
- Spring Cloud微服务安全实战- 2-1 环境安装
下面这些.后续随着讲课逐步再去安装. 2019年1月开始 jdk是收费的 找jdk最后一个免费版本 8u192这是jdk1.8最后的一个免费版本 STS spring提供的ide可以方便的开发spri ...
- 2015 Astar Contest - Round 3 题解
1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...
- Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression
题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...
- 21. javacript高级程序设计-Ajax与Comet
1. Ajax与Comet 1.1 XMLHttpRequest对象 IE5是第一款引入XHR对象的浏览器,IE5中是通过MSXML库中的一个ActiveX对象实现的.因此在IE中可能存在MSXML2 ...
- Contest - 中南大学第六届大学生程序设计竞赛(Semilive)
题1:1160十进制-十六进制 注意他给的数据范围 2^31,int是 2^31-1 #include<iostream> using namespace std; int main() ...
- 2月21日python程序设计
Python变量 1.不需要事先声明变量名及其类型,直接赋值即可. 2.强类型编程语言,根据赋值或运算来推断变量类型. 3.动态类型语言,变量的类型也是可以随时变化的. >>> x ...
- 台州学院maximum cow训练记录
前队名太过晦气,故启用最大牛 我们的组队大概就是18年初,组队阵容是17级生詹志龙.陶源和16级的黄睿博. 三人大学前均无接触过此类竞赛,队伍十分年轻.我可能是我们队最菜的,我只是知道的内容最多,靠我 ...
- TOJ 5065: 最长连续子序列
5065: 最长连续子序列 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 140 ...
随机推荐
- 个人团队兼职开发app(社交,语聊1v1,视频直播)
如果您有意向创业,意向社交类产品,如语聊,及时通信,视频直播,1v1等,又苦无没有人力资源. 我们岁数都是30+,在互联网行业摸爬滚打十年有余. 后端,前端,客户端,运维,四个人. 我们共事很长一段时 ...
- 在 AWS 平台搭建 DolphinScheduler
AWS平台搭建 DolphinScheduler DolphinScheduler 是当前热门的调度器,提供了完善的可视化.拖拉拽式的调度.在 AWS 平台上提供了 airflow 与 step fu ...
- HTTP事务理解
借图: 首先三次握手理解: TCP三次握手好比两个对话, 第一次握手:甲给乙一直发送信息,乙没有回应,甲不知道乙有没有收到信息 第二次握手:乙收到信息,然后再给甲回信息,此时甲知道乙收到信息,但乙不知 ...
- 【Zabbix】Zabbix5.0安装部署问题汇总
报错信息:No package 'oniguruma' found 解决方法:https://www.limstash.com/articles/202003/1563 报错信息: PHP bcmat ...
- Java Executors类的9种创建线程池的方法及应用场景分析
在Java中,Executors 类提供了多种静态工厂方法来创建不同类型的线程池.在学习线程池的过程中,一定避不开Executors类,掌握这个类的使用.原理.使用场景,对于实际项目开发时,运用自如, ...
- jQuery 插件autocomplete 应用
项目中有时会用到自动补全查询,就像Google搜索框.淘宝商品搜索功能,输入汉字或字母,则以该汉字或字母开头的相关条目会显示出来供用户选择, autocomplete插件就是完成这样的功能. auto ...
- TypeScript 学习笔记 — 交叉类型、条件类型和条件分发(八)
目录 交叉类型 条件类型 1. 直接传入判断的条件 2. 把条件当成泛型传入 3. 多重条件判断 4. 判断接口中的类型 extends 父子关系(类型等级) 条件分发机制 实际开发中如何避免? &l ...
- Django查询特定条件的数据并插入其他表格模型
要将特定 wk_nu 值对应的数据批量插入到 MPS005D3Model 中,你可以执行以下步骤: 确定要插入的 wk_nu 值. 获取与该 wk_nu 相关的数据. 将获取的数据逐一创建为 MPS0 ...
- [oeasy]python0096_游戏娱乐行业_雅达利_米洛华_四人赛马_影视结合游戏
游戏娱乐行业 回忆上次内容 游戏机行业从无到有 雅达利 公司 一枝独秀 并且带领 行业 发展起来 雅达利公司 优秀员工 乔布斯 在 朋友 帮助下完成了<pong> Jobs 黑了 Woz ...
- 题解:AT_abc357_f [ABC357F] Two Sequence Queries
题意 维护一个数据结构,支持两个数列的区间求和,和查询区间内两数列各元素积的和. 分析 线段树万岁! 这道题要维护两个序列,所以线段树中要同时存储两个区间和.但还要在维护一个信息,是该区间内两序列元素 ...