弱鸡儿长乐爆零旅Day2
T1
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int a[55],ans[55]; int main() { //freopen("soccer.in","r",stdin); //freopen("soccer.out","w",stdout); int n; scanf("%d",&n); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { char ch; cin>>ch; if(ch=='W') a[i]+=3; else if(ch=='L') a[j]+=3; else{ a[i]+=1; a[j]+=1; } } } int temp=-1,tot=0; for(int i=1;i<=n;i++) { if(temp<a[i]) { tot=0; memset(ans,0,sizeof(ans)); ans[++tot]=i; temp=a[i]; } else if(temp==a[i]) { ans[++tot]=i; } } for(int i=1;i<=n;i++) { if(ans[i]) printf("%d ",ans[i]); } return 0; }
T2
跑两遍dijkstra
#include<iostream> #include<cstdio> #include<queue> #include<cstring> using namespace std; const int N=3005,M=100010; struct rex{ int x; int y; int z; }a[M]; int edge[M],ver[M],nxt[M],tot,head[N],vis[N]; int n,m,q,u,v; void add(int x,int y,int z) { edge[++tot]=z; ver[tot]=y; nxt[tot]=head[x]; head[x]=tot; } int dis[N][2]; void dj(int op) { memset(vis,0,sizeof(vis)); priority_queue < pair<int,int> >que; dis[1][op]=0; que.push(make_pair(0,1)); while(!que.empty()) { int x=que.top().second; que.pop(); if(vis[x])continue; vis[x]=1; for(int i=head[x];i;i=nxt[i]) { int y=ver[i],z=edge[i]; if(dis[y][op]>dis[x][op]+z) { dis[y][op]=dis[x][op]+z; que.push(make_pair(-dis[y][op],y)); } } } } int main() { //freopen("production.in","r",stdin); //freopen("production.out","w",stdout); scanf("%d%d",&n,&m); memset(dis,0x7f,sizeof(dis)); for(int i=1;i<=m;i++) { scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z); add(a[i].x,a[i].y,a[i].z); } dj(0); tot=0; memset(head,0,sizeof(head)); memset(ver,0,sizeof(ver)); memset(edge,0,sizeof(edge)); memset(nxt,0,sizeof(nxt)); for(int i=1;i<=m;i++) add(a[i].y,a[i].x,a[i].z); dj(1); scanf("%d",&q); for(int i=1;i<=q;i++) { int x,y; scanf("%d%d",&x,&y); if(dis[x][1]!=0x7f7f7f7f && dis[y][0]!=0x7f7f7f7f) printf("%d\n",dis[x][1]+dis[y][0]); else printf("-1\n"); } return 0; }
freopen要加在主函数里aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
T3
dpdpdpdpdpdpdpdpdpdpdpdpdpdpdp
#include<cmath> #include<iostream> #include<cstring> #include<cstdio> using namespace std; const double INF=0x3f3f3f3f; //f[i][j]表示从A到i点和A到j点两段距离的和 double f[1010][1010]; struct rec{ double x,y; }a[1005]; double dis(int i,int j) { double x=a[i].x-a[j].x; double y=a[i].y-a[j].y; return sqrt(x*x+y*y); } int main() { int n,b1,b2; scanf("%d%d%d",&n,&b1,&b2); b1++,b2++; for(int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=INF; f[1][1]=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(i!=1 && i==j)continue; int k=max(i,j)+1;//保证走不到重复的点 if(k==n+1)//有一个走到了 { if(i!=n) f[n][n]=min(f[n][n],f[i][j]+dis(i,n)); if(j!=n) f[n][n]=min(f[n][n],f[i][j]+dis(j,n)); continue; } if(k!=b1) f[i][k]=min(f[i][k],f[i][j]+dis(j,k)); if(k!=b2) f[k][j]=min(f[k][j],f[i][j]+dis(i,k)); } } printf("%.2lf",f[n][n]); return 0; }
T4
又是迪屁
我又不会
#include<iostream> #include<cstdio> #include<cstring> #include<string> using namespace std; const long long mod=1e9+7; //f[i][j]表示前i个位置 左括号比右括号多j个(j就是前缀和) long long f[2010][2010],ans; string s; int main() { int n,m; scanf("%d%d",&n,&m); cin>>s; int T=0,Min=0x3f3f3f3f; for(int i=0;i<s.length();i++) { if(s[i]=='(') T++; else if(s[i]==')') T--; Min=min(T,Min); } f[0][0]=1; for(int i=1;i<=n-m;i++) { for(int j=0;j<=i;j++) { if(j==0) f[i][j]=(f[i][j]+f[i-1][j+1])%mod;//第二维表示的前缀和不能小于零 else f[i][j]=(f[i][j]+f[i-1][j+1]+f[i-1][j-1])%mod;//添加左括号或右括号 } } for(int i=0;i<=n-m;i++) { for(int j=0;j<=i;j++) { if(j+Min>=0 && j+T<=n-m) ans=(ans+f[i][j]*f[n-m-i][j+T])%mod; } } printf("%lld",ans); return 0; }
感谢巨佬ZbWer与xiejinhao%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%