哈爾濱理工大學軟件與微電子學院程序設計競賽(新生賽) -補檔

time:2019.11.08
題目較多,所以使用目錄。

文章目錄

Problem A:NowCoder54536 小樂樂學編程

實踐出真知!

//#pragma GCC optimize(2)
#include<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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<bits/stdc++.h>
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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章