2019牛客暑期多校训练营(第八场)

2019牛客暑期多校训练营 第八场

C.CDMA

链接:https://ac.nowcoder.com/acm/contest/888/C
来源:牛客网

Gromah and LZR have entered the third level. There is a blank grid of size m\times mm×m, and above the grid is a word “CDMA”.

In CDMA Technology, a Technology about computer network, every network node should be appointed a unique binary sequence with a fixed and the same length. Moreover, if we regard 0 0 0 in the sequence as − 1 -1 1 , and regard 1 1 1 as + 1 +1 +1 , then these sequences should satisfy that for any two different sequences s , t s,t s,t , the inner product of s , t s,t s,t should be exactly 0 0 0.
The inner product of two sequences s , t s,t s,t with the same length n n n equals to ∑ i = 1 n s i t i \sum_{i=1}^{n} s_it_i i=1nsiti.
So, the key to the next level is to construct a grid of size m\times mm×m, whose elements are all − 1 −1 1 or 1 1 1 , and for any two different rows, the inner product of them should be exactly 0 0 0.
In this problem, it is guaranteed that m m m is a positive integer power of 2 2 2 and there exists some solutions for input m m m . If there are multiple solutions, you may print any of them.

输入描述:

Only one positive integer m m m in one line. m ∈ { 2 k ∣ k = 1 , 2 , ⋯ , 10 } m∈\{2^k∣k=1,2,⋯,10\} m{2kk=1,2,,10}
输出描述:
Print m m m lines, each contains a sequence with length m m m, whose elements should be all − 1 −1 1 or 1 1 1 satisfying that for any two different rows, the inner product of them equals 0 0 0.
You may print multiple blank spaces between two numbers or at the end of each line, and you may print any number of blank characters at the end of whole output file.
输入
2
输出
1 1
1 -1

说明

The inner product of the two rows is 1 × ( − 1 ) + 1 × 1 = 0 1\times(-1) + 1\times 1 = 0 1×(1)+1×1=0.

解析

膜拜丁佬%oz

1 1
1 -1

所以可能右下角应该是和左上角是相反的.
然后把这个 2 × 2 2\times2 2×2矩阵当作一个数.
那么 4 × 4 4\times4 4×4的就是

1 1 1 1
1 -1 1 -1
1 1 -1 -1
1 -1 -1 1

然后…以此类推,发现规律成立了
1

#include <cstdio>
#include <cstring>
#include<iostream>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cmath>
typedef long long ll;
using namespace std;
int mp[11][2100][2100];
 
int main()
{
    mp[0][0][0]=1;mp[0][0][1]=1;
    mp[0][1][0]=1;mp[0][1][1]=-1;
    int cnt=2;
    for(int i=1;i<=10;i++){
        for(int j=0;j<cnt;j++)
            for(int k=0;k<cnt*2;k++)
                mp[i][j][k]=mp[i-1][j][k%cnt];
        
        for(int j=cnt;j<cnt*2;j++)
            for(int k=0;k<cnt*2;k++)
                if(k>=cnt)
                    mp[i][j][k]=-mp[i-1][j%cnt][k%cnt];
                else
                    mp[i][j][k]=mp[i-1][j%cnt][k%cnt];
        
        cnt*=2;
    }
    int n;
    cin>>n;
    cnt=log2(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            printf("%d ",mp[cnt][i][j]);
        cout<<endl;
    }
}

G.Gemstones

链接:https://ac.nowcoder.com/acm/contest/888/G
来源:牛客网

题目描述

Gromah and LZR have entered the seventh level. There are a sequence of gemstones on the wall.
After some tries, Gromah discovers that one can take exactly three successive gemstones with the same types away from the gemstone sequence each time, after taking away three gemstones, the left two parts of origin sequence will be merged to one sequence in origin order automatically.
For example, as for " A T C C C T T G " "ATCCCTTG" "ATCCCTTG", we can take three ′ C ′ 'C' Cs away with two parts " A T " "AT" "AT", " T T G " "TTG" "TTG" left, then the two parts will be merged to " A T T T G " "ATTTG" "ATTTG", and we can take three ′ T ′ 'T' Ts next time.

The password of this level is the maximum possible times to take gemstones from origin sequence.

Please help them to determine the maximum times.
输入描述:
Only one line containing a string s s s
, denoting the gemstone sequence, where the same letters are regarded as the same types.
1 ≤ ∣ s ∣ ≤ 1 0 5 1≤∣s∣≤10^5 1s105
s s s only contains uppercase letters.
输出描述:
Print a non-negative integer in a single line, denoting the maximum times.
输入
A T C C C T T G ATCCCTTG ATCCCTTG
输出
2

说明

One possible way is that " A T C C C T T G " → ‘ ‘ A T T T G " → ‘ ‘ A G " "ATCCCTTG"→‘‘ATTTG"→‘‘AG" "ATCCCTTG"ATTTG"AG".

解析

用两个栈,分别存字符和栈内连续字符个数.
当放入一个字符时,判断是否与栈顶相同,相同便将栈顶字符的个数 + 1 +1 +1,不同就压入栈,同时第二个栈顶压入 1 1 1.

#include <bits/stdc++.h>
using namespace std;
 
const int MAXN=1e5+10;
char q[MAXN];
int a[MAXN];
char s[MAXN];
int main()
{
    cin>>s;
    int len=strlen(s),tail=1,ans=0;
    q[tail]=s[0];
    a[tail]++;
    for(int i=1;i<len;i++){
        if(s[i]==q[tail]){
            a[tail]++;
            if(a[tail]==3){
                a[tail]=0;
                tail--;
                ans++;
            }
        }
        else{
            tail++;
            q[tail]=s[i];
            a[tail]++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值