首页 > 其他分享 >9.26 SMU Autumn 2023 Round 5

9.26 SMU Autumn 2023 Round 5

时间:2023-09-27 11:36:21浏览次数:36  
标签:typedef const 9.26 int double SMU long Autumn define

SMU Autumn 2023 Round 5

A - Everyone Loves to Sleep

思路:将小于睡觉时间的闹钟加24:00,找到最小的时间min,答案即为min-睡觉时间

#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void solve(){
    PII st;
    int n;cin>>n>>st.first>>st.second;
    vector<PII>ve(n);
    PII ans;
    ans={50,50};

    for(int i=0;i<n;++i){
        cin>>ve[i].first>>ve[i].second;
        if(ve[i]<st){
            ve[i].first+=24;
        }
        ans=min(ans,ve[i]);
    }
    if(ans.second<st.second)ans.second+=60,ans.first--;
    cout<<ans.first-st.first<<' '<<ans.second-st.second<<'\n';

}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

B - Minimum Varied Number

思路:由于每一位的数不一样,且需要位数尽可能少,那直接从最大的开始取,直到凑够

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void solve(){
    int n;cin>>n;
    string s;
    for(int i=9;n&&i>=1;--i){
        s.push_back('0'+min(n,i));
        n-=min(n,i);
    }
    std::reverse(s.begin(), s.end());
    cout<<s<<'\n';
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

C - Color with Occurrences

思路:由于每个串需要是原串的子串,且串的个数最多为10,那么把每个串能够匹配原串的左右边界位置以及该串的编号统计后排序,贪心的覆盖整个串,对于没被覆盖的起点l,找到一个si,使得si.l<=l且si.r最大,统计需要的个数,若最后不能覆盖完,则-1

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e3+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

struct E{
    int l,r,id;
    bool operator<(const E &e)const{
        if(e.l!=l)return l<e.l;
        return r<e.r;
    }
};
void solve(){
    string s;
    int n,len;
    cin>>s>>n;len=s.size();
    s.insert(s.begin(),' ');
    vector<E>f;
    string a;
    auto P=[len,s](int st,string x){
        if(x.size()>len-st+1)return false;
        for(int i=st,j=0;j<x.size();++j,++i){
            if(x[j]!=s[i])return false;
        }
        return true;
    };
    for(int i=1;i<=n;++i){
        cin>>a;
        for(int j=1;j<=len;++j){
            if(P(j,a)){
                f.push_back((E){j,j+(int)a.size()-1,i});
            }
        }
    }
    sort(f.begin(),f.end());
//    cout<<f.size()<<'\n';
//    for(auto v:f)cout<<v.id<<':'<<v.l<<' '<<v.r<<'\n';
    int st=1;
    vector<PII>ans;
    bool ok=false;
    for(int i=0;i<f.size();++i){
        int j=i,p=0,ma=-INF;
        while(j<f.size()&&f[j].l<=st){
            if(f[j].r>ma){
                ma=f[j].r;
                p=j;
            }
            j++;
        }
        if(ma<st)break;
        ans.push_back({f[p].id,f[p].l});
        st=ma+1;
        i=j-1;
        if(st>len){
            ok=true;break;
        }

    }
    if(ok){
        cout<<ans.size()<<'\n';
        for(auto v:ans)cout<<v.first<<' '<<v.second<<'\n';
    }else cout<<"-1\n";
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

D - Add Modulo 10

思路:多画几个例子可以发现,将数分成了两种,第一种:能整除5的情况,最后一位为5的数都能转化为最后一位为0的数,且之后不会再转化;

第二种:最后一位为:1->2->4->8->6->2->4...,每个循环之间的数刚好差20,那么将数的最后一位转化为同一个数,在判断所有数是不是都相差20

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void solve(){
    int n;cin>>n;
    bool ok1=true;
    vector<int>f;
    vector<int>ve(n+1);
    for(int i=1;i<=n;++i){
        cin>>ve[i];
        if(ve[i]%5==0&&ve[i]%10!=0)ve[i]+=5;
        if(i>1&&ve[i]!=ve[i-1])ok1=false;
    }
    if(ok1||n==1){
        cout<<"Yes\n";return ;
    }
    for(int i=1;i<=n;++i){
        if(ve[i]%10==0){
            cout<<"No\n";return ;
        }
        int p=ve[i];
        while(p%10!=6){
            p+=p%10;
        }
        f.push_back(p);
    }
    for(int i=1;i<f.size();++i){
        if(abs(f[i]-f[0])%20!=0){
            cout<<"No\n";return ;
        }
    }
    cout<<"Yes\n";
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

G - Make Them Equal

思路:由于数的范围为1e3,可以先预处理出转化成所有数需要的次数;那么问题就变成01背包问题;可能会t,循环的k可以减少为min(需要的总次数,k)

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e3+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;
vector<int>ve(N+5,INF);
void init(){
    ve[1]=0;
    for(int i=1;i<N;++i){
        for(int j=1;j<=i;++j){
            int x=i/j;
            if(i+x>N)continue;
            ve[i+x]=min(ve[i+x],ve[i]+1);
            if(x==1)break;
        }
    }
}
void solve(){
    int n,k,s=0;cin>>n>>k;
    vector<int>b(n+1),v(n+1),w(n+1);
    for(int i=1;i<=n;++i){
        cin>>b[i];
        v[i]=ve[b[i]];s+=v[i];
    }
    for(int i=1;i<=n;++i)cin>>w[i];
    vector<int>f(min(s,k)+1);
    for(int i=1;i<=n;++i){
        for(int j=min(s,k);j>=v[i];--j)
            f[j]=max(f[j],f[j-v[i]]+w[i]);
    }
    cout<<f[min(s,k)]<<'\n';
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    init();
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

H - Kill the Monster

思路:k的范围不大,直接暴力枚举k即可

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e3+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    int hc,dc,hm,dm,k,w,a;
    cin>>hc>>dc>>hm>>dm>>k>>w>>a;
    bool ok=false;
    for(int i=0;i<=k;++i){
        int h=hc+i*a,d=dc+(k-i)*w;
        int xc=(hm+d-1)/d,xm=(h+dm-1)/dm;
//        cout<<i<<":"<<h<<' '<<d<<"--"<<xc<<' '<<xm<<'\n';
        if(xc<=xm){
            ok=true;break;
        }
    }
    if(ok)cout<<"YES\n";
    else cout<<"NO\n";
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

I - Div. 7

思路:暴力枚举与x位数相同的所有数,取最小的替换数

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void solve(){
    int n;cin>>n;
    if(n%7==0)cout<<n<<'\n';
    else{
        int cnt=4;
        auto P=[](int a,int b){
            int res=0;
            for(int i=0;i<3;++i){
                if(a%10!=b%10)res++;
                a/=10,b/=10;
            }
            return res;
        };
        int ans;
        int p=n,l=0;
        while(p){
            l++;p/=10;
        }
        int st=pow(10,l-1);
        while(st%7)st++;
        for(int i=st;i<pow(10,l);i+=7){
            int c=P(i,n);
            if(c<cnt){
                cnt=c;ans=i;
            }
            if(cnt==1)break;
        }
        cout<<ans<<'\n';
    }
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

标签:typedef,const,9.26,int,double,SMU,long,Autumn,define
From: https://www.cnblogs.com/bible-/p/17732172.html

相关文章

  • 2023.9.26
    今天晚上去416自习了一下,期间和学长交流,确定了近期的学习方向中途有事离开,本来以为很快就能回去,结果事情有点出乎意料得多,搞到晚上九点多才搞完,回去的时候416已经没人了总之今天也没学多少东西,在做buuctf上的题,最近有关pwn有一些东西想要验证一下......
  • 9.26随笔
    1.看到这个操场还是挺感慨的,今年没有去参加田径队的训练,前两年都去了,其实还是有点想的,但是嗯年龄越大好像身体也不行了,加之训练量挺大,花的时间很多,但是好像想了一下,好像就算不花这些时间也没有做到其他的事情。虽然开始是为了奖去,但那个氛围,还是挺让人怀念的。2.今天是比较忙的一......
  • 9.26随笔
    JavaScript语句标识符JavaScript语句通常以一个 语句标识符 为开始,并执行该语句。语句标识符是保留关键字不能作为变量名使用。下表列出了JavaScript语句标识符(关键字):语句描述break用于跳出循环。catch语句块,在try语句块执行出错时执行catch语句块。......
  • 大二打卡(9.26)
    今天做了什么,:今天的开局,数据结构,听懂了,主要是跟前面的课的知识点都差不太多,前面的理解了,今天的理解难度就不太大,然后是马克思主义原理,今天的马克思主义原理课格外的好玩,可能是老师今天的内容能让我们发挥脑洞的地方比较多,还叫了好几个同学,包括我,不过我是因为被自己的脑洞笑到了,然......
  • 9.26
    今天做了什么:今天上午上的数据结构和马克思主义原理,数据结构讲了点队列,关于队列知道了一点大概的运行思路,然后就是对于最基础的队列的时间复杂度如何优化,可以通过指针的方式将原本的时间复杂度O(n)(由于出队列使得后面的元素递进一位)变成O(1)只要通过指针将下次的输出直接......
  • 每日总结9.26
    今天上午我先上了一节算法与数据结构的课程。这门课程主要讲解了各种算法和数据结构的基本原理和应用。我们学习了不同的排序算法,如冒泡排序、插入排序和快速排序等,以及栈、队列和链表等数据结构。老师通过生动的例子和实际的应用场景,让我们更好地理解和掌握这些概念。这门课程对......
  • 9.26每日总结
    今天学习了mongodb数据库的使用,并且学会了对其进行简单的创建数据库以及创建数据表的操作,然后学会了简单的增删改查,并且用编程软件进行连接。同时进一步了解了企业erp,并找了相关的代码进测试学习。......
  • SMU Autumn 2023 Round 5
    SMUAutumn2023Round5A.EveryoneLovestoSleep把时间都转成分钟,然后存起来,二分找到离他睡觉点最近的一个时间段,减去他的睡觉点,如果最近的在第二天,则把中间的这段时间加起来#include<bits/stdc++.h>#defineintlonglong#definedebug(a)cout<<#a<<"="<<a<<'\n'......
  • 2023.09.26 联考总结&题解
    T1derby你考虑直接贪心进行匹配即可,就是说对于每一个\(1\)去匹配最大的\(0\)#include<bits/stdc++.h>usingnamespacestd;intn,m;vector<int>A[2],B[2];intmain(){ freopen("derby.in","r",stdin); freopen("derby.out","w",s......
  • 2023.9.26
    今天学习了数据结构,首先学习了栈的基本知识,栈的初始化为先给栈分配一个预定大小的数组空间,接着学习了如栈的操作,将元素押入栈顶,用栈顶指针加一,出栈操做同上类似。接着学习了链式表的栈操作,类似于单链表的结构,利用前插法押入元素,在顺序出栈同单链表相似。紧接着学习了递归思想,首先......