あいさか たいがblogAisaka_Taiga的博客
//https://img2018.cnblogs.com/blog/1646268/201908/1646268-20190806114008215-138720377.jpg

10.15模拟赛解题报告

10.15模拟赛解题报告

T1#

题面
本题的题目的意思很明白,因为我不会正解所以只能打暴力,40分到手,加上特殊性质直接输出0可以得60分。
暴力代码:

Copy
#include<bits/stdc++.h> #define bug cout<<"WTF?"<<'\n' #define int long long #define P 1000000007 using namespace std; struct sb{int u,v;}e[10010]; int n,m,ans,in[10010],cnt1=0; void dfs(int x,int cnt) { // cnt1++; // if(cnt1>(2e8+5e7))return ; if(cnt<m)return ; if(x==n) { // int sum=0,flag=1; // for(int i=1;i<=n;i++) // if(in[i]==0)sum++; // if(sum!=m)flag=0; // ans+=flag; if(cnt==m)ans=(ans+1)%P; return ; } int u=e[x].u; int v=e[x].v; if(in[u]==0)in[u]++,dfs(x+1,cnt-1),in[u]--; else in[u]++,dfs(x+1,cnt),in[u]--; if(in[v]==0)in[v]++,dfs(x+1,cnt-1),in[v]--; else in[v]++,dfs(x+1,cnt),in[v]--; return ; } signed main() { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); cin>>n>>m; if(m==0) { cout<<0<<endl; return 0; } for(int i=1;i<n;i++) scanf("%lld%lld",&e[i].u,&e[i].v); dfs(1,n); cout<<ans<<endl; // fclose(stdin); // fclose(stdout); return 0; } /* 4 2 1 2 2 3 2 4 */

官方题解:

std:

Copy
#include<bits/stdc++.h> #define N 5005 #define P 1000000007 using namespace std; int i,j,k,l,s,n,m,last[N],to[2*N],tot,a,b,Next[2*N],x,y,q[N],fa[N],si[N]; long long f[N][N][2],ans,F[N][2]; inline void add(int x,int y) { Next[++tot]=last[x]; last[x]=tot; to[tot]=y; } int main() { freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); scanf("%d%d",&n,&m); for (i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x); int l=0,r=1; q[1]=1; while (l<r) { int k=q[++l]; for (int i=last[k];i;i=Next[i]) { if (to[i]!=fa[k]) fa[q[++r]=to[i]]=k; } } for (i=n;i;i--) { f[q[i]][0][0]=1; for (j=last[q[i]];j;j=Next[j]) { if (fa[q[i]]==to[j]) continue; for (a=si[q[i]];a>=0;a--) for (b=si[to[j]];b>=0;b--) { (F[a+b+1][1]+=1ll*f[q[i]][a][1]*f[to[j]][b][0])%=P; (F[a+b+1][1]+=1ll*f[q[i]][a][0]*f[to[j]][b][0])%=P; (F[a+b][1]+=1ll*f[q[i]][a][0]*f[to[j]][b][1])%=P; (F[a+b][1]+=1ll*f[q[i]][a][1]*f[to[j]][b][1]*2)%=P; (F[a+b][0]+=1ll*f[q[i]][a][0]*f[to[j]][b][0])%=P; (F[a+b][0]+=1ll*f[q[i]][a][0]*f[to[j]][b][1])%=P; (F[a+b][1]+=1ll*f[q[i]][a][1]*f[to[j]][b][0])%=P; } si[q[i]]+=si[to[j]]; for (a=0;a<=si[q[i]];a++) { f[q[i]][a][0]=F[a][0],F[a][0]=0; f[q[i]][a][1]=F[a][1],F[a][1]=0; } } si[q[i]]++; } if (m) ans=(f[1][m][1]+f[1][m-1][0])%P; else ans=f[1][m][1]; printf("%lld\n",ans); }

T2#

题面
这道题一开始想打搜索,但是边界条件不好找,所以打了一个暴力枚举到一定的倍数就直接输出找到的答案,一开始考虑过打表,但打的太慢了,一看只有3个数就直接暴力了,考试的时候忘了把逗号去了,爆零了,不然能得40分。
暴力代码:

Copy
#include<bits/stdc++.h> #define P 822337203685477580 #define int long long using namespace std; int t,n,ans,b[5010]; inline int zhuan(int x) { int cnt=0,xx=x; while(xx) { b[++cnt]=xx%2; xx/=2; } int sum=0; for(int i=1;i<=cnt;i++) { if(b[i]==1)sum++; if(sum>ans)break; } return sum; } signed main() { freopen("b.in","r",stdin); freopen("b.out","w",stdout); cin>>t; while(t--) { int cnt1=0; ans=9999; cin>>n; for(int i=1;cnt1<=(1e6+300000);i++) { cnt1++; int summ; if(i*n<=P) summ=zhuan(i*n); ans=min(ans,summ); } cout<<ans<<endl; } }

官方题解:

std:

Copy
#include <bits/stdc++.h> using namespace std; const int offset = 3e6 + 7; int o[offset * 2 + 1]; int f[offset]; bool vis[offset]; int Main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) f[i] = 3000; int h = offset, t = offset; o[h] = 1; f[1] = 1; while (h <= t) { int u = o[h++]; if (f[u] < f[2 * u % n]) { f[ 2 * u % n ] = f[u]; o[--h] = 2 * u % n; } if (f[u] + 1 < f[(2 * u + 1) % n]) { f[ (2 * u + 1) % n ] = f[u] + 1; o[++t] = (2 * u + 1) % n; } } /*cout << f[8 % n] << endl; cout << f[16 % n] << endl; cout << f[32 % n] << endl; cout << f[33 % n] << endl;*/ printf("%d\n", f[0]); return 0; } int main(){ freopen("b.in","r",stdin); freopen("b.out","w",stdout); int x; scanf("%d",&x); for(;x--;){ memset(o,0,sizeof o); memset(f,0,sizeof f); memset(vis,0,sizeof vis); Main(); } }

T3#

题面
这道题看到了也是不会正解,所以考虑部分分,直接枚举4个点然后判断即可,最后得分:29;
暴力代码:

Copy
#include<bits/stdc++.h> using namespace std; int n,m,mp[510][510],ans; int main() { freopen("c.in","r",stdin); freopen("c.out","w",stdout); cin>>n>>m; for(int i=1;i<=m;i++) { int u,v; scanf("%d%d",&u,&v); mp[u][v]=1; mp[v][u]=1; } for(int u=1;u<=n;u++) for(int v=u+1;v<=n;v++) for(int x=v+1;x<=n;x++) for(int y=x+1;y<=n;y++) if(mp[u][v]==1||mp[v][u]==1) if(mp[v][x]==1||mp[x][v]==1) if(mp[x][y]==1||mp[y][x]==1) if(mp[y][u]==1||mp[u][y]==1) ans++; cout<<ans<<endl; return 0; } /* 4 5 1 2 2 3 3 4 4 1 1 3 */

官方题解:

std:

Copy
/* * Author : Remilia Scarlet */ // #pragma comment(linker, "/STACK:102400000,102400000") #include <bits/stdc++.h> #define For(i,l,r) for(int _r=r,i=l;i<=_r;++i) #define rep(i,l,r) for(int _r=r,i=l;i<_r;++i) #define dto(i,r,l) for(int _l=l,i=r;i>=_l;--i) #define x first #define y second #define pb push_back #define mk make_pair #define elif else if #define oo (c=getchar()) #define SZ(V) (int(V.size())) #define ALL(V) V.begin(),V.end() using namespace std; typedef double db; typedef long long LL; typedef pair<int ,int> PII; typedef vector<int> VI; typedef complex<db> cpx; typedef vector<PII> VII; // typedef __int128 bigint; int ran(){return (rand()<<15)+rand();} int IN(){ int x=0;char c; for(;oo<48 && c^'-' || c>57;);bool f=c=='-';if(f)oo; for(;c>47 && c<58;oo)x=(x<<1)+(x<<3)+c-48;return f?-x:x; } void print(int x,char en='\n'){ printf("%d",x);if(en)putchar(en); } void hello(){ freopen("c.in","r",stdin); freopen("c.out","w",stdout); // srand(time(0)); } int aim,n,m,deg[100010],key[100010]; LL ans; VI li[100010]; bool lt(int u,int v){ return deg[u]<deg[v] || deg[u] == deg[v] && u<v; } void dfs(int u,int d){ if(d==0){ aim = u; rep(i,0,SZ(li[u])){ int v = li[u][i]; if(lt(v,aim)){ dfs(v,d+1); } } }elif(d==1){ rep(i,0,SZ(li[u])){ int v = li[u][i]; if(lt(v,aim)){ ans += key[v]; ++key[v]; } } } } void clr(int u,int d){ if(d==0){ aim = u; rep(i,0,SZ(li[u])){ int v = li[u][i]; if(lt(v,aim)){ clr(v,d+1); } } }elif(d==1){ rep(i,0,SZ(li[u])){ int v = li[u][i]; if(lt(v,aim)){ key[v] = 0; } } } } int main(int argc, char* argv[]){ hello(); n = IN(); m = IN(); For(i,1,m){ int u = IN(), v = IN(); li[u].pb(v); li[v].pb(u); ++deg[u]; ++deg[v]; } For(i,1,n){ dfs(i,0); clr(i,0); } printf("%lld\n",ans); }
posted @   北烛青澜  阅读(14)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
目录