首页 > 编程语言 >SMU Spring 2023 Contest Round 4(第 21 届上海大学程序设计联赛 春季赛)

SMU Spring 2023 Contest Round 4(第 21 届上海大学程序设计联赛 春季赛)

时间:2023-06-01 22:13:09浏览次数:54  
标签:21 Contest int Spring long mod include dp define

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;
}
View Code

 

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;
}
View Code

 

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;
}
/*

 */
View Code

 

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;
}
View Code

 

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;
}
View Code

 

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;
}
View Code

 

标签:21,Contest,int,Spring,long,mod,include,dp,define
From: https://www.cnblogs.com/Kescholar/p/17450256.html

相关文章

  • 基于JAVA的springboot+vue财务管理系统,附源码+数据库+论文+PPT
    1、项目介绍随着信息技术和网络技术的飞速发展,人类已进入全新信息化时代,传统管理技术已无法高效,便捷地管理信息。为了迎合时代需求,优化管理效率,各种各样的管理系统应运而生,各行各业相继进入信息管理时代,财务管理系统就是信息时代变革中的产物之一。任何系统都要遵循系统设计的基......
  • 1821D - Black Cells(暴力贪心枚举)
    大意加思路:相当于有一个绳子,其中有n段可以上色,如果要给一段上色代价增加2,没向前走一步代价加一,可以看出代价最多可以去对掉长度为一的段落,因为最后要给x个点上色代价做少为x,而前面的段落给1个点上色代价最少为2,另外要考虑最后一段可能没有完全上色。点击查看代码#include<bits/......
  • SpringBoot SSM vue 在线办公系统
    SpringBootSSMvue在线办公系统系统功能登录忘记密码首页统计分析用户管理员工管理公告管理考勤管理绩效管理薪酬管理流程管理留言管理文件管理开发环境和技术开发语言:Java使用框架:SpringBoot或SSM +Mybatis+MysqlSpringBoot是一个用于构建Java应用......
  • 2021级《软件工程》测试河北宏志大学学生成绩管理系统
    2021级《软件工程》开发技能测试试卷(180分钟) 河北宏志大学学生成绩管理系统(卷面成绩40分) 河北宏志大学学生成绩管理系统1、项目需求:学生管理是各大院校的管理工作中尤为重视的一项工作,它一直以来是学校管理的一项重要的衡量指标。学生管理系统的应用解决了学校日常学生......
  • 【SpringTask】
    SpringTask是Spring框架提供的任务调度工具,可以按照约定的时间自动执行某个代码逻辑。作用:定时自动执行某段Java代码应用场景:信用卡每月还款提醒 强调:只要是需要定时处理的场景,都可以使用SpringTask。......
  • 企业级springboot项目架构模板V3.0,开箱即用
    此次3.0更新点:1.加入文件服务(quick-storage)功能支持OSS、FTP存储(该服务支持以SDK的方式引入)2.修复sentinel因path路径问题导致流控失效问题3.修复word模板生成PDF文件工具类时首次生成时,图片生成没有成功写入FTP的问题,原因为临时文件路径问题。4.修改部分类的包路径5.auth服......
  • springBoot service 事务注解@Transactional不起作用的解决
    在springBoot使用事物时,发现事务并没有正常执行,没有进行回滚@Transactionalpublicvoidadd(StringcompanyName,Stringname)throwsMyException{ companyDao.add(companyName);try{ userDao.addUser(name);}catch(DuplicateKeyExceptione){//......
  • 企业级springboot项目架构模板V1.0,开箱即用
    项目地址:https://gitee.com/liujinxin_ark/quick-template/releases项目问题可在评论中留言,项目持续更新中…quick-template项目介绍软件架构quick-auth-serve工程quick-log-serve工程quick-common工程quick-config工程quick-base-serve工程quick-web-serve工程control目......
  • springboot多模块打包配置问题
    工程案例结构: -baidu//聚合过程   -baidu_web     //子模块web工程   -baidu_service//子模块   -baidu_config//子模块配置工程  注意事项(配置步骤):1.baidu聚......
  • SpringBoot配置Bean是否生效
    @Configuration@ConditionalOnProperty(prefix="xxl.job",name="enable",havingValue="true",matchIfMissing=true)publicclassXxlJobConfig{//...}上述可直接读取配置文件中的,xxl.job.enable=true@ConditionalOnProperty(prefi......