2017-11-8 NOIP模拟赛

时间:2022-12-17 10:40:06

1.足球联赛

2017-11-8 NOIP模拟赛

2017-11-8 NOIP模拟赛

 

2017-11-8 NOIP模拟赛2017-11-8 NOIP模拟赛
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
struct node{
    int sc,id;
}a[51];
char s[51][51];
bool cmp(node x,node y){
    if(x.sc!=y.sc)return x.sc>y.sc;
    return x.id<y.id;
}
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[i]+1),a[i].id=i;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i==j)continue;
            if(s[i][j]=='W')a[i].sc+=3;
            if(s[i][j]=='L')a[j].sc+=3;
            if(s[i][j]=='D')a[i].sc+=1,a[j].sc+=1;
        }
    }
    sort(a+1,a+n+1,cmp);
    int ans=a[1].sc;printf("%d ",a[1].id);
    for(int i=2;i<=n;i++){
        if(a[i].sc!=ans)return 0;
        printf("%d ",a[i].id);
    }
    return 0;
}
100分

 

 

 

 

2.最短路径

2017-11-8 NOIP模拟赛

2017-11-8 NOIP模拟赛

 

2017-11-8 NOIP模拟赛2017-11-8 NOIP模拟赛
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<queue>
#define maxn 1010
using namespace std;
int n,b1,b2,pre[maxn];
double x[maxn],y[maxn],dis[maxn][maxn],d[maxn];
double ans=1000000000000000000;
bool vis[maxn],v[maxn];
double Calc(double a1,double b1,double a2,double b2){
    double res;
    res=sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
    return res;
}
void dfs(int pos,double sum){
    if(sum>=ans)return;
    if(x[pos]>x[b1]&&vis[b1]==0)return;
    if(pos==n){
        int p=n;
        for(int i=n;i>=1;i--){
            if(!vis[i]){
                sum+=dis[i][p];
                p=i;
                if(sum>=ans)return;
            }
        }
        ans=min(ans,sum);
        return;
    }
    for(int i=pos+1;i<=n;i++){
        if(i==b2)continue;
        if(i==b1){
            vis[i]=1;
            dfs(i,sum+dis[pos][i]);
            vis[i]=0;
            break;
        }
        vis[i]=1;
        dfs(i,sum+dis[pos][i]);
        vis[i]=0;    
    }
}

struct node{
    double v;
    int id;
    bool operator < (const node x)const{
        return v>x.v;
    }
};
node make_node(double v,int id){
    node res;res.v=v;res.id=id;
    return res;
}
double Dij1(){
    priority_queue<node>q;
    q.push(make_node(0,1));
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++)d[i]=1000000000;
    d[1]=0;
    while(!q.empty()){
        node now=q.top();q.pop();
        if(vis[now.id])continue;
        vis[now.id]=1;
        for(int i=now.id+1;i<=n;i++){
            if(i>b1)break;
            if(d[i]>d[now.id]+dis[now.id][i]){
                d[i]=d[now.id]+dis[now.id][i];
                q.push(make_node(d[i],i));
                pre[i]=now.id;
            }
        }
    }
}
double Dij2(){
    priority_queue<node>q;
    q.push(make_node(d[b1],b1));
    vis[b1]=0;
    while(!q.empty()){
        node now=q.top();q.pop();
        if(vis[now.id])continue;
        vis[now.id]=1;
        for(int i=now.id+1;i<=n;i++){
            if(d[i]>d[now.id]+dis[now.id][i]){
                d[i]=d[now.id]+dis[now.id][i];
                q.push(make_node(d[i],i));
                pre[i]=now.id;
            }
        }
    }
    double res=0;
    int now=n;
    while(now){
        v[now]=1;
        res+=dis[now][pre[now]];
        now=pre[now];
    }
    v[1]=0;
    int p=n;
    for(int i=n;i>=1;i--){
        if(!v[i]){
            res+=dis[i][p];
            p=i;
        }
    }
    return res;
}

int main(){
    freopen("paths.in","r",stdin);freopen("paths.out","w",stdout);
//    freopen("Cola.txt","r",stdin);
    scanf("%d%d%d",&n,&b1,&b2);
    b1++;b2++;
    for(int i=1;i<=n;i++)scanf("%lf%lf",&x[i],&y[i]);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++){
            double d=Calc(x[i],y[i],x[j],y[j]);
            dis[i][j]=dis[j][i]=d;
        }
    if(n<=20){//爆搜 
        dfs(1,0);
        printf("%.2lf",ans);
        return 0;
    }
    else{//贪心 
        double ans1=0,ans2=0;
        memset(v,0,sizeof(v));
        Dij1();
        ans1=Dij2();
        printf("%.2lf",ans1);
    }
}
20分 暴力

 

 

 

3.阿Q的停车场

2017-11-8 NOIP模拟赛

2017-11-8 NOIP模拟赛

 

2017-11-8 NOIP模拟赛2017-11-8 NOIP模拟赛
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,F,x,pos[1000010],car[200010];
bool check(int x){
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(car[i]==0)cnt++;
        else cnt=0;
        if(cnt>=x)return 1;
    }
    return 0;
}
void Insert(int id){
    int l=0,r=1000000,mid,len=0;
    while(l<=r){
        mid=(l+r)>>1;
        if(check(mid))len=mid,l=mid+1;
        else r=mid-1;
    }
    if(len%2==0)len-=1;
    l=1,r=0;
    int Pos;
    for(int i=1;i<=n;i++){
        if(car[i]==0)r=i;
        if(car[i]>0)l=i+1;
        if(r-l+1>=len)break;
    }
    if(r==n-1&&car[n]==0)r=n;
    if(l==1){
        puts("1");
        pos[id]=1;
        car[1]=id;
        return;
    }
    else if(r==n){
        printf("%d\n",n);
        pos[id]=n;
        car[n]=id;
        return;
    }
    Pos=l+len/2;
    pos[id]=Pos;
    car[Pos]=id;
    printf("%d\n",Pos);
}
int main(){
//    freopen("park.in","r",stdin);freopen("park.out","w",stdout);
//    freopen("Cola.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&F,&x);
        if(F==1){
            if(i==1){
                puts("1");
                car[1]=x;
                pos[x]=1;
            }
            else Insert(x);
        }
        if(F==2){
            car[pos[x]]=0;
            pos[x]=0;
        }
    }
}
10分 暴力