2019中山大学程序设计竞赛(重现赛)部分题解 :Triangle,Coding Problem,Clumsy Keke,Enlarge it

这篇博客回顾了2019中山大学程序设计竞赛中的一些题目,包括Enlarge it、Clumsy Keke和Coding Problem。Enlarge it要求扩展矩阵,Clumsy Keke涉及三维体积计算,Coding Problem是关于二进制到十进制的转换。对于Coding Problem,博主提供了AC代码,并分享了避免超时的处理策略。Triangle问题探讨了如何判断给定数组中是否存在能构成三角形的三边,通过排序和斐波那契序列分析得出解决方案。
摘要由CSDN通过智能技术生成

比赛地址

Enlarge it

Sample Input
3 3 2
.*.
.*.
.*.
Sample Output
..**..
..**..
..**..
..**..
..**..
..**..

题意:n,m,k 给出n行m列,要求扩展成n×k行,m*k列。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <deque>
#include <set>
#define MAX 0x3f3f3f3f
#define mod 100
#define fori(a,b) for(ll i=a;i<=b;i++)
#define forj(a,b) for(ll j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e3+10;
char a[M][M];
int main()
{
    int n,m,k;
    while(cin >> n >> m >> k){
        mem(a,0);
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin >> a[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int o=0;o<k;o++){
            for(int j=0;j<m;j++){
                    for(int p=0;p<k;p++)
                        cout << a[i][j] ;

            }
            cout << endl;
            }

        }

    }
    return 0;
}

Clumsy Keke

Sample Input
5 6 4
1 1 1 1 1 1
0 0 0 1 0 1
0 0 0 1 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 1 1 0
1 0 0 1
0 0 0 1
0 0 0 1
0 0 0 1
1 1 1 1
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 1 1 1 1
 

Sample Output
17

 

Hint

题意:给出三个坐标轴,1代表这个方格有,将三个坐标轴拼起来,问这个三维的体积是多少。

思路:如果拼起来相应位置都是1的话,这个三维图形里面一定有,ans++就可以了。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <deque>
#include <set>
#define MAX 0x3f3f3f3f
#define mod 100
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=100;
int xy[M][M],yz[M][M],zx[M][M];
int main()
{
    int x,y,z;
    while(~scanf("%d%d%d",&x,&y,&z)){
        mem(xy,0);
        mem(yz,0);
        mem(zx,0);
        fori(1,x)
            forj(1,y)
                scanf("%d",&xy[i][j]);
        fori(1,y)
            forj(1,z)
                scanf("%d",&yz[i][j]);
        fori(1,z)
            forj(1,x)
                scanf("%d",&zx[i][j]);
        int ans=0;
        for(int i=1;i<=x;i++){
            for(int j=1;j<=y;j++){
                for(int k=1;k<=z;k++){
                    if(xy[i][j]&&yz[j][k]&&zx[k][i])
                        ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Coding Problem

Sample Input
abc
 

Sample Output
33 36 27 6

Hint
s=abc
binary ascii string=10000110 01000110 11000110
answer binary array=100001 100100 011011 000110
final answer array=33 36 27 6
 

题意:给出一个字符串,每个字符串用8位2进制表示(不用余数倒排),6位二进制数一组,求每6位的十进制是多少。

思路:3位字符肯定对应4个数字。挨个处理就好,string比较好用,一定是按照3个字符4个数字输出,不要3个字符3个输出,最后剩下的积攒下来一起输出,亲身试验,会时间超限。

AC代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <deque>
#include <set>
#define MAX 0x3f3f3f3f
#define mod 100
#define fori(a,b) for(ll i=a;i<=b;i++)
#define forj(a,b) for(ll j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e6+10;
string s,ss,s1;
int main()
{

    cin >> s;
    int len = s.size();
    for(int i=0; i<len; i++)
    {
        int a=s[i];
        while(a)
        {
            int t=a%2;
            s1+=t+'0';
            a/=2;
        }
        while(s1.size()<8)//不够位要补0
        {
            s1+='0';
        }
        ss+=s1;
        s1.clear();
        string s2=ss.substr(0,6);
        ss.erase(0,6);
        int m=0,flag=1;
        for(int j=5; j>=0; j--)
        {
            m+=(s2[j]-'0')*flag;
            flag*=2;
        }
        cout <<  m << " ";
        if(i%3==2)
        {
            s2=ss.substr(0,6);
            ss.erase(0,6);
            int m=0,flag=1;
            for(int j=5; j>=0; j--)
            {
                m+=(s2[j]-'0')*flag;
                flag*=2;
            }
            cout <<  m  << " " ;
        }
    }
    return 0;
}

Triangle


Sample Input
4
1 2 3 4
 

Sample Output
YES

题意:给出n个数,问其中有没有3个数使得这三条边可以构成三角形,有就YES,没有就NO。n的范围是5e6,下面n个数不会超过2^31。

思路:本来想着排序一下,这样只要满足两小边之和大于第三边就行了,结果会T,把sort去掉就对了,可能给的是有序序列吧。

AC:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <deque>
#include <set>
#define MAX 0x3f3f3f3f
#define mod 100
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=5e6+5;
int a[M];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
            int flag=0;
            fori(0,n-1){
                scanf("%d",&a[i]);
                
            }
                 //这里本来有一个sort
            ll x=a[0],y=a[1];
            fori(2,n-1){
                if(x+y>a[i]){
                    flag=1;
                    break;
                }
                else {
                    x=y;
                    y=a[i];
                }
            }
            if(flag)
                cout << "YES" <<endl;
            else
                cout << "NO" <<endl;
    }
    return 0;
}

比赛完了交流,发现他们是推的斐波那契,结论是当n大于一定数时,一定会YES,这样取100个数,将这100个数排序暴力就好。

AC代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define eps 0.0000000001
#define mem(a) memset(a,0,sizeof(a))
#define MAX 1e9
#define inf 99999999999999999
#define mod 1000000007
using namespace std;
typedef long long ll;
//priority_queue<int,vector<int>,greater<int> > q;
#define mod 1000000007
const int N=11000000;
int t,q,i,j,flag,dd1,dd2,w[150];
int main()
{
    while(~scanf("%d",&t))
    {
        flag=0;
        if(t>100)
        {
            flag=1;
            for(i=0; i<t; i++)
            {
                scanf("%d",&q);
            }
        }
        else
        {
            flag=0;
            for(i=0; i<t; i++)
            {
                scanf("%d",&w[i]);
            }
        }
        if(t<3)
            flag=0;
        else
        {
            if(!flag)
            {
                sort(w,w+t);
                for(i=0; i<t-2; i++)
                {
                    dd1=w[i+2]-w[i];
                    if(dd1<w[i+1])
                    {
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

以上是比赛做出来的题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值