• 黑龙江大学程序设计竞赛(重现赛)


    A:

    Find the Nth Character

    题目描述

    今天在给

    的同学们上程序算法课的时候出了一道找规律的题目,题目表述如下
    假设:
    现在要求上课的同学们把所有的串依次连接起来,于是得到:

    那么你能告诉串中的第个字母是多少吗?




    输入描述:

    输入首先是一个数字,代表有次询问

    接下来的行每行有一个整数

    输出描述:

    对于每次询问,输出串中第个位置对应的字母。

    示例1

    输入

    复制
    6
    1
    2
    3
    4
    5
    10

    输出

    复制
    a
    a
    b
    a
    b
    d
    思路:这个题目似曾相识的感觉。。直接上代码吧
    #include<iostream>
    #include<vector>
    #include<string>
    #include<cstring>
    #include<cmath>
    #include <algorithm>
    #include <stdlib.h>
    #include <cstdio>
    #include<sstream>
    #include<cctype>
    #include <queue>
    #include <map>
    #define ll long long
    using namespace std;
    char c[10010];
    int main()
    {
        ll t,q;
        cin>>t;
        for(ll i=1;i<=t;i++)
        {
            cin>>q;ll k=0;
            while(q-k*(k+1)/2>0)
            {
                k++;
            }
            --k;
            if(q-k*(k+1)/2==0) {if(k%26==0) k=26;else k%=26;cout<<char(96+k)<<endl;}
            else {
                q-=k*(k+1)/2;
                {if(q%26==0) q=26;else q%=26;cout<<char(96+q)<<endl;}
            }
        }
    }

     下面代码是借鉴别人的:

    #include<iostream>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int main()
    {
        int n,T;
        while(~scanf("%d",&T))
        {
            while(T--)
            {
                scanf("%d",&n);
                int x=floor(0.5*(-1+sqrt(1+8*n))-0.001);
                // printf("x=%d
    ",x);
                x=n-x*(x+1)/2;
                putchar('a'+(x-1)%26);
                puts("");
            }
        }
        return 0;
    }

     C: 

      

    爱的魔力转圈圈,想你想到心花怒放黑夜白天,可是我害怕爱情只是一瞬间,转眼会不见,我要慢慢冒险。经过了无数的思想斗争,他要做出这个决定,和喜欢的女孩子表白,但女孩只是留给他一个排列,排列的定义是一个由组成的序列每个数出现并且只出现1次。


    现在他需要把个数通过一定顺序首尾连接形成一个圆环,使得相邻元素互质的对数尽可能多,请输出最大的对数。两个数互质的定义是这两个数的GCD(最大公约数)为1。比如6和4的最大公约数为2,不互质。4和3的最大公约数为1,互质。


    输入描述:

    第一行是一个数字,表示共有T组测试数据.

    接下来行,每行一个数字.

    输出描述:

    一行一个整数表示答案
    示例1

    输入

    复制
    2
    3
    5

    输出

    复制
    3
    5
    简单暴力。
    #include<iostream>
    #include<vector>
    #include<string>
    #include<cstring>
    #include<cmath>
    #include <algorithm>
    #include <stdlib.h>
    #include <cstdio>
    #include<sstream>
    #include<cctype>
    #include <queue>
    #include <map>
    #define ll long long
    using namespace std;
    int c[10010];
    bool gcd(int a,int b)
    {
        if(a<b) swap(a,b);
        int r=a%b;
        while(r)
        {
            a=b;
            b=r;
            r=a%b;
        }
        if(b==1) return 1;
        else return 0;
    }
    int main()
    {
        for(int i=1;i<=1000;++i)
            c[i]=i;
       ll t,q;
       cin>>t;
       while(t--)
       {
           cin>>q;int Max=-1000;
            sort(c+1,c+1001);
           do
           {
               int sum=0;
               if(gcd(c[1],c[q])) ++sum;
               for(ll i=1;i<q;++i)
               {
                   if(gcd(c[i],c[i+1])) ++sum;
               }
               Max=max(sum,Max);
               if(sum==q) {break;}
           }while(next_permutation(c+1,c+t+1));
           cout<<Max<<endl;
       }
    }
    View Code

     K:

    链接:https://ac.nowcoder.com/acm/contest/877/K
    来源:牛客网

    题目描述

    输入描述:

    输出描述:

    示例1

    输入

    复制
    2
    35
    1000000000

    输出

    复制
    17
    82

    说明

    In the first example, you can choose, for example,a = 17 andb = 18, so thatS(17) + S(18) = 1 + 7 + 1 + 8 = 17. It can be shown that it is impossible to get a larger answer.

    In the second test example, you can choose, for example,a = 500000001 andb = 499999999, withS(500000001) + S(499999999) = 82. It can be shown that it is impossible to get a larger answer.

    靠感觉贪心吧。是其中某个数尽可能每一位都是9,比如35,可以是9+(35-9)=35,如果是99就大于35了。
    #include<iostream>
    #include<vector>
    #include<string>
    #include<cstring>
    #include<cmath>
    #include <algorithm>
    #include <stdlib.h>
    #include <cstdio>
    #include<sstream>
    #include<cctype>
    #include <queue>
    #include <map>
    #define ll long long
    using namespace std;
    int  ans[100100],sum[100100];
    int main()
    {
        ll t,n,m;
        cin>>t;
        while(t--)
        {
            cin>>n;
            ll s=0;
            while(n>s)
            {
                s=s*10+9;
            }
            s=(s-9)/10;
            ll sum=0;
            ll a=n-s;
            while(s)
            {
                sum+=s%10;
                s/=10;
            }
            while(a)
            {
                sum+=a%10;
                a/=10;
            }
            cout<<sum<<endl;
        }
    }
    View Code

    剩下的有题解后再补



  • 相关阅读:
    【转】MySQL innodb_autoinc_lock_mode 详解 ,并发插入时主键冲突的解决方案
    optimize table在优化mysql时很重要
    Spring MVC+Mybatis 多数据源配置及发现的几个问题
    Mysql主键一致时,可以进行在元数据上的操作
    同一条sql在mysql5.6和5.7版本遇到的问题。
    实现ApplicationContextAware接口时,获取ApplicationContext为null
    获取访问者的IP
    for...in...
    CSS hack
    Base64
  • 原文地址:https://www.cnblogs.com/Auroras/p/10774052.html
Copyright © 2020-2023  润新知