组队赛第一场

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
AC 代码
   #include <bits/stdc++.h>
using namespace std;

const int manx=5e6+10;
int a[manx];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
        }
        int f=0;
        if(n>=50)
        {
            printf("YES\n");
            f=1;
        }
        if(f==0)
        {
            sort(a+1,a+1+n);
            int flag=0;
            for(int i=1; i<=n-2; i++)
            {
                if(a[i]+a[i+1]>a[i+2]&&a[i+2]-a[i]<a[i+1])
                {
                    flag=1;
                    printf("YES\n");
                    break;

                }
            }
            if(flag==0)
                printf("NO\n");
        }
    }
    return 0;
}
 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

..**..
..**..
..**..
..**..
..**..
..**..
AC 代码
    #include <bits/stdc++.h>
using namespace std;

char a[110][110];
int main()
{
    int n,m,k;
    while(~scanf("%d %d %d",&n,&m,&k))
    {
        getchar();
        for(int i=1; i<=n; i++)
        {
            scanf("%s",a[i]);
            getchar();
        }
        for(int i=1; i<=n; i++)
        {
            for(int l=1; l<=k; l++)
            {
                for(int j=0; j<m; j++)
                {
                    for(int kk=1; kk<=k; kk++)
                    {
                        printf("%c",a[i][j]);
                    }
                }
                printf("\n");
            }
        }
    }
    return 0;
}

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
AC 代码
    #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int xy[100][100],xz[100][100],yz[100][100];
int main()
{
    int x,y,z,i,j,h;
    int sum;
    while(scanf("%d%d%d",&x,&y,&z)!=EOF)
    {
        sum=0;
        for(i=0; i<x; i++)
        {
            for(j=0; j<y; j++)
            {
                scanf("%d",&xy[i][j]);

            }
        }
        for(i=0; i<y; i++)
        {
            for(j=0; j<z; j++)
            {
                scanf("%d",&yz[i][j]);
            }
        }
        for(i=0; i<z; i++)
        {
            for(j=0; j<x; j++)
            {
                scanf("%d",&xz[i][j]);
            }
        }
        for(i=0; i<x; i++)
        {
            for(j=0; j<y; j++)
            {
                for(h=0; h<z; h++)
                {
                    if(xy[i][j]==1&&yz[j][h]==1&&xz[h][i]==1)
                        sum++;
                }
            }
        }
        printf("%d\n",sum);
    }
}
 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 3*n lowercase letter.The binary ascii string of s is a string consist of 8*3*n 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 8*3*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
        
 AC  代码
     #include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
using namespace std;

int main()
{
    string s,ans="";
    vector<int>v;
    cin>>s;
    int len = s.size(),n = len/3;
    for(int i=0; i<s.size(); i++)
    {
        int k = s[i];
        while(k)
        {
            if(k%2==0)
                ans+='0';
            else
                ans+='1';
            k/=2;
        }
        while(ans.size()%8!=0)
        {
            ans+='0';
        }
    }
    while(ans.size()!=n*4*6)
    {
        ans+='0';
    }
    int cnt = 0,p=0;
    for(int i=ans.size()-1; i>=0; i--)
    {
        if(ans[i]=='1')
        {
            p+=(int)pow(2,cnt++);
        }
        else
        {
            cnt++;
        }
        if(cnt==6)
        {
            v.push_back(p);
            cnt = 0;
            p=0;
        }
    }
    for(int i=v.size()-1; i>=0; i--)
    {



            cout<<v[i]<<" ";

    }

    for(int i=v.size(); i<4*n; i++)
    {
        cout<<" "<<0;
    }

    return 0;
}

第一场组队赛,新认识的队友,
ac的都是比较基本的题目,太多的用到数据结构的知识,
最坑的是最后一个,哪一个大的空白就是原来思维定势用标准输出法,最后一个没有空格,结果多次pc,最后去掉空格过,果然自作多情不太行。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
学校要从 n 个人中选出 m 个人组队,这种组合数问题可以使用组合数公式来求解。组合数公式表示为C(n, m),表示从n个元素中选出m个元素的组合数。 组合数公式可以通过递归或动态规划的方式来计算。以下是一个使用递归方式计算组合数的示例代码: ```cpp #include <iostream> using namespace std; int combination(int n, int m) { if (m == 0 || n == m) { return 1; } else { return combination(n - 1, m - 1) + combination(n - 1, m); } } int main() { int n, m; cout << "请输入总人数 n:"; cin >> n; cout << "请输入选取人数 m:"; cin >> m; int result = combination(n, m); cout << "从 " << n << " 个人中选取 " << m << " 个人的组合数为:" << result << endl; return 0; } ``` 在这个示例代码中,`combination()`函数使用递归方式计算组合数。当m等于0或n等于m时,返回1,表示已经选取完毕或没有可选的元素了。否则,根据组合数的性质,将问题拆分为两个子问题:选取第n个元素和不选取第n个元素。递归地计算这两个子问题,并将结果相加。 在主函数中,首先输入总人数n和选取人数m。然后调用`combination()`函数计算组合数,并输出结果。 请注意,递归方式计算组合数的效率较低,当n和m较大时可能会出现栈溢出等问题。为了提高效率,可以使用动态规划等更高效的算法来计算组合数。 希望能够帮助到您!如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

直接AC好吗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值