B-Beauty Values

题目描述

Gromah and LZR have entered the second level. There is a sequence a1,a2,⋯ ,ana_1, a_2, \cdots, a_na1​,a2​,⋯,an​ on the wall.           There is also a note board saying "the beauty value of a sequence is the number of different elements in the sequence".            LZR soon comes up with the password of this level, which is the sum of the beauty values of all successive subintervals of the sequence on the wall.          Please help them determine the password!      
输入描述:
The first line contains one positive integer nn_{}n​, denoting the length of the sequence.The second line contains nn_{}n​ positive integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_na1​,a2​,⋯,an​, denoting the sequence.1≤ai≤n≤1051 \le a_i \le n \le 10^51≤ai​≤n≤105
输出描述:
Print a non-negative integer in a single line, denoting the answer.

示例1

输入
复制

4
1 2 1 3

输出
复制

18

说明

The beauty values of subintervals [1,1],[2,2],[3,3],[4,4][1,1], [2,2], [3,3], [4,4]_{}[1,1],[2,2],[3,3],[4,4]​ are all 11_{}1​.The beauty values of subintervals [1,2],[1,3],[2,3],[3,4][1,2], [1,3], [2,3], [3,4]_{}[1,2],[1,3],[2,3],[3,4]​ are all 22_{}2​.The beauty values of subintervals [1,4],[2,4][1,4], [2,4]_{}[1,4],[2,4]​ are all 33_{}3​.As a result, the sum of all beauty values are 1×4+2×4+3×2=181\times 4 + 2\times 4 + 3\times 2 = 181×4+2×4+3×2=18.

题意:给定一个序列,求所有子序列中不同元素个数的总和

遍历每个数,当去掉这个数时减去的是该数距它下一个出现的位置差。输入时储存一下后继就行

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+20;
int nex[N],a[N];
long long sum[N];
int main()
{int n;while(scanf("%d",&n)!=EOF){map<int,int>mp;set<int>st;memset(nex,0,sizeof(nex));memset(sum,0,sizeof(sum));for(int i=1;i<=n;i++){scanf("%d",&a[i]);st.insert(a[i]);sum[1]+=st.size();if(mp[a[i]]==0)mp[a[i]]=i;else{nex[mp[a[i]]]=i;mp[a[i]]=i;}}
//        for(int i=1;i<=n;i++)
//            cout<<nex[i]<<' ';
//        cout<<'\n';
//        cout<<sum[1]<<'\n';long long ans=sum[1];for(int i=2;i<=n;i++){if(nex[i-1]!=0)sum[i]=sum[i-1]-(nex[i-1]-i+1);elsesum[i]=sum[i-1]-(n-i+2);ans+=sum[i];}
//        for(int i=1;i<=n;i++)
//            cout<<sum[i]<<' ';
//        cout<<'\n';cout<<ans<<'\n';}return 0;
}
/*
8
1 2 4 1 3 4 3 5
*/

C-CDMA

题目描述

Gromah and LZR have entered the third level. There is a blank grid of size m×mm\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 00_{}0​ in the sequence as −1-1_{}−1​, and regard 11_{}1​ as +1+1_{}+1​, then these sequences should satisfy that for any two different sequences s,ts,t_{}s,t​, the inner product of s,ts,t_{}s,t​ should be exactly 00_{}0​.

The inner product of two sequences s,ts,t_{}s,t​ with the same length nn_{}n​ equals to ∑i=1nsiti\sum_{i=1}^{n} s_it_i∑i=1n​si​ti​.

So, the key to the next level is to construct a grid of size m×mm\times mm×m, whose elements are all −1-1_{}−1​ or 11_{}1​, and for any two different rows, the inner product of them should be exactly 00_{}0​.

In this problem, it is guaranteed that mm_{}m​ is a positive integer power of 22_{}2​ and there exists some solutions for input mm_{}m​. If there are multiple solutions, you may print any of them.

输入描述:

 

Only one positive integer mm_{}m​ in one line.

m∈{2k  ∣  k=1,2,⋯ ,10}m \in \{2^k \; | \;k = 1, 2, \cdots, 10\}m∈{2k∣k=1,2,⋯,10}

输出描述:

Print mm_{}m​ lines, each contains a sequence with length mm_{}m​, whose elements should be all −1-1_{}−1​ or 11_{}1​ satisfying that for any two different rows, the inner product of them equals 00_{}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.

示例1

输入

复制

2

输出

复制

1 1
1 -1

说明

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

题意:任意输出一个m*m的矩阵,满足任意两行相同元素乘积之和为0

wotaicailebaqwqwq

找到一个满足题意的2阶矩阵,之后的多阶肯定与2阶的有关

1 1

1 -1

四阶的话把二阶套到里面的1里,-1的地方取反qwq  以此类推。

#include<bits/stdc++.h>
using namespace std;
int mp[2050][2050];
int main()
{int n;mp[1][1]=1;mp[1][2]=1;mp[2][1]=1;mp[2][2]=-1;for(int k=2; k<=1024; k*=2){
//        cout<<k<<endl;for(int i=1; i<=k; i++){for(int j=1; j<=k; j++){mp[i+k][j]=mp[i][j];}for(int j=1; j<=k; j++){mp[i][j+k]=mp[i][j];}for(int j=1; j<=k; j++){mp[i+k][j+k]=-mp[i][j];}}}while(scanf("%d",&n)!=EOF){for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){cout<<mp[i][j];if(j!=n){cout<<' ';}}cout<<'\n';}
//        cout<<"YES"<<endl;}
}

G-Gemstones

题目描述

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 "ATCCCTTG", we can take three 'C's away with two parts "AT", "TTG" left, then the two parts will be merged to "ATTTG", and we can take three 'T's 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 ss_{}s​, denoting the gemstone sequence, where the same letters are regarded as the same types.

1≤∣s∣≤1051 \le |s| \le 10^51≤∣s∣≤105

ss_{}s​ only contains uppercase letters.

输出描述:

Print a non-negative integer in a single line, denoting the maximum times.

示例1

输入

复制

ATCCCTTG

输出

复制

2

说明

One possible way is that ‘‘ATCCCTTG "  →  ‘‘ATTTG "  →‘‘AG "``ATCCCTTG\,"  \; \rightarrow \; ``ATTTG\," \; \rightarrow ``AG\,"‘‘ATCCCTTG"→‘‘ATTTG"→‘‘AG".

题意:3个相同的字母可以消掉,问可以消多少次

温暖的单调栈裸题

#include <bits/stdc++.h>
using namespace std;
int main()
{string s;while(cin>>s){int len=s.size();if(len<3)cout<<0<<'\n';else{stack<char>st;int ans=0;st.push(s[0]);st.push(s[1]);for(int i=2; i<len; i++){if(st.size()>=2){char c=st.top();if(c==s[i]){st.pop();if(st.top()==s[i]){st.pop();ans++;}else{st.push(c);st.push(s[i]);}}elsest.push(s[i]);}elsest.push(s[i]);}cout<<ans<<'\n';}}return 0;
}///ABBBAATCHCCCHHCCTT

2019牛客ACM暑期多校第八场相关推荐

  1. 2019牛客网暑期多校赛第七场C题Governing sand --思维+前缀和

    链接:https://ac.nowcoder.com/acm/contest/887/C 来源:牛客网 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 65536K,其他语言13107 ...

  2. 2019牛客网暑假多校训练第四场 K —number

    链接:https://ac.nowcoder.com/acm/contest/884/K 来源:牛客网 题目描述 300iq loves numbers who are multiple of 300 ...

  3. 2019牛客暑期多校第八场 Flower Dance

    题意 给一些点,找4个点,要求1个点在剩余三个点围成的三角形的内部,问方案数 题解 写得我有种不想碰几何的冲动.... 太迷了,精度迷,同一种意思的不同表达迷,明明那么简洁的思路,为什么写出来这么多特 ...

  4. 2019牛客暑期多校训练营(第四场)----E- triples II

    首先发出题目链接: 链接:https://ac.nowcoder.com/acm/contest/884/E 来源:牛客网 涉及:位运算,容斥定义,dp 点击这里回到2019牛客暑期多校训练营解题-目 ...

  5. 2019牛客暑期多校训练营(第五场)C generator 2 (BSGS)

    2019牛客暑期多校训练营(第五场)C generator 2 思路 x0=x0x_0 = x_0x0​=x0​ x1=a∗x0∗bx_1 = a * x_0 * bx1​=a∗x0​∗b x2=a∗ ...

  6. 牛客网暑期ACM多校训练营(第十场)F.Rikka with Line Graph

    牛客网暑期ACM多校训练营(第十场)F.Rikka with Line Graph 做法:\(G'\) 中的对应原图两条边(a,b) (c,d)的最短路为: \[ w[a][b] + w[c][d] ...

  7. 牛客网暑期ACM多校训练营(第九场)

    牛客网暑期ACM多校训练营(第九场) A. Circulant Matrix 做法:看到下标 \(xor\) 这种情况就想 \(FWT\),可是半天没思路,于是放弃了..其实这个 \(n\) 疯狂暗示 ...

  8. 牛客网暑期ACM多校训练营(第五场)

    牛客网暑期ACM多校训练营(第五场) A. gpa 二分答案,然后就转化为是否满足 \(\frac {\sum s[i]c[i]}{\sum s[i]} ≥ D\), \(\sum s[i]c[i] ...

  9. 牛客网暑期ACM多校训练营(第三场)

    牛客网暑期ACM多校训练营(第三场) A. PACM Team 01背包,输出方案,用bool存每种状态下用的哪一个物品,卡内存.官方题解上,说用char或者short就行了.还有一种做法是把用的物品 ...

  10. 牛客网暑期ACM多校训练营(第一场)

    牛客网暑期ACM多校训练营(第一场) A. Monotonic Matrix 考虑0和1的分界线,1和2的分界线,发现问题可以转化为两条不互相穿过的路径的方案数(可重叠),题解的做法就是把一条路径斜着 ...

最新文章

  1. 微软推出Windows XP/Server 2003紧急安全补丁:修复远程桌面CVE-2019-0708漏洞
  2. nginx代理响应报文体不全解决思路
  3. 一文看尽CVPR 2019十大新研究:“不看也知”成热点,无人车新增重磅开源数据集...
  4. linux笔记第一章--基本命令记载
  5. ALV复制内容到剪贴板
  6. python 基本数据类型常用方法总结
  7. 嵌入式智能国际大会图文直播:探索人工智能的前世今生
  8. jsp usebean_JSP动作标签– jsp useBean,包含,转发
  9. Linux Kernel中irq handler, softirq handler 和 tasklet
  10. 政务信息系统整合共享实施方案
  11. Android 融云SDK-即时通讯IM(附源码)
  12. 免积分下载与PDF转换
  13. 计算机输入法切换用户登录,电脑切换不出来输入法,教您解决切换输入法的问题...
  14. 八大远程控制软件排行,Teamviewer替代软件
  15. Tampermonkey油猴插件
  16. 今日金融词汇---股价复权,是什么?
  17. K700C通过电脑共享宽带上网!
  18. 阿正入门深度学习---从EM算法开始
  19. python经纬度批量定位 绘制高清地图
  20. Excel在行上输入连续序号的3种方法的操作比较

热门文章

  1. 瀚高数据库安全配置要求
  2. 用java写新年快乐特效代码_蓝叶分享新年快乐大红灯笼特效代码
  3. 如何查看征信报告上的不良信息?
  4. OSChina 周六乱弹 ——你打算怎么和老妈解释
  5. 不得不会的linux账号与权限管理
  6. UBT18:ubuntu安装阿里云盘
  7. 爱恨情仇——Kobe悖论终结篇
  8. xz (压缩文件格式)
  9. 猜单词游戏。计算机随机产生一个单词,打乱字母顺序,供玩家去猜 a.准备一组单词,随机抽取一个b.将抽取的单词作为答案,打乱字母顺序,显示给玩家,供其猜测c.猜测错误继续猜测或以空字符串.
  10. win10系统事件查看器如何打开 Win10事件查看器怎么使用