中南林业科技大学第十一届程序设计大赛 A B C D E K G题

啊 菜鸡是后面补的题 看人家谁ac的多 然后 就开始慢慢的补题 嗯 直接上代码 应该都不是难题 

这个是 A题

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
char p[105];
string slove(int ll)
{
    // printf("%d\n",ll);
      string ss;
      ss.clear();
      char ww[5];
      int sum=0;
      while(ll!=0)
      {
           ww[sum++]=ll%26+'a';
           ll/=26;
      }
      while(sum<3)
         ww[sum++]='a';
    for(int i=sum-1;i>=0;i--)
        ss+=ww[i];
        return ss;
}
int main()
{
     int t,len,ll;
     string ss;
     scanf("%d",&t);
     while(t--)
     {
           ss.clear();
          scanf("%d",&len);
          scanf("%s",p);

          for(int i=0;i<len;i+=5)
          {
                 ll=0;
                 for(int j=i;j<=i+4;j++)
                 {
                       ll=ll*10+(p[j]-'0');
                 }
                   ss+=slove(ll);
          }
          cout<<ss<<endl;
     }
    return 0;
}

B题   

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
int p[105];
int main()
{
    int t,sum=0;
    while(~scanf("%d",&t))
    {
        sum=0;
        for(int i=0; i<t; i++)
            scanf("%d",p+i);
        for(int i=0; i<t; i++)
        {
            for(int j=i+1; j<t; j++)
            {
                if(p[i]*2==p[j])
                    sum++;
            }
        }
        printf("%d\n",sum);
    }

    return 0;
}

然后下面的是 K题(第一求出来逆元 然后多mod 就行了)

#include<algorithm>
#include<string.h>
#include<stdio.h>
#define LL unsigned long long
using namespace std;
const LL mod=1000000007;
const LL niyuan=166666668;
int main()
{
    LL n;
    while(~scanf("%llu",&n))
    {
        LL u=(n%mod)*((n+1)%mod);
        LL ans=(u%mod)*((2*n+1)%mod);
        ans=(ans%mod*niyuan%mod)%mod;
        printf("%llu\n",ans);
    }
    return 0;
}

C题有好多种解法 我想说的是两种 第一种是普通解法 但是会非常慢 巨慢 那种 本人不太建议的一种

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
int main()
{
      unsigned long long int t,sum;
    while(~scanf("%llu",&t))
    {
            sum=0;
            while(t)
            {
                 if(t&1)
                 sum++;
                 t/=2;
            }
            printf("%llu\n",sum);
    }
    return 0;
}
第二种 是利用位运算 & &的作用就是 当两个数字都为1的时候才为1  然后 我们要 想一想 人家要的是 一的 个数 每次去掉一个1 就好了 这样就降低了 复杂度 那么 我们每次都让 n&(n-1)比如 1111  那么减去1 就是 1110 结果就是 1110 如果是 1100 减去1就是 1011 那么答案就是1000 那么这样就可以写出程序
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
int main()
{
      unsigned long long int t,sum;
    while(~scanf("%llu",&t))
    {
            sum=0;
            while(t)
            {
                 t&=(t-1);
                 sum++;
            }
            printf("%llu\n",sum);
    }
    return 0;
}

D题 反正我是找的规律

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
int main()
{
    long long int t;
    while(~scanf("%lld",&t))
    {   
          //
           t=t-(long long int)sqrt(t);
           printf("%lld\n",t);
    }
    return 0;
}

E题的话 就是一个向上取整还有向下取整 而且要加上原来变化的

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
//向下取整 floor
//向上取整ceil
int main()
{
     int t,jin,jin1,yin,yin1,tong,tong1,sum,summ;
     while(~scanf("%d",&t))
     {
             jin=floor(t*0.1);
             jin1=ceil(t*0.1);
             sum=jin1-jin;
             yin=floor(t*0.2);
             yin1=ceil(t*0.2);
             summ=yin1-yin;
             tong=floor(t*0.3);
             tong1=ceil(t*0.3);
             printf("%d %d %d\n",sum,sum+summ,tong1-tong+sum+summ);
     }
    return 0;
}

G题的话 数据结构了解一波???

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
int p;
int main()
{
     int n,ans,a,b;
     while(~scanf("%d",&n))
     {
      priority_queue<int,vector<int>,greater<int> >pp;
            ans=0;
           for(int i=0;i<n;i++)
           {
               scanf("%d",&p);
               pp.push(p);
           }
          while(!pp.empty())
          {
                a=pp.top();
                pp.pop();
                if(!pp.empty())
                {
                     b=pp.top();
                     pp.pop();
                }
               else
                  break;
                ans+=a+b;
                pp.push(a+b);
          }
       printf("%d\n",ans);
     }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41071646/article/details/80385889