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
Ran twice 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 to be added to the main function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
T3
dpdpdpdpdpdpdpdpdpdpdpdpdpdpdp
#include <the cmath> #include <the iostream> #include <CString> #include <cstdio> the using namespace STD; const Double INF = 0x3f3f3f3f ; // F [i] [j] represents from A to A to point i and the point j and two distance 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 ; // ensure repeating able to get to a point IF (n-K + == . 1 ) // a come { 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
Di is fart
I will not
#include <the iostream> #include <cstdio> #include <CString> #include < String > the using namespace STD; const Long Long MOD = + 1E9 . 7 ; // F [i] [J] indicates the i-th position before the left than the right parenthesis brackets plurality j-th (j is a prefix and) 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%; // second dimension represents the prefix is not less than zero and the else F [I] [J] = (F [I] [J] + F [I- . 1 ] [+ J . 1 ] + F [I- . 1 ] [J- . 1 ]) MOD%; // add a left or right parenthesis } } for ( int I = 0 ; I <= nm; 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; }
Thanks giant guy ZbWer and xiejinhao %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%