2019中山大学程序设计竞赛(重现赛)2019/4/20

这场比赛打得很憋屈,快读会TLE,每题都wa了好多发。呜呜

1002 Triangle

After Xiaoteng took a math class, he learned a lot of different shapes, but Xiaoteng’s favorite triangle is because he likes stable shapes, just like his style.
After the Xiaoxun knew it, he wanted to give a triangle as a gift to Xiaoteng. He originally planned to do one, but he was too tired. So he decided to bring some wooden sticks to Xiaoteng and let Xiaoteng make a triangle himself.
One day, Xiaoxun brought n sticks to Xiaoteng. Xiaoteng wanted to try to use three of them to form a triangle, but the number is too much, Xiaoteng stunned, so he can only ask for your help

Input

There are mutiple test cases.
Each case starts with a line containing a integer n(1≤n≤5×106) which represent the number of sticks and this is followed by n positive intergers(smaller than 231−1) separated by spaces.

Output

YES or NO for each case mean Xiaoteng can or can’t use three of sticks to form a triangle.

Sample Input

4
1 2 3 4

Sample Output

YES

题目大意:

有n根火柴,选三根能否构成三角形。(有序)

题目思路:

本人代码比较暴力,直接判断前两个之和是否大于第三个。

#include <iostream>
//#include  <cstring>
#include <algorithm>
//#include <cmath>
#include <stdio.h>
//#include <algorithm>
using namespace std;
//typedef long long ll;
//const int INF=0x3f3f3f3f;
int a[5000005];
int main(){
    int n;
   while(scanf("%d",&n)!=EOF){
     for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
     }
     if(n<3){
        printf("NO\n");
        continue;
     }else{
     //sort(a,a+n);
     int o=0;
     for(int i=2;i<n;i++){
        if(a[i-2]+a[i-1]>a[i]){
            o=1;
            printf("YES\n");
            break;
        }
     }
     if(o==0) {printf("NO\n");continue;}
     else {
        continue;
        }
     }
   }
return 0;
}

大佬思想
如果没有三角形,那么数列是斐波拉契数列级别增长,所以个数<50;

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=5000010;
int a[maxn];
int main(){
    //freopen("input.txt","r",stdin);
    int N;
    while(~scanf("%d",&N)){
        rep(i,1,N) scanf("%d", &a[i]);
        bool F=0;
        if(N<100){
           sort(a+1,a+N+1);
           rep(i,1,N-2){
               if(a[i]+a[i+1]>a[i+2]){ F=1; break; }
           }
        }
        else F=true;
        puts(F?"YES":"NO");
    }
    return 0;
}

1009 Enlarge it

Taotao is glad to see that lots of students have registered for today’s algorithm competition. Thus he wants to pull a banner on the wall. But Taotao is so stupid that he doesn’t even know how to enlarge words to fit the size of banner. So Taotao gives you a slogan template and asked you to enlarge them in k times.

Input

There are multiple test cases.
For each test case, first line contains three numbers n, m, k (1<=n, m<=100,1<=k<=10).
The next n lines each contain m visible characters.

Output

For each test case, you should output kn lines each contain km visible characters to represent the expanded slogan.

Sample Input

3 3 2
.*.
.*.
.*.

Sample Output

…**…
…**…
…**…
…**…
…**…
…**…

水题

#include <iostream>
#include  <cstring>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;

int main(){
    //int T;
    //scanf("%d",&T);
    //while(T--){
    char a[105][105];
    int n,m,k;
   while(scanf("%d %d %d",&n,&m,&k)!=EOF){
   for(int i=0;i<n;i++){
    scanf("%s",a[i]);
   }
   string str[105];
    for(int i=0;i<n;i++){
        for(int t=0;t<m;t++){
            for(int j=t*k;j<t*k+k;j++){
                 str[i]+=a[i][t];
            }
        }
    }
    int ans=0;
    for(int j=0;j<n;){
    ans++;
    cout<<str[j]<<endl;
    if(ans==k){j++;ans=0;}
    }
   }
   //}
return 0;
}

1005 Coding Problem

Here is the logic.I am the brother of mata Chuang.Mata chuang is the brother of cxk.So what am I?Am I the grand-brother of cxk?Or am I in a position that same brother level of cxk?Or cxk is the grand-brother of me?
Fine,it doesn’t matter to the problem.Problem can’t be a problem until it has description.But description are just words.Meaningless words.So,we treat words miserably like this, given a string s consist of 3n lowercase letter.The binary ascii string of s is a string consist of 83n 0-1 string(one char,8bits,The lower significnt bit is in the front, the higher is in the back.). We want you output the binary ascii string.But we don’t want the string too long.So we want you put every 6 bit together(The higher significnt bit is in the front, the lower is in the back.) and output the corresponding array,with a length of 83*n/6.Please check the sample for specific.

Input

one line,one string. (n<=1e5)

Output

one line,4*n integer representing the target array.

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

题目大意:

把输入的字符串的ACSII表的数的二进制反向取八位,然后排在一起,每六个为一个数输出。

思路:

先将字符的二进制打表出来,然后直接模拟就好啦。

#include <iostream>
#include  <cstring>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
string a;
int p,q,r,t;
int ans[205][10];

void daozhuan(int i){
    int u=0;
    int y=i;
    while(y){
        if(u>7) break;
        if(y&1) ans[i][u]=1;
        else ans[i][u]=0;
         y>>=1;
         u++;
    }
}

void solve(int n){
    n=n*3;
    int d=a[n];
    int b=a[n+1];
    int c=a[n+2];
    printf("%d ",ans[d][5]+ans[d][4]*2+ans[d][3]*4+ans[d][2]*8+ans[d][1]*16+ans[d][0]*32);
    printf("%d ",ans[b][3]+ans[b][2]*2+ans[b][1]*4+ans[b][0]*8+ans[d][7]*16+ans[d][6]*32);
    printf("%d ",ans[c][1]+ans[c][0]*2+ans[b][7]*4+ans[b][6]*8+ans[b][5]*16+ans[b][4]*32);
    printf("%d ",ans[c][7]+ans[c][6]*2+ans[c][5]*4+ans[c][4]*8+ans[c][3]*16+ans[c][2]*32);
}

int main(){
   memset(ans,0,sizeof(ans));
   cin>>a;
   for(int i=90;i<140;i++){
    daozhuan(i);
   }
   for(int i=0;i<a.size()/3;i++){
     solve(i);
   }
return 0;
}

1008 Clumsy Keke

Keke is currently studying engineering drawing courses, and the teacher has taught her how to find its volume through the three views of the part. But her brain doesn’t work well that she can’t find the volume of complex parts. So she needs your help.
To simplify the problem, the part is made up of cubes with side length 1, and the vertices of these cubes are all on the grid. Give you three 0/1 matrices, each representing each of the three views. 0 means that there is no projection of cubes at this position of the view; 1 means that there is a projection of cubes at this position of the view.
Now Keke wants you to help her find the volume of the part determined by the three views.

Input

There are mutiple test cases, the number of which is no more than 10. For each test case:
The first line of input contains three integers mx,my,mz(1≤mx,my,mz≤99) , which represent the coordinate range of all possible cubes (i.e. all possible cubes are in the cuboid area whose body diagonal is from (1,1,1) to (mx,my,mz)).
Following input a 0/1 matrix with mx lines and my columns representing the front view, and the y-th column of the x-th row represents the projection of all the cubes in the front view such as (x,y,?).
Following input a 0/1 matrix with my lines and mz columns representing the side view, and the z-th column of the y-th row represents the projections of all the cubes in the side view such as (?,y,z).
Following input a 0/1 matrix with mz lines and mx columns representing the top view, and the x-th column of the z-th row represents the projection of all the cubes of the top view such as (x,?,z).
The ‘?’ in the above coordinates represents any integer. Numbers in the same line are separated by spaces. For more detailed input information, please see the sample.

Output

For each test case:
The first line of output should contain an integer, representing the volume of the part determined by the three views. If the determined part is not unique, find the largest of all possible parts.
Keke’s teacher promises that there is at least one part that satisfies the input.

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
在这里插入图片描述

题目大意:

给你物体的正视图,侧视图,俯视图,问你这个最多由几块方块构成。

题目思路;

开个三位数组,先全部填一,如果输入的为0,则整行或者整列或者整竖都变成0,最后计算剩下的1即可。

#include<bits/stdc++.h>
using namespace std;
const int maxn=20000010;
int a[105][105][105],b,x,y,z,X,Y,Z,ans;
int main(){
    while(scanf("%d%d%d",&X,&Y,&Z)!=EOF){
        for(x=1;x<=X;x++)
        for(y=1;y<=Y;y++)
        for(z=1;z<=Z;z++)
        a[x][y][z]=1;
        for(x=1;x<=X;x++)
            for(y=1;y<=Y;y++){
            scanf("%d",&b);
            if(!b)
            for(z=1;z<=Z;z++)
            a[x][y][z]=0;
        }
        for(y=1;y<=Y;y++)for(z=1;z<=Z;z++){
            scanf("%d",&b);
            if(!b)
            for(x=1;x<=X;x++)
            a[x][y][z]=0;
        }
        for(z=1;z<=Z;z++)
        for(x=1;x<=X;x++){
            scanf("%d",&b);
            if(!b)
            for(y=1;y<=Y;y++)
            a[x][y][z]=0;
        }
        ans=0;
        for(x=1;x<=X;x++)
        for(y=1;y<=Y;y++)
        for(z=1;z<=Z;z++)
        ans+=a[x][y][z];
        printf("%d\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43333395/article/details/89410291
今日推荐