avatar
fireworks99
keep hungry keep foolish

2019中山大学程序设计竞赛

1002Triangle

给出n个int内的数字,是否有三个数字能作为三角形的三条边

只是n可能到五百万

思维

想一下极限(就是组不成三角形):1, 2, 3, 5, 8, 13, 21……

是一个斐波那契数列,然后陷入僵局……然后云龙说斐波那契数列很容易超int,

试了一下,f[46]就超int了……

队友给力!!!

思路

接受输入后,若n>=50(其实n >= 46就行),直接输出“YES”,否则排序当水题做

Code

#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 0x3f3f3f3f;

int a[5000005];

int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        int cnt = 0;
        while(n--)
            scanf("%d", &a[cnt++]);
        if(cnt >= 50)
        {
            cout << "YES" << '\n';
            continue;
        }
        sort(a, a + cnt);
        bool ans = 0;
        for(int i = 0; i + 2 < cnt; ++i)
            if(a[i] > a[i + 2] - a[i + 1])
            {
                ans = 1;
                break;
            }
        if(ans)
            cout << "YES" << '\n';
        else
            cout << "NO" << '\n';
    }
    return 0;
}

原来用了输入挂,发现while(n--)后应该加一个getchar()才能去读

1005 Coding Problem(水题)

Code

#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 0x3f3f3f3f;

string ten_two(int a)
{
    string s;
    while(a)
    {
        s += (a % 2 + '0');
        a /= 2;
    }
    while(s.length() < 8)
        s += '0';
    return s;
}

int two_ten(string s)
{
    reverse(s.begin(), s.end());
    int sz = s.length();
    int ans = 0;
    for(int i = 0; i < sz; ++i)
        ans += (int)pow(2, i) * (s[i] - '0');
    return ans;
}

int main()
{
    string s, ans;
    cin >> s;
    int sz = s.length();
    for(int i = 0; i < sz; ++i)
        ans += ten_two(int(s[i]));

    sz = ans.length();
    for(int i = 0; i + 5 < sz; i += 6)
        {
            s.clear();
            s += ans[i] ;
            s += ans[i + 1];
            s += ans[i + 2];
            s += ans[i + 3];
            s += ans[i + 4];
            s += ans[i + 5];
            cout << two_ten(s) << ' ';
        }
    return 0;
}

1008 Clumsy Keke

Code

#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

bool vis1[105][105][105];
bool vis2[105][105][105];
bool vis3[105][105][105];

int main()
{
    int a, b, c, t;
    while(~scanf("%d%d%d", &a, &b, &c))
    {
        for(int i = 1; i <= a; ++i)
            for(int j = 1; j <= b; ++j)
                for(int k = 1; k <= c; ++k)
                {
                    vis1[i][j][k] = 0;
                    vis2[i][j][k] = 0;
                    vis3[i][j][k] = 0;
                }
        for(int i = 1; i <= a; ++i)
            for(int j = 1; j <= b; ++j)
            {
                scanf("%d", &t);
                if(t == 1)
                    for(int k = 1; k <= c; ++k)
                        vis1[i][j][k] = 1;
            }
        for(int i = 1; i <= b; ++i)
            for(int j = 1; j <= c; ++j)
            {
                scanf("%d", &t);
                if(t == 1)
                    for(int k = 1; k <= a; ++k)
                        vis2[k][i][j] = 1;
            }
        for(int i = 1; i <= c; ++i)
            for(int j = 1; j <= a; ++j)
            {
                scanf("%d", &t);
                if(t == 1)
                    for(int k = 1; k <= b; ++k)
                        vis3[j][k][i] = 1;
            }
        int ans = 0;
        for(int i = 1; i <= a; ++i)
            for(int j = 1; j <= b; ++j)
                for(int k = 1; k <= c; ++k)
                    if(vis1[i][j][k] && vis2[i][j][k] && vis3[i][j][k])
                        ans++;
        cout <<ans << '\n';
    }
    return 0;
}

1009 Enlarge it(签到题)

#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 0x3f3f3f3f;

string s[105];
int main()
{
    int n, m, k;
    while(~scanf("%d%d%d", &n, &m, &k))
    {
        for(int i = 0; i < n; ++i)
            cin >> s[i];

        for(int i = 0; i < n; ++i)
        {
            for(int q = 0; q < k; ++q)
            {
                for(int j = 0; j < m; ++j)
                {
                    for(int p = 0; p < k; ++p)
                        cout << s[i][j];
                }
                cout << '\n';
            }
        }
    }
    return 0;
}
Site by Baole Zhao | Powered by Hexo | theme PreciousJoy