首页 > 其他分享 >2023 SMU RoboCom-CAIP 选拔赛

2023 SMU RoboCom-CAIP 选拔赛

时间:2023-05-14 13:24:47浏览次数:55  
标签:CAIP int SMU stk2 long lst include RoboCom define

A. 小斧头

 

 

#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;
    vector<int> a(n + 1), b(n + 1), c(n + 1),f(n + 1);
    for (int i = 1; i <=n ; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n ; ++i) {
        cin >> b[i];
    }
    for (int i = 1; i <= n ; ++i) {
        c[i] = max(a[i], b[i]);
    }
    stack<int> stk1, stk2;
    int lst;
    for (int i = 1; i <= n ; ++i) {
        while(!stk1.empty() && a[i] > c[stk1.top()])
            stk1.pop();
        while(!stk2.empty() && b[i] > c[stk2.top()])
            stk2.pop();
        if(b[i] >= a[i]){
            if(stk2.empty())
                lst = 0;
            else
                lst = stk2.top();
            f[i] = f[lst] + i - lst;
        }
        else{
            if(stk1.empty())
                lst = 0;
            else
                lst = stk1.top();
            f[i] = f[lst];
        }
        ans += f[i];
        stk1.push(i);
        stk2.push(i);
    }
//    for(auto i : f)
//        cout << i << ' ';
//    cout << endl;
    cout << ans << endl;
    return ;
}
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. 能不能整除?

 

 

C. 又是一道构造题

#include  <map>
#include  <set>
#include  <cmath>
#include  <queue>
#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 = 2e4 + 10, mod = 1e9 +7;

//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
vector<int> a,b;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
2
4 5
20 12 27 15
6 30 45 4 3
6 5
2808 1 180 1980 1001 945
16632 630 1 23166 3900
*/
int ans;

void solve()
{
    a.clear();
    b.clear();
    ans = 0;
    cin >> n >> m;
    vector<vector<int> > ma(n,vector<int>(m,0));
    for(int i = 0;i < n; i++){
        int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i = 0;i < m;i ++){
        int x;
        cin >> x;
        b.push_back(x);
    }
    auto g = a;
    auto gg = b;
    for(int i = 0;i < n;i ++){
        for(int j = 0;j < m;j ++){
            int x = __gcd(a[i],b[j]);
            a[i] /= x;
            b[j] /= x;
            ma[i][j] = x;
        }
    }
    for(int i = 0;i < n;i ++){
        int c = 1;
        for(int j = 0;j < m;j ++){
            c *= ma[i][j];
        }
        if(c != g[i]){
            cout << -1 << endl;
            return ;
        }
    }
    for(int i = 0;i < m;i ++){
        int c = 1;
        for(int j = 0;j < n;j ++){
            c *= ma[j][i];
        }
        if(c != gg[i]){
            cout << -1 << endl;
            return ;
        }
    }
    for(auto i : ma){
        for(auto j : i){
            cout << j << ' ';
        }
        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();
        cout << endl;
    }
    return 0;
}

 

标签:CAIP,int,SMU,stk2,long,lst,include,RoboCom,define
From: https://www.cnblogs.com/Kescholar/p/17399141.html

相关文章

  • SMU Spring 2023 Contest Round 1
    B.ContestPreparation#include<iostream>#include<cstdio>#include<algorithm>#include<string>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#defineinf0x3f......
  • SMU Spring 2023 Contest Round 2
    M.DifferentBilling#include<map>#include<set>#include<cmath>#include<queue>#include<cstdio>#include<vector>#include<climits>#include<cstring>#include<cstdlib>#include<......
  • 2023 SMU RoboCom-CAIP 选拔赛
    2023SMURoboCom-CAIP选拔赛A-小斧头思路:70分由于区间范围越大,最大值越大,st表存区间最大值,枚举bi的值作为[l,r]内最大值,可用二分求出l,r的范围(左边求小于bi,右边求小于等于bi,这样可以得到所有的可能)#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>......
  • 2023 SMU RoboCom-CAIP 选拔赛
    A.小斧头\(O(N^3)\)20points暴力枚举左右端点,然后暴力求区间最值#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintread(){...}int32_tmain(){intn=read(),res=0;vector<int>a(n),b(n);for(auto&i:a)i......
  • SMU Spring 2023 Trial Contest Round 10
    A.RemoveDuplicates#include<bits/stdc++.h>//#defineinf0x3f3f3f3f#defineendl'\n'#defineintlonglongusingnamespacestd;constintN=2e3+10,mod=1e9+7;//typedeflonglongll;typedefpair<int,int>PII;//queue......
  • SMU Spring 2023 Trial Contest Round 10
    SMUSpring2023TrialContestRound10 A-RemoveDuplicates#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;constintN=2e2+5,INF=0x3f3f3f3f,Mod=1e6;constdoubleeps=1e-6;typedef......
  • SMU Spring 2023 Trial Contest Round 9
    SMUSpring2023TrialContestRound9A-WrongSubtraction#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;constintN=1e5+5,INF=0x3f3f3f3f,Mod=1e6;constdoubleeps=1e-6;typedefl......
  • SMU Spring 2023 Trial Contest Round 9
    A.WrongSubtraction#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){intn,k;cin>>n>>k;while(k--){if(n%10==0)n/=10;elsen--;}cout<<n;return0;}B.T......
  • SMU Spring 2023 Trial Contest Round 1(6/8)
    SMUSpring2023TrialContestRound1(6/8)A.PrependandAppendPrependandAppend只需考虑给定字符串两端是否符合10或01即可,双指针从两端模拟即可。#include<iost......
  • SMU Spring 2023 Trial Contest Round 1
    A.PrependandAppend如果两段字符不同就可以删掉,如果不能删了就是最初的字符串#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn;stri......