提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 目录

    A. Password

    B. Permutation Val

    C. Save the Magazines

    D. Problem with Random Tests

    总结


  • 总结

A. Password

题目:

Monocarp has forgotten the password to his mobile phone. The password consists of 44 digits from 00 to 99 (note that it can start with the digit 0).

Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp also remembers some digits which were definitely not used in the password.

You have to calculate the number of different sequences of 4 digits that could be the password for Monocarp's mobile phone (i. e. these sequences should meet all constraints on Monocarp's password).

Input

The first line contains a single integer tt (1≤t≤2001≤t≤200) — the number of testcases.

The first line of each testcase contains a single integer nn (1≤n≤81≤n≤8) — the number of digits for which Monocarp remembers that they were not used in the password.

The second line contains nn different integers a1,a2,…ana1,a2,…an (0≤ai≤90≤ai≤9) representing the digits that were not used in the password. Note that the digits a1,a2,…,ana1,a2,…,an are given in ascending order.

Output

For each testcase, print one integer — the number of different 44-digit sequences that meet the constraints.

Example

2

8

0 1 2 4 5 6 8 9

1

8

output

6
216

Note

In the first example, all possible passwords are: "3377", "3737", "3773", "7337", "7373", "7733".

题解:

这题的题意是在0~9十个数字中减去n个数字之后剩余的数字俩俩组合排列的个数,俩个数的排列方式如第一个案例是6种,设x = 10 - n 则结果为(x*(x-1))/2*6.

代码

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<string.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 20;
int a[N],b[N];
char c[N];
//string s1[N],s2[N],s3[N];
int main(void)
{int t;cin >> t;while(t--){int n;cin >> n;for(int i=1;i<=n;i++){cin >> a[i]; }int x = 10-n;cout << x*(x-1)*3 << endl;}return 0;} 

B. Permutation Val

题目:

B. Permutation Value

time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

You are given an integer nn. You have to construct a permutation of size nn.

A permutation is an array where each integer from 1 to ss (where ss is the size of permutation) occurs exactly once. For example, [2,1,4,3][2,1,4,3] is a permutation of size 4; [1,2,4,5,3][1,2,4,5,3] is a permutation of size 55; [1,4,3][1,4,3] is not a permutation (the integer 22 is absent), [2,1,3,1][2,1,3,1] is not a permutation (the integer 11 appears twice).

A subsegment of a permutation is a contiguous subsequence of that permutation. For example, the permutation [2,1,4,3][2,1,4,3] has 1010 subsegments: [2][2], [2,1][2,1], [2,1,4][2,1,4], [2,1,4,3][2,1,4,3], [1][1], [1,4][1,4], [1,4,3][1,4,3], [4][4], [4,3][4,3] and [3][3].

The value of the permutation is the number of its subsegments which are also permutations. For example, the value of [2,1,4,3][2,1,4,3] is 33 since the subsegments [2,1][2,1], [1][1] and [2,1,4,3][2,1,4,3] are permutations.

You have to construct a permutation of size nn with minimum possible value among all permutations of size nn.

Input

The first line contains one integer tt (1≤t≤481≤t≤48) — the number of test cases.

Then, tt lines follow. The ii-th of them contains one integer nn (3≤n≤503≤n≤50) representing the ii-th test case.

Output

For each test case, print nn integers — the permutation of size nn with minimum possible value. If there are multiple such permutations, print any of them.

Example

input

2

5

6

output

1 4 3 5 2
4 1 6 2 5 3

Note

In the first example, the permutation [1,4,3,5,2]is one of the possible answers; its value is 2.

In the second example, the permutation [4,1,6,2,5,3] is one of the possible answers; its value is 2.

题解:

意思是找出最少的子序列满足题意给的序列,也就是在长度n的数组中,数字1~n都要出现一次,假设满足这种条件的数组为I数组。所以当给出一个长度n时,我们需要构造一个数组,使它的子序列满足I数组的个数最少,如第一个样例中的n = 5,我们可以构造数组1 5 4 3 2,所以它的子序列满足I数组的为[1],[1,5,4,3,2]这俩个,也就是说,我们只需要构造将1后面的数字倒过来,就一定能使让它的子序列为2个,一个是[1],一个是我们构造的原数组,其他数组是不满足的,因为我们把它们倒过来了,[1,5]不符合,[1,5,4]不符合...其他全部都不符合,所以只要构造一个数组,第一个元素为1,然后从i = n开始,倒序输出即可

代码:

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<string.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 20;
int a[N],b[N];
char c[N];
//string s1[N],s2[N],s3[N];
int main(void)
{int t;cin >> t;while(t--){int n;cin >> n;cout << 1 << " ";for(int i=n;i>=2;i--){cout << i << " ";}cout << endl;}return 0;} 

C. Save the Magazines

题目:

C. Save the Magazines

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Monocarp has been collecting rare magazines for quite a while, and now he has decided to sell them. He distributed the magazines between nn boxes, arranged in a row. The ii-th box contains aiai magazines. Some of the boxes are covered with lids, others are not.

Suddenly it started to rain, and now Monocarp has to save as many magazines from the rain as possible. To do this, he can move the lids between boxes as follows: if the ii-th box was covered with a lid initially, he can either move the lid from the ii-th box to the box (i−1)(i−1) (if it exists), or keep the lid on the ii-th box. You may assume that Monocarp can move the lids instantly at the same moment, and no lid can be moved more than once. If a box will be covered with a lid after Monocarp moves the lids, the magazines in it will be safe from the rain; otherwise they will soak.

You have to calculate the maximum number of magazines Monocarp can save from the rain.

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of the testcases.

The first line of each testcase contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of boxes.

The second line contains a string of nn characters 0 and/or 1. If the ii-th character is 1, the ii-th box is initially covered with a lid. If the ii-th character is 0, the ii-th box is initially not covered.

The third line contains a sequence of integers a1,a2,…,ana1,a2,…,an (1≤ai≤1041≤ai≤104), where aiai is the number of magazines in the ii-th box.

The sum of nn over all testcases doesn't exceed 2⋅1052⋅105.

Output

For each testcase, print one integer — the maximum number of magazines Monocarp can save from the rain.

Example

input

4

5

01110

10 5 8 9 6

6

011011

20 10 9 30 20 19

4

0000

100 100 100 100

4

0111

5 4 5 1

output

27
80
0
14

Note

In the first testcase of the example, Monocarp can move the lid from the second box to the first box, so the boxes 1, 3 and 4 are covered, and 10+8+9=27magazines are saved.

In the second testcase, Monocarp can move the lid from the second box to the first box, then from the third box to the second box, then from the fifth box to the fourth box, and then from the sixth box to the fifth box. The boxes 1, 2, 4 and 5 will be covered, so 20+10+30+20=80 magazines can be saved.

There are no lids in the third testcase, so it's impossible to save even a single magazine.

题解:

题意是有n个装满ai本书的箱子,有些盒子有盖子,有些盒子没盖子,有盖子的盒子,可以选择不动,也可以选择移动然后盖住面前的一个箱子(i-1),找到能盖住最多书的方法,并输出盖住最多的书。一个含'0'或'1'的字符串s表示箱子的状态,1表示当前有盖子,0表示没盖子,我们可以先找到第一个'1',也就是有盖子的下标i,定义一个index存放有盖子前面第一个没有盖子的箱子的下标,也就是可以进行交换盖子的下标,如果我们在循环中s[i]等于'0'时,就让index = i,当s[i] = '1'时,

如果a[index] >=a[i],那么我们就可以选择交换盖子,即是让ans += a[index],交换后第i个位置就没有盖子了变为'0'了,即index = i;

如果a[i]>a[index]我们就不交换,index也不用变,直接让 ans+= a[i]即可,以此类推,最后输出ans即可

代码:

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<string.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 2e5+10;
int a[N],b[N];
char c[N];
//string s1[N],s2[N],s3[N];
int main(void)
{int t;cin >> t;while(t--){int n;ll ans = 0;cin >> n;string s;cin >> s;s = "/"+s;int res=0;for(int i=1;i<=n;i++){cin >> a[i];}int res1=0;int index=1; //如果第一个位置为1时,因为前面没有箱子,此时就不能交换,让index = 0.if(s[1]=='1'){ans+=a[1];index=0;}for(int i=2;i<=n;i++){if(s[i]=='0')index = i;if(s[i] == '1'){if(index==0){ans+=a[i];continue;}ans+=max(a[i],a[index]);if(a[index]>=a[i]){index = i;}}}cout << ans << endl;}return 0;} 

D. Problem with Random Tests

题目:

D. Problem with Random Tests

time limit per test

4 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

You are given a string ss consisting of nn characters. Each character of ss is either 0 or 1.

A substring of ss is a contiguous subsequence of its characters.

You have to choose two substrings of ss (possibly intersecting, possibly the same, possibly non-intersecting — just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:

  • let s1s1 be the first substring, s2s2 be the second chosen substring, and f(si)f(si) be the integer such that sisi is its binary representation (for example, if sisi is 11010, f(si)=26f(si)=26);
  • the value is the bitwise OR of f(s1)f(s1) and f(s2)f(s2).

Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.

Input

The first line contains one integer nn — the number of characters in ss.

The second line contains ss itself, consisting of exactly nn characters 0 and/or 1.

All non-example tests in this problem are generated randomly: every character of ss is chosen independently of other characters; for each character, the probability of it being 1 is exactly 1212.

This problem has exactly 4040 tests. Tests from 11 to 33 are the examples; tests from 44 to 4040 are generated randomly. In tests from 44 to 1010, n=5n=5; in tests from 1111 to 2020, n=1000n=1000; in tests from 2121 to 4040, n=106n=106.

Hacks are forbidden in this problem.

Output

Print the maximum possible value you can get in binary representation without leading zeroes.

Examples

input

5
11010

output

11111

input

7
1110010

output

1111110

input

4
0000

output

0

Note

In the first example, you can choose the substrings 11010 and 101. f(s1)=26f(s1)=26, f(s2)=5f(s2)=5, their bitwise OR is 3131, and the binary representation of 3131 is 11111.

In the second example, you can choose the substrings 1110010 and 11100.

题解:     

第一步:这题首先先找到字符串s中第一个1出现的下标,如果前面有0,则去掉前面的0,因为前面的0在最后结果是没用的,得到字串ans;如01000,将s变为1000即可

第二步然后找到ans中第一个0的位置,因为第一个0的位置根据题意是一定能变成1的,因为这个0前面有1,比如10010,我们只需要截取1001即可使第四个0变为1,所以可以证明,第一个0前面的所有1,都能使这个0变为1,只需要截取len = s.length-index+1个子串即可,如1001的长度等于5-2+1,所以我们将所有这个0前面的1开头所截取的长度为len的字串与s根据题目的意思“或”运算,找到最大的那个s3输出它即可

代码:

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<string.h>
#include<map>
typedef long long ll;
using namespace std;
const int N = 1e6+10;
int a[N],b[N];
char c[N];
//string s1[N],s2[N],s3[N];
int main(void)
{int t;cin >> t;string s;cin >> s;s = "/"+s;string ans;int len=0;for(int i=1;i<=t;i++){if(s[i] == '1'){ans = s.substr(i,t-i+1);len = t-i+1;break;   }}//如果序列子序列len=0,则证明该字符串全部为0,输入0即可if(len==0){cout << 0;}else{ans = " "+ans;int index=0;for(int i=1;i<=len;i++){if(ans[i] == '0'){index = i;break;}}//如果index=0,则证明该字符串中全部都为1,则只需要输出它本身即可if(index == 0){for(int i=1;i<=len;i++)cout << ans[i];return 0;}int len1 = len-index+1;string s3=" ";string s5=" ";//s5代表进行或运算后的最大值,也就是len个1组成的字符串for(int i=1;i<=len;i++)s5 +='1';for(int i=1;i<index;i++){string s1=" ";string s2=ans;int ii=len1;//截取len1长度的字符串s1s1 += ans.substr(i,len1);//ans和s1进行或运算for(int j=len1,jj=len;j>=1;j--,jj--){if(s1[j]=='1'&&s2[jj]=='0')s2[jj] = '1';}s2 = " "+s2;//s3存的是得到的字符串的最大值 if(s3<s2)s3 = s2;//如果s3已经是等于s5则到达最大值,退出循环即可if(s3==s5)break;}string s4 = s3.substr(1,s3.length());cout << s4 << endl;}return 0;} 

总结

第一次写csdn,所以不太熟练,因为题目是从codeforce复制过来的,题目会乱,建议在cf网站上看题,谢谢观看

Educational Codeforces Round 137 (Rated for Div. 2)A~D题解相关推荐

  1. Educational Codeforces Round 133 (Rated for Div. 2)(CD题解)

    Educational Codeforces Round 133 (Rated for Div. 2)CD题解 过AB补CD C. Robot in a Hallway 题意 题意:现有 2∗m 的方 ...

  2. Educational Codeforces Round 140 (Rated for Div. 2)A~D题解

    文章目录 A B C D A 思路:就是三个点如果任意两个点的横坐标相同,并且任意两个点的纵坐标相同的话就不行. #include <cstring> #include <iostr ...

  3. Educational Codeforces Round 113 (Rated for Div. 2) A~D题解

    文章目录 A. Balanced Substring B. Chess Tournament C. Jury Meeting D. Inconvenient Pairs A. Balanced Sub ...

  4. Educational Codeforces Round 127 (Rated for Div. 2) A~E 题解

    A. String Building 题意: 问是否可以用 a a . a a a . b b . b b b aa.aaa.bb.bbb aa.aaa.bb.bbb 拼成所给字符串. 思路: 将原字 ...

  5. Educational Codeforces Round 113 (Rated for Div. 2) D. Inconvenient Pairs

    Educational Codeforces Round 113(Rated for Div. 2)的其他题解点我 D. Inconvenient Pairs 原题链接 题目大意: 在一个大小为 1e ...

  6. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  7. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  8. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

  9. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

最新文章

  1. RHEL6.4更改为CentOS6.4的yum源
  2. 地区的json数据_Python 连接开放航空交通数据,轻松构建航班跟踪应用!
  3. python 数据分析学什么-python数据分析师要学什么
  4. TensorFlowIO操作(一)----线程和队列
  5. mysql错误:……is marked as crashed and should be repai
  6. RAID5EE 含有上次残余信息的分析
  7. 猎豹浏览器插件无法加载怎么办 插件无法加载解决方法
  8. 2月8日见!三星Galaxy S22系列新增樱花粉配色
  9. Java项目导入eclipse后项目出现JRE System Library [JavaSE-1.8](unbound)
  10. kmem 反编译linux内核_24小时学通Linux内核之如何处理输入输出操作
  11. 用matlab画x 的定积分图像,matlab图像定积分
  12. Linux学习笔记:常用100条命令(一)
  13. 如何安装xvidcore
  14. 【配置管理】配置审核-物理配置审核-功能配置审核-配置管理审核
  15. Web中间件漏洞总结
  16. 【VUE】微商城(七)----实现分类页面功能
  17. [运算放大器]佛朗哥笔记 - 电阻性反馈电路 - 电流泵与电流放大器
  18. 多元统计分析-橄榄油数据集
  19. 商务协同办公市场有「后浪」
  20. 查询出部门名称、部门的员工数、部门的平均工资、部门的最低收入雇员姓名和最高收入雇员的姓名...

热门文章

  1. 图像(层)正常混合模式详解(上)
  2. word使用:默认粘贴方式的更改
  3. 如何提取header中指定字段
  4. 华硕服务器主板安装系统提示驱动,解决B150主板安装win7操作系统USB设备无法读取故障...
  5. (七)继续对话库检索的闲聊系统
  6. 地图学相关知识(一)
  7. Python模块字典
  8. 【微信小程序】开发入门篇(二)
  9. windows下更改中文用户名为英文
  10. 易学笔记-系统分析师考试-第9章 系统规划/9.5 成本效益分析技术/9.5.2 净现值分析