zoukankan      html  css  js  c++  java
  • 牛客网练习赛21(补题) ABE

    https://www.nowcoder.com/acm/contest/130#question

    ////A
    //
    //
    ////#include<iostream>
    ////#include<cstdio>
    ////#include<cstring>
    ////#include<cmath>
    ////#include<queue>
    ////#include<set>
    ////#include<algorithm>
    ////#include<map>
    ////#define maxn 200005
    ////typedef long long ll;
    ////using namespace std;
    ////int gcd(ll a,ll b)
    ////{
    ////   return  b==0?a:gcd(b,a%b);
    ////}
    ////ll a,b,c;
    ////int main()
    ////{
    ////    int T;
    ////    cin>>T;
    ////    while(T--)
    ////    {
    ////        int flag=0;
    ////        cin>>a>>b>>c;
    ////       ll s1=gcd(a,b);
    ////       ll s2=gcd(s1,c);
    ////       ll z1=max(a,b);
    ////       ll z2=max(z1,c);
    ////        cout<<z2/s2-3<<endl;
    ////    }
    ////    return 0;
    ////}
    //
    //
    //
    ////B
    //题目理解错误代码
    
    //#include<iostream>
    //#include<cstdio>
    //#include<cstring>
    //#include<cmath>
    //#include<queue>
    //#include<set>
    //#include<algorithm>
    //#include<map>
    //#define maxn 200005
    //typedef long long ll;
    //using namespace std;
    //struct node
    //{
    //    int cha,x,y,ans=0;
    //};
    //int m,n,res;
    //int vis[1000][1000];
    //int mp[1000][1000];
    //int nx[2]={0,1};
    //int ny[2]={1,0};
    //node s1,s2,s3;
    //queue<node>que;
    //void bfs(int i,int j)
    //{
    //    if(i<0||i>m||j<0||j>m)return ;
    //    s1.x=i;s1.y=j;s1.cha=mp[i][j];
    //    s1.ans++;
    //    que.push(s1);
    //    //vis[i][j]=1;
    //    while(!que.empty())
    //    {
    //        s2=que.front();
    //        que.pop();
    //    if(s2.x==m&&s2.y==n)res=s2.cha;
    //    for(int i=0;i<2;i++)
    //    {
    //        s3.x=s2.x+nx[i];
    //        s3.y=s2.y+ny[i];
    //        s3.ans=s2.ans+1;
    //        if(!vis[s3.x][s3.y]&&s3.x<=m&&s3.y<=n)
    //        {
    //            if(s3.ans%2==0){
    //             s3.cha=s2.cha-mp[s3.x][s3.y];
    //            }
    //            else s3.cha=s2.cha+mp[s3.x][s3.y];
    //            vis[s3.x][s3.y]=1;
    //            que.push(s3);
    //        }
    //        if(vis[s3.x][s3.y]&&s3.x<=m&&s3.y<=n)
    //        {
    //            if(s3.ans%2==0){
    //           s3.cha=min(s3.cha,s2.cha-mp[s3.x][s3.y]);
    //            }
    //            else s3.cha=min(s3.cha,s2.cha+mp[s3.x][s3.y]);
    //           que.push(s3);
    //        }
    //    }
    //    }
    //}
    //int main()
    //{
    //    int t;
    //    cin>>t;
    //    while(t--)
    //    {
    //        res=0;
    //        memset(vis,0,sizeof(vis));
    //        cin>>m>>n;
    //        for(int i=1;i<=m;i++)
    //            for(int j=1;j<=n;j++)
    //        {
    //            cin>>mp[i][j];
    //        }
    //        bfs(1,1);
    //        cout<<res<<endl;
    //    }
    //    return 0;
    //}
    
    
    
    //正解
    
    //#include<iostream>
    //#include<cstdio>
    //#include<cstring>
    //#include<cmath>
    //#include<queue>
    //#include<set>
    //#include<algorithm>
    //#include<map>
    //#define maxn 200005
    //typedef long long ll;
    //using namespace std;
    //int n,m,T;
    //int mp[505][505];
    //int main()
    //{
    //ios::sync_with_stdio(false);
    //    cin>>T;
    //    while(T--){
    //        cin>>n>>m;
    //        for(int i=1;i<=n;++i)
    //            for(int j=1;j<=m;++j)
    //                cin>>mp[i][j];
    //        for(int i=n;i>=1;i--)
    //            for(int j=m;j>=1;j--){
    //                if(i!=n&&j!=m)  mp[i][j]-=max(mp[i][j+1],mp[i+1][j]);
    //                else if(i!=n&&j==m)  mp[i][j]-=mp[i+1][j];
    //                else if(i==n&&j!=m)  mp[i][j]-=mp[i][j+1];
    //            }
    //        cout<<mp[1][1]<<endl;
    //    }
    //
    //    return 0;
    //}
    
    
    
    //D
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #include<set>
    #include<algorithm>
    #include<map>
    #define maxn 200005
    #define inf 100000000005
    typedef long long ll;
    using namespace std;
    ll n,k,res,x[10005],y[10005],ans[10005];
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
          memset(ans,0,sizeof(ans));
          cin>>n>>k;
          ll flag=inf;
          for(int i=0;i<n;i++)
          {
              cin>>x[i]>>y[i];
          }
          int z=0;
          for(int i=0;i<n;i++)
          {
              for(int j=0;j<n;j++)
              {
                 for(int t=0;t<n;t++)
                 {
                     ans[t]=abs(x[t]-x[i])+abs(y[t]-y[j]);
                 }
    
          sort(ans,ans+n);
          res=0;
          for(int i=0;i<k;i++)
          {
             // cout<<ans[i]<<endl;
              res+=ans[i];
          }
          flag=min(res,flag);
               }
          }
          cout<<flag<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Spring Boot2 系列教程(二十)Spring Boot 整合JdbcTemplate 多数据源
    Spring Boot 如何给微信公众号返回消息
    Spring Boot2 系列教程(十九)Spring Boot 整合 JdbcTemplate
    Spring Boot2 系列教程(十八)Spring Boot 中自定义 SpringMVC 配置
    Spring Boot 开发微信公众号后台
    Spring Boot2 系列教程(十七)SpringBoot 整合 Swagger2
    Spring Boot2 系列教程(十六)定时任务的两种实现方式
    Spring Boot2 系列教程(十五)定义系统启动任务的两种方式
    Spring Boot2 系列教程(十四)CORS 解决跨域问题
    JavaScript二维数组
  • 原文地址:https://www.cnblogs.com/huangzzz/p/9276496.html
Copyright © 2011-2022 走看看