2019西北工业大学程序设计创新实践基地春季选拔赛(重现赛)补题笔记

A Chino with Geometry

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
double dis(double x1,double y1,double x2,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
    int ix0,iy0,ir,ix1,iy1,iy2;
    cin >> ix0 >> iy0 >> ir >>ix1 >> iy1 >> iy2;
    double x0 = (double)ix0,y0 = (double)iy0,r = (double)ir,x1 = (double)ix1,y1 = (double)iy1
        ,y2 = (double)iy2;
    //printf("%lf %lf %lf %lf\n",y1,y2,x1,x0);
    double k = (y1-y2)/x1;
    double a=(1+k*k),b=(2*(y2-y0)*k-2*x0),c=x0*x0+(y2-y0)*(y2-y0)-r*r;
    double dlta = b*b - 4*a*c;
    double sx1 = (-b+sqrt(dlta))/(2*a),sx2 = (-b-sqrt(dlta))/(2*a);
    double sy1 = k*sx1 + y2 ,sy2 = k*sx2 + y2;
    //printf("%lf %lf %lf %lf\n",k,sy1,sx2,sy2);
    cout << (long long)(dis(sx1,sy1,x1,y1)*dis(sx2,sy2,x1,y1)+0.5) << endl;
    return 0;
}

B Chino with Repeater

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int t = log(n)/log(2);
    if(n==(1<<t))cout << t << endl;
    else cout << t+1 << endl;
    return 0;
}

D Chino with Equation

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll exgcd(ll a,ll b,ll& x,ll& y){
    if(a%b==0){
        x=0,y=1;
        return b;
    }
    ll r,tx,ty;
    r=exgcd(b,a%b,tx,ty);
    x=ty;
    y=tx-a/b*ty;
    return 0;
}
 
ll comp(ll a,ll b,ll m){
    if(a<b) return 0;
    if(a==b) return 1;
    if(b>a-b) b=a-b;
    ll ans=1,ca=1,cb=1;
    for(int i=0;i<b;i++){
        ca=ca*(a-i)%m;
        cb=cb*(b-i)%m;
    }
    ll x,y;
    exgcd(cb,m,x,y);
    x=(x%mod+mod)%m;
    ans=ca*x%m;
    return ans;
}
 
ll lucas(ll a,ll b,ll m){
    ll ans=1;
    while(a&&b){
        ans=(ans*comp(a%m,b%m,m))%m;
        a/=m;
        b/=m;
    }
    return ans;
}
int main()
{
    ll m,n;
    cin >> m >> n ;
    cout << lucas(n-1,m-1,mod) << ' ' << lucas(m+n-1,m-1,mod) << endl;
    return 0;
}

F Chino with Expectation

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1e5+10;
int a[N]={0};
int main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        a[i]+=a[i-1];
    }
    while(q--)
    {
        int x,l,r;
        scanf("%d%d%d",&x,&l,&r);
        double ans = a[r]-a[l-1];
        double p = (r-l+1)/(double)n;
        printf("%.6lf\n",ans/(r-l+1)*(1-p)+(ans+x)/(r-l+1)*(p));
    }
    return 0;
}

G Chino with Train to the Rabbit Town

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N =5e5+10;
int w[N],dp[N]={0},pre[N];
int main()
{
    int n,k,mx=0;
    scanf("%d%d",&n,&k);
    memset(pre,-1,sizeof(pre));
    dp[0]=w[0]=pre[0]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&w[i]);
        w[i]^=w[i-1];
        dp[i]=dp[i-1];
        if(pre[w[i]^k]!=-1)
            dp[i]=max(dp[i],dp[pre[w[i]^k]]+1);
        mx=max(mx,dp[i]);
        pre[w[i]]=i;
    }
    printf("%d\n",mx);
    return 0;
}

H Chino with Ciste

#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
typedef pair<int,int> PII;
const int N =2e3+10;
struct s
{
    int x,y,step,turns,d;
    s(int _x,int _y,int _s,int _t,int _d):x(_x),y(_y),step(_s),turns(_t),d(_d){}
    bool operator < (const s &a) const
    {
        if(a.turns!=turns)return a.turns < turns;
        else return a.step < step;
    }
};
char mp[N][N];
int ans=0,vis[N][N];
pair<int,int>dir[4]={{1,0},{-1,0},{0,1},{0,-1}};
priority_queue <s> q;
PII S,E;
int n,m;
int bfs()
{
    int flag=1;
    while(!q.empty())q.pop();
    q.push(s(S.first,S.second,0,0,0));
    vis[S.first][S.second]=1;
    while(!q.empty())
    {
        s z = q.top();
        q.pop();
        //cout << z.x << " " << z.y << " " << z.d << endl;
        if(z.x==E.first&&z.y==E.second)
        {
            printf("%d\n",z.turns);
            flag=0;
            return 0;
        }
        for(int i=0;i<4;i++)
        {
            int x1=z.x+dir[i].first,y1 = z.y+dir[i].second;
            if(x1>=0&&x1<n&&y1>=0&&y1<m&&(!vis[x1][y1])&&mp[x1][y1]!='*')
            {
                vis[z.x][z.y]=1;
                if(z.d==0)
                {
                    if(i<2)q.push(s(x1,y1,z.step+1,z.turns,1));
                    else q.push(s(x1,y1,z.step+1,z.turns,2));
                }
                else if(i<2)
                {
                    if(z.d==1)q.push(s(x1,y1,z.step+1,z.turns,1));
                    else q.push(s(x1,y1,z.step+1,z.turns+1,1));
                }
                else
                {
                    if(z.d==1)q.push(s(x1,y1,z.step+1,z.turns+1,2));
                    else q.push(s(x1,y1,z.step+1,z.turns,2));
                }
            }
        }
    }
    if(flag)printf("troil\n");
    return 0;
}
int main()
{
    memset(vis,0,sizeof(vis));
    scanf("%d%d",&n,&m);
    getchar();
    for(int i=0;i<n;i++)
        for(int j=0;j<=m;j++)
        {
            mp[i][j]=getchar();
            if(mp[i][j]=='S')S = {i,j};
            if(mp[i][j]=='T')E = {i,j};
        }
    //printf("%d %d %d %d \n",S.first,S.second,E.first,E.second);
    bfs();
    return 0;
}

C Chino with Queue

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int n;
struct ios {
    inline char read(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }

    template <typename _Tp> inline ios & operator >> (_Tp&x){
        static char c11,boo;
        for(c11=read(),boo=0;!isdigit(c11);c11=read()){
            if(c11==-1)return *this;
            boo|=c11=='-';
        }
        for(x=0;isdigit(c11);c11=read())x=x*10+(c11^'0');
        boo&&(x=-x);
        return *this;
    }
} io;
const int N=20;
int w[N][N],dp[N][1<<N];
int slove()
{
    for(int i=0;i<n;i++)dp[i][1<<i]=w[i][i];
    for(int i=1;i<(1<<n);++i)
        for(int j=0;j<n;++j)
            for(int k=0;k<n;++k)
            {
                if(((i&(1<<j))==0)&&(i&(1<<k)))
                {
                    dp[j][i|(1<<j)]=max(dp[j][i|(1<<j)],dp[k][i]+w[j][k]);
                }
            }
    int mx=0;
    for(int i=0;i<n;i++)mx = max(dp[i][(1<<n)-1],mx);
    return mx;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            io >> w[i][j];
    printf("%d",slove());
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值