哈尔滨理工大学软件与微电子学院程序设计竞赛(新生赛) -补档

time:2019.11.08
题目较多,所以使用目录。

文章目录

    • Problem A:[NowCoder54536 小乐乐学编程](https://ac.nowcoder.com/acm/problem/54536)
    • Problem B:[NowCoder54537 小乐乐算平均分](https://ac.nowcoder.com/acm/problem/54537)
    • Problem C:[NowCoder54538 小乐乐找最大数](https://ac.nowcoder.com/acm/problem/54538)
    • Problem D:[NowCoder54539 小乐乐是否被叫家长](https://ac.nowcoder.com/acm/problem/54539)
    • Problem E:[NowCoder54540 小乐乐转换成绩](https://ac.nowcoder.com/acm/problem/54540)
    • Problem F:[NowCoder54541 小乐乐算多少人被请家长](https://ac.nowcoder.com/acm/problem/54541)
    • Problem G:[NowCoder54542 小乐乐算最高分](https://ac.nowcoder.com/acm/problem/54542)
    • Problem H:[NowCoder54543 小乐乐计算求和](https://ac.nowcoder.com/acm/problem/54543)
    • Problem I:[NowCoder54544 小乐乐计算函数](https://ac.nowcoder.com/acm/problem/54544)
    • Problem J:[NowCoder54545 小乐乐查找数字](https://ac.nowcoder.com/acm/problem/54545)
    • Problem K:[NowCoder54501 小乐乐与进制转换](https://ac.nowcoder.com/acm/problem/54501)
    • Problem L:[NowCoder54502 小乐乐求和](https://ac.nowcoder.com/acm/problem/54502)
    • Problem M:[NowCoder54503 小乐乐定闹钟](https://ac.nowcoder.com/acm/problem/54503)
    • Problem N:[NowCoder54504 小乐乐排电梯](https://ac.nowcoder.com/acm/problem/54504)
    • Problem O:[NowCoder54505 小乐乐与欧几里得](https://ac.nowcoder.com/acm/problem/54505)
    • Problem P:[NowCoder54506 小乐乐改数字](https://ac.nowcoder.com/acm/problem/54506)
    • Problem Q:[NowCoder54507 小乐乐走台阶](https://ac.nowcoder.com/acm/problem/54507)
    • Problem R:[NowCoder54508 小乐乐与序列](https://ac.nowcoder.com/acm/problem/54508)
    • Problem S:[NowCoder54509 小乐乐与字符串](https://ac.nowcoder.com/acm/problem/54509)
    • Problem T:[NowCoder54510 小乐乐与二段数](https://ac.nowcoder.com/acm/problem/54510)

Problem A:NowCoder54536 小乐乐学编程

实践出真知!

//#pragma GCC optimize(2)
#include
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cout<<"Practice makes perfect!"<<endl;
    return 0;
}

Problem B:NowCoder54537 小乐乐算平均分

//#pragma GCC optimize(2)
#include
using namespace std;
double a, b, c;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b>>c;
    printf("%.2lf %.2lf\n", a+b+c, (a+b+c)/3);
    return 0;
}

Problem C:NowCoder54538 小乐乐找最大数

//#pragma GCC optimize(2)
#include
using namespace std;
int n, maxn = -0x3f3f3f3f;
int main()
{
    ios::sync_with_stdio(false);
    for(int i=1; i<=4; i++)
    {
        cin>>n;
        maxn = max(maxn, n);
    }
    cout<<maxn<<endl;
    return 0;
}

Problem D:NowCoder54539 小乐乐是否被叫家长

//#pragma GCC optimize(2)
#include
using namespace std;
int m, c, e;
int main()
{
    ios::sync_with_stdio(false);
    cin>>m>>c>>e;
    if((m+c+e)/3 < 60) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Problem E:NowCoder54540 小乐乐转换成绩

//#pragma GCC optimize(2)
#include
using namespace std;
int n;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    if(n>=90 && n<=100) cout<<"A"<<endl;
    else if(n>=80 && n<=89) cout<<"B"<<endl;
    else if(n>=70 && n<=79) cout<<"C"<<endl;
    else if(n>=60 && n<=69) cout<<"D"<<endl;
    else if(n>=0 && n<=59) cout<<"E"<<endl;
    else cout<<"F"<<endl;
    return 0;
}

Problem F:NowCoder54541 小乐乐算多少人被请家长

//#pragma GCC optimize(2)
#include
using namespace std;
int n, a, b, c, cnt=0;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    while(n--)
    {
        cin>>a>>b>>c;
        if((a+b+c)/3 < 60) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Problem G:NowCoder54542 小乐乐算最高分

//#pragma GCC optimize(2)
#include
using namespace std;
int n, x, maxn = -0x3f3f3f3f;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>x;
        maxn = max(maxn, x);
    }
    cout<<maxn<<endl;
    return 0;
}

Problem H:NowCoder54543 小乐乐计算求和

//#pragma GCC optimize(2)
#include
using namespace std;
int jc(int n)
{
    if(n == 0) return 1;
    else return n*jc(n-1);
}
int main()
{
    ios::sync_with_stdio(false);
    int n, tot=0;
    cin>>n;
    for(int i=1; i<=n; i++)
        tot += jc(i);
    cout<<tot<<endl;
    return 0;
}

Problem I:NowCoder54544 小乐乐计算函数

//#pragma GCC optimize(2)
#include
using namespace std;
int max3(int x, int y, int z)
{
    x = max(x, y);
    x = max(x, z);
    return x;
}
int main()
{
    ios::sync_with_stdio(false);
    int a, b, c;
    cin>>a>>b>>c;
    printf("%.2lf\n", 1.0*max3(a+b, b, c)/(max3(a, b+c, c)+max3(a, b, b+c)));
    return 0;
}

Problem J:NowCoder54545 小乐乐查找数字

//#pragma GCC optimize(2)
#include
using namespace std;
int n, x, a[105];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    cin>>x;
    for(int i=1; i<=n; i++)
        if(a[i] == x) a[104]++;
    cout<<a[104]<<endl;
    return 0;
}

Problem K:NowCoder54501 小乐乐与进制转换

//#pragma GCC optimize(2)
#include
using namespace std;
int n, a[10010], cnt=0;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    while(n)
    {
        a[++cnt] = n%6;
        n /= 6;
    }
    for(int i=cnt; i>=1; i--)
        cout<<a[i];
    return 0;
}

Problem L:NowCoder54502 小乐乐求和

//#pragma GCC optimize(2)
#include
using namespace std;
int n;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    cout<<(long long)n*(n+1)/2<<endl;
    return 0;
}

Problem M:NowCoder54503 小乐乐定闹钟

//#pragma GCC optimize(2)
#include
using namespace std;
int hour, minute, k;
char m;
int main()
{
    ios::sync_with_stdio(false);
    scanf("%d%c%d%d", &hour, &m, &minute, &k);
    minute += k;
    if(minute > 60)
    {
        hour += minute/60;
        minute -= minute/60*60;
    }
    if(hour > 24)
    {
        hour -= hour/24*24;
    }
    printf("%02d:%02d", hour, minute);
    return 0;
}

Problem N:NowCoder54504 小乐乐排电梯

//#pragma GCC optimize(2)
#include
using namespace std;
int n, ttime=0;
int main()
{
    ios::sync_with_stdio(false);
    scanf("%d", &n);
    while(n >= 12)
    {
        ttime += 4;
        n -= 12;
    }
    printf("%d", ttime+2);
    return 0;
}

Problem O:NowCoder54505 小乐乐与欧几里得

//#pragma GCC optimize(2)
#include
using namespace std;
int n, m;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    int t = __gcd(n, m);
    cout<<t+(long long)m*n/t<<endl;
    return 0;
}

Problem P:NowCoder54506 小乐乐改数字

字符串做法:

//#pragma GCC optimize(2)
#include
using namespace std;
string str;
int main()
{
    ios::sync_with_stdio(false);
    cin>>str;
    for(int i=0; i<str.size(); i++)
        str[i] = (str[i]-'0')%2+'0';
    int flag=15;
    for(int i=0; i<str.size(); i++)
        if(str[i] == '1')
        {
            flag = i;
            break;
        }
    if(flag == 15) cout<<0<<endl;
    else
    {
        for(int i=flag; i<str.size(); i++)
            cout<<str[i];
        cout<<endl;
    }
    return 0;
}

当时的做法:

#include
using namespace std;
int n, i, flag=-1;
int a[11];
int main()
{
    scanf("%d", &n);
    while(n != 0)
    {
        if((n%10)%2) a[++i]=1;
        else a[++i] = 0;
        n /= 10;
    }
    reverse(a+1, a+i+1);
    for(int j=1; j<=i; j++)
        if(a[j] != 0)
        {
            flag = j;
            break;
        }
    if(flag == -1)
        printf("0");
    else
        for(int j=flag; j<=i; j++)
            printf("%d", a[j]);
    return 0;
}

Problem Q:NowCoder54507 小乐乐走台阶

报了一个warning

//#pragma GCC optimize(2)
#include
using namespace std;
int step(int m)
{
    if(m==1 || m==2) return m;
    if(m>=3) return step(m-1)+step(m-2);
}
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    cout<<step(n)<<endl;
    return 0;
}

Problem R:NowCoder54508 小乐乐与序列

方法:直接判断,桶排,sort+unique,set

以下为桶排:

//#pragma GCC optimize(2)
#include
using namespace std;
int a[100010];
int main()
{
    ios::sync_with_stdio(false);
    int n, k, maxn=-1;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>k;
        a[k]++;
        maxn = max(maxn, k);
    }
    for(int i=1; i<=maxn; i++)
        if(a[i]) cout<<i<<" ";
    return 0;
}

以下为set:

//#pragma GCC optimize(2)
#include
using namespace std;
set<int> s;
int main()
{
    ios::sync_with_stdio(false);
    int n, k;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>k;
        s.insert(k);
    }
    for(set<int>::iterator it=s.begin(); it!=s.end(); it++)
        cout<<*it<<" ";
    return 0;
}

Problem S:NowCoder54509 小乐乐与字符串

这题当时要是做出来了哈理工校赛还能再多A一道。

//#pragma GCC optimize(2)
#include
using namespace std;
string str;
int main()
{
    ios::sync_with_stdio(false);
    long long c=0, ch=0, chn=0;
    cin>>str;
    for(int i=0; i<str.size(); i++)
    {
        if(str[i] == 'C')
            c++;
        else if(str[i] == 'H')
            ch += c;
        else if(str[i] == 'N')
            chn += ch;
    }
    cout<<chn<<endl;
    return 0;
}

Problem T:NowCoder54510 小乐乐与二段数

题解链接:https://blog.csdn.net/Q_1849805767/article/details/102980620

//#pragma GCC optimize(2)
#include
using namespace std;
typedef long long ll;
const int maxn = 10010;
int n, a[maxn], b[maxn/10];
bool check(int x, int y, int z, int w)
{
    int L, R;
    if(x > 5) return 1;
    L = z;
    R = w;
    for(int i=0; i<y; i++) L = L*10+z;
    for(int i=0; i<x-y; i++)
    {
        L *= 10;
        if(i > 0)
            R = R*10+w;
    }
    return L+R>n;
}
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n)
    {
        if(!n) return 0;
        cout<<n<<": ";
        if(n == 1)
        {
            cout<<10<<endl;
            continue;
        }
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        a[0] = 1;
        b[0] = 1;
        for(int i=1; i<9999; i++)
            a[i] = (a[i-1]*10+1) % n;
        for(int i=1; i<999; i++)
            b[i] = b[i-1]*10%n;
        int p=0, q=0, r=0, s=0;
        for(int i=1; i<9999; i++)
        {
            //r = 0;
            int m=0;
            if((n%10==0||n%25==0) && i>11)
                m = i-11;
            for(int j=m; j<i; j++)
                for(int k=1; k<10; k++)
                    for(int t=0; t<(n%10?10:1); t++)
                        if(t != k)
                            if(((ll)a[j]*b[i-j]*k+a[i-j-1]*t)%n == 0)
                                if(check(i, j, k, t) && (!r||k<r||k==r&&j>q&&k<s))
                                {
                                    p = i;
                                    q = j;
                                    r = k;
                                    s = t;
                                }
            if(r) break;
        }
        for(int i=0; i<q+1; i++)
            cout<<r;
        for(int i=0; i<p-q; i++)
            cout<<s;
        cout<<endl;
    }
    return 0;
}

你可能感兴趣的:(各种比赛)