B.正则表达式(签到,赛时写复杂了就这样吧,一定要仔细读题!)
#include<bits/stdc++.h> #define int long long #define double long double #define endl '\n' #define pb push_back #define pf push_front using namespace std; const int N=1e6+10; double pi=3.1415926535; int f[N]; void solve(){ int n;cin>>n; int ans=0; for(int i=1;i<=n;i++){ string s;cin>>s; int last=0,flag=0; for(int j=0;j<s.size();j++){ if(s[j]=='.'){ string ss=s.substr(last,j-last); int len=ss.size(); if(len>3){ flag=1; break; } if(len==3){ if(ss[0]>'2'){ flag=1; break; }else if(ss[0]=='2'&&ss[1]>'5'){ flag=1; break; }else if(ss[0]=='2'&&ss[1]=='5'&&ss[2]>'5'){ flag=1; break; } } last=j+1; } } string ss=s.substr(last); int len=ss.size(); if(len>3)flag=1; if(len==3){ if(ss[0]>'2'){ flag=1; }else if(ss[0]=='2'&&ss[1]>'5'){ flag=1; }else if(ss[0]=='2'&&ss[1]=='5'&&ss[2]>'5'){ flag=1; } } if(!flag)ans++; } cout<<ans<<endl; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int _; _=1; //cin>>_; while(_--)solve(); return 0; }
C.Circle(签到,算是结论题?或者自己推一下式子)
#include<bits/stdc++.h> #define int long long #define double long double #define endl '\n' #define pb push_back #define pf push_front using namespace std; const int N=1e6+10; double pi=3.1415926535; int f[N]; void solve(){ int n;cin>>n; f[0]=1,f[1]=2,f[2]=4; for(int i=3;i<=N;i++){ f[i]=i*i-i+2; } for(int i=0;i<n;i++){ int x;cin>>x; cout<<f[x]<<' '; } } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int _; _=1; //cin>>_; while(_--)solve(); return 0; }
J.keillempkill学姐の卷积(签到,随便暴力即可)
![]()
#include<bits/stdc++.h> #define int long long #define double long double #define endl '\n' #define pb push_back #define pf push_front using namespace std; const int N=30; double pi=3.1415926535; int f[N]; int n,m,q; int op[30][30],core[30][30],ans[30][30]; void solve(){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>core[i][j]; } } for(int i=1;i<=m;i++){ for(int j=1;j<=m;j++){ cin>>op[i][j]; } } for(int i=0;i<=m-n;i++){ for(int j=0;j<=m-n;j++){ for(int k1=1;k1<=n;k1++){ for(int k2=1;k2<=n;k2++){ ans[i][j]+=op[k1+i][k2+j]*core[k1][k2]; } } } } for(int i=0;i<=m-n;i++){ for(int j=0;j<=m-n;j++){ cout<<ans[i][j]<<' '; } cout<<endl; } } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int _; _=1; //cin>>_; while(_--)solve(); return 0; }
L.SSH(简单,算是模拟加stl应用吧)
![]()
#include<bits/stdc++.h> #define int long long #define double long double #define endl '\n' #define pb push_back #define pf push_front using namespace std; const int N=1e6+10; double pi=3.1415926535; int f[N]; int n,m,q; map<pair<string,string>,int>ipanduser; map<pair<string,string>,int>keyuser; map<string,string>key; void solve(){ cin>>m>>n>>q; while(m--){ string s1,s2;cin>>s1>>s2; key[s2]=s1;// } while(n--){ string ip;cin>>ip; int k;cin>>k; while(k--){ string user;cin>>user; ipanduser[{ip,user}]=1; int t;cin>>t; while(t--){ string pub;cin>>pub; keyuser[{user,pub}]=1; } } } while(q--){ string user,ip,pri; cin>>user>>ip>>pri; if(ipanduser[{ip,user}]&&keyuser[{user,key[pri]}]) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int _; _=1; //cin>>_; while(_--)solve(); return 0; }
I.游戏(简单,按题意跑两遍最短路即可,比较输出最小花费)
#include<bits/stdc++.h> #define int long long const int INF=0x3f3f3f3f3f3f3f3f,N=1e6+10; using namespace std; typedef pair<int,int> PII; int flag; int n,m,k; int e[N],ne[N],h[N],w[N],s[N],idx,dist[N]; void add(int a,int b,int c,int d){ e[idx]=b,ne[idx]=h[a],w[idx]=c,s[idx]=d,h[a]=idx++; } map<int,int>st; void dij(int ss) { for(int i=1;i<=n;i++)dist[i]=INF; dist[ss] = 0; priority_queue<PII, vector<PII>, greater<PII> > heap; heap.push({0, ss}); while (heap.size()) { auto t = heap.top(); heap.pop(); int ver = t.second, distance = t.first; if (st[ver]) continue; st[ver] = 1; for (int i = h[ver];~i; i = ne[i]) { int j = e[i]; if(s[i]||flag){ if (dist[j] > dist[ver] + w[i]) { dist[j] = dist[ver] + w[i]; heap.push({dist[j], j}); } } } } } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>m>>k; memset(h,-1,sizeof h); while(m--){ int a,b,c,d;cin>>a>>b>>c>>d; add(a,b,c,d),add(b,a,c,d); } dij(1); int res=INF,ans=0; res=min(res,dist[n]); if(dist[k]!=INF){ ans+=dist[k]; flag=1; st.clear(); dij(k); ans+=dist[n]; res=min(res,ans); } if(res>=INF)cout<<-1; else cout<<res; return 0; }
F.累加器(简单,个人认为我的解法不错,用到了前缀和,可以找规律发现从0到x,若x是2的整数次幂,如2^k,则改变k-1,否则存在循环节,可以把1~15的二进制表示画出来再结合我的代码看规律)
#include<bits/stdc++.h> #define int long long #define endl '\n' #define pb push_back #define pf push_front using namespace std; const int N=1e7+10; int dp[N],s[N]; int lowbit(int x){ return x&-x; } void pre(){ for(int i=0;i<=23;i++){ dp[1<<i]=i+1; } int last=0; for(int i=1;i<=2e6+10;i++){ if(i-lowbit(i)==0){ last=i; }else{ dp[i]=dp[i-last]; } } for(int i=1;i<=2e6+10;i++)s[i]=s[i-1]+dp[i]; } void solve(){ int x,y;cin>>x>>y; cout<<s[y+x]-s[x]<<endl; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int _; _=1; pre(); cin>>_; while(_--)solve(); return 0; }
E.区间(中等,线段树板子题吧)
#include<bits/stdc++.h> #define ll long long using namespace std; const int N=1e6+10; ll n,q; struct Node{ ll l,r,lnode,rnode; ll lmax,rmax,len,ansmax; }tr[N<<2]; void pushup(Node&root,Node&left,Node&right){ root.lmax=left.lmax,root.rmax=right.rmax; root.len=left.len+right.len; root.lnode=left.lnode,root.rnode=right.rnode; root.ansmax=max(max(left.ansmax,right.ansmax),left.rmax+right.lmax); if(left.ansmax==left.len) root.lmax=left.ansmax+right.lmax; if(right.ansmax==right.len) root.rmax=left.rmax+right.ansmax; } void pushup(ll u){ pushup(tr[u],tr[u<<1],tr[u<<1|1]); } void build(ll u,ll l,ll r){ tr[u].len=tr[u].r-tr[u].l+1; if(l==r)tr[u]={l,r,0,0,1,1,1,1}; else{ tr[u]={l,r}; ll mid=l+r>>1; build(u<<1,l,mid),build(u<<1|1,mid+1,r); pushup(u); } } void modify(ll u,ll x){ if(tr[u].l==x&&tr[u].r==x){ if(tr[u].lnode==0){ tr[u].lnode^=1,tr[u].rnode^=1; tr[u].lmax=tr[u].rmax=tr[u].ansmax=0; }else{ tr[u].lnode^=1,tr[u].rnode^=1; tr[u].lmax=tr[u].rmax=tr[u].ansmax=1; } }else{ ll mid=tr[u].l+tr[u].r>>1; if(x<=mid)modify(u<<1,x); else modify(u<<1|1,x); pushup(u); } } Node query(ll u,ll l,ll r){ if(l<=tr[u].l&&tr[u].r<=r)return tr[u]; else{ ll mid=tr[u].l+tr[u].r>>1; if(r<=mid)return query(u<<1,l,r); else if(l>mid)return query(u<<1|1,l,r); else{ Node res; auto left=query(u<<1,l,r); auto right=query(u<<1|1,l,r); pushup(res,left,right); return res; } } } signed main(){ cin>>n>>q; build(1,1,n); while(q--){ ll op; cin>>op; if(op==1){ ll x;cin>>x; modify(1,x); }else{ ll x,y;cin>>x>>y; Node ans=query(1,x,y); cout<<ans.ansmax<<endl; } } return 0; }
总结:这篇没啥好总结的,都赛时出的,赛后还有题没补,持续更新ing