11.8模拟赛
题解:模拟
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,mx; int c[55],ans[55]; char s[55]; int main(){ freopen("soccer.in","r",stdin); freopen("soccer.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s",s+1); for(int j=1;j<=n;j++){ if(s[j]=='W')c[i]+=3; if(s[j]=='L')c[j]+=3; if(s[j]=='D')c[i]++,c[j]++; } } for(int i=1;i<=n;i++)mx=max(mx,c[i]); for(int i=1;i<=n;i++)if(c[i]==mx)printf("%d ",i); fclose(stdin);fclose(stdout); return 0; }
题解:
暴力
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define N 1020 using namespace std; int n,b1,b2; int vis[55]; double xi[N],yi[N],dis[55][55]; double ans; inline int read(){ char ch=getchar();int x=0,f=1; for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1; for(;isdigit(ch);ch=getchar())x=x*10+ch-'0'; return x*f; } double dist(int x,int y){ return (double)sqrt((xi[y]-xi[x])*(xi[y]-xi[x])+(yi[x]-yi[y])*(yi[x]-yi[y])); } void dfs(int now1,int now2,double sum){ if(now1==n&&now2==n){ if(b1==1)vis[0]=1;if(b2==1)vis[0]=2; if(b1==1&&b2==1)vis[1]=-1; if((vis[b1]==1&&vis[b2]==2)||(vis[1]==-1))ans=min(ans,sum); return; } int k=max(now1,now2); if(k==n)k=min(now1,now2);k++; if(now1!=n&&vis[k]!=2){ if(k!=n)vis[k]=1; dfs(k,now2,sum+dis[now1][k]); vis[k]=0; } if(now2!=n&&vis[k]!=1){ if(k!=n)vis[k]=2; dfs(now1,k,sum+dis[now2][k]); vis[k]=0; } } int main(){ freopen("paths.in","r",stdin); freopen("paths.out","w",stdout); n=read();b1=read();b2=read();b1++;b2++; for(int i=1;i<=n;i++)scanf("%lf%lf",&xi[i],&yi[i]); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) dis[j][i]=dis[i][j]=dist(i,j); ans=1000000000.0;vis[0]=1; dfs(1,1,0.0); printf("%.2lf\n",ans); fclose(stdin);fclose(stdout); return 0; }
题解:
为什么在笔记本里改是不对的...对拍了半天的0分暴力...竟然是对的..
#include<iostream> #include<cstdio> #include<cstring> #define N 1000008 #define M 200005 using namespace std; int n,m,nowcnt; int c[N],w[N]; //c数组离散化,怕车编号有负数,p数组记录停车位置、w数组表示第i辆车停在哪个位置 bool p[N]; inline int read(){ char ch=getchar();int x=0,f=1; for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1; for(;isdigit(ch);ch=getchar())x=x*10+ch-'0'; return x*f; } void stopcar(int x){ int pos,mx=-1; for(int i=1;i<=n+1;i++){ int st=-1; if(p[i]==0)st=i; while(p[i]==0&&i<=n)i++; if(st!=-1){ if(st==1){ if(i-st-1>mx)mx=i-st,pos=1; }else if(i==n+1){ if(i-st-1>mx)mx=i-st,pos=n; }else { int len=i-st; len=(len-1)/2; if(len>mx)mx=len,pos=st+len; } } st=-1; } w[x]=pos;p[pos]=true; printf("%d\n",pos); } int main(){ // freopen("in.txt","r",stdin); // freopen("wa.out","w",stdout); n=read();m=read(); for(int i=1;i<=m;i++){ int od,x; od=read();x=read(); if(od==1){ nowcnt++;c[nowcnt]=x; stopcar(nowcnt); } if(od==2){ for(int j=1;j<=nowcnt;j++){ if(c[j]==x){ p[w[j]]=0;c[j]=10000000;break; } } } } fclose(stdin);fclose(stdout); return 0; }