A. Do Not Be Distracted!

题意:

一件事情一但开始,只能做完才能做别的事,当出现一件事不连续出现时,教师会怀疑

题目:

Polycarp has 26 tasks. Each task is designated by a capital letter of the Latin alphabet.

The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.

Polycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.

For example, if Polycarp solved tasks in the following order: “DDBBCCCBBEZ”, then the teacher will see that on the third day Polycarp began to solve the task ‘B’, then on the fifth day he got distracted and began to solve the task ‘C’, on the eighth day Polycarp returned to the task ‘B’. Other examples of when the teacher is suspicious: “BAB”, “AABBCCDDEEBZZ” and “AAAAZAAAAA”.

If Polycarp solved the tasks as follows: “FFGZZZY”, then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn’t have any suspicious: “BA”, “AFFFCC” and “YYYYY”.

Help Polycarp find out if his teacher might be suspicious.

Input

The first line contains an integer t (1≤t≤1000). Then t test cases follow.

The first line of each test case contains one integer n (1≤n≤50) — the number of days during which Polycarp solved tasks.

The second line contains a string of length n, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.

Output

For each test case output:

“YES”, if the teacher cannot be suspicious;
“NO”, otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

Example

input

5
3
ABA
11
DDBBCCCBBEZ
7
FFGZZZY
1
Z
2
AB

output

NO
NO
YES
YES
YES

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int t,n,m;
int main(){string s;cin>>t;while(t--){cin>>n>>s;int flag=0;int book[30];memset(book,0,sizeof(book));for(int i=0;i<n;i++){while(s[i]==s[i+1])i++;//cout<<<<endl;if(book[s[i]-'A'+1]==1){flag=1;break;}book[s[i]-'A'+1]=1;}flag==1?cout<<"NO"<<endl:cout<<"YES"<<endl;}
}

B. Ordinary Numbers

题意:

给你一个数n,问(1~n)中有多少个,每个数位都相等的数?

题目:

Let’s call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.

For a given number n, find the number of ordinary numbers among the numbers from 1 to n.

Input

The first line contains one integer t (1≤t≤104). Then t test cases follow.

Each test case is characterized by one integer n (1≤n≤109).

Output

For each test case output the number of ordinary numbers among numbers from 1 to n.

Example

input

6
1
2
3
4
5
100

output

1
2
3
4
5
18

AC代码:

#include<iostream>
using namespace std;
int main()
{int t;cin>>t;while(t--){long long int n,i,j,count=0;cin>>n;for(i=1; i<=n; i=i*10+1){for(j=1; j<=9; j++)if(i*j<=n){count++;//cout<<i<<"***"<<j<<endl;}}cout<<count<<endl;}
}

C. Not Adjacent Matrix

题意:

给你一个n*n的方格,向里面放置(1~n∗nn*nn∗n)的数,问如何放,使得任意格子的上下左右格子的差值不为一。

题目:

We will consider the numbers a and b as adjacent if they differ by exactly one, that is, |a−b|=1.

We will consider cells of a square matrix n×n as adjacent if they have a common side, that is, for cell (r,c) cells (r,c−1), (r,c+1), (r−1,c) and (r+1,c) are adjacent to it.

For a given number n, construct a square matrix n×n such that:

Each integer from 1 to n2 occurs in this matrix exactly once;
If (r1,c1) and (r2,c2) are adjacent cells, then the numbers written in them must not be adjacent.

Input

The first line contains one integer t (1≤t≤100). Then t test cases follow.

Each test case is characterized by one integer n (1≤n≤100).

Output

For each test case, output:

-1, if the required matrix does not exist;
the required matrix, otherwise (any such matrix if many of them exist).
The matrix should be outputted as n lines, where each line contains n integers.

Example

input

3
1
2
3

output

1
-1
2 9 7
4 6 3
1 8 5

AC代码:

#include <bits/stdc++.h>
using namespace std;int main()
{int t;cin>>t;while(t--){int n;cin>>n;if(n == 2)cout<<"-1\n";else{for(int i=1; i<=n*n; i+=2)//交叉放置即可cout<<i<<' ';for(int i=2; i<=n*n; i+=2)cout<<i<<' ';cout<<endl;}}return 0;
}

D. Same Differences

题意:

给你一个n个整数的数组,问数组中满足i<j and aj−ai=j−i,a_{j}-a_{i} = j-i,aj​−ai​=j−i,.有多少个?

题目:

You are given an array a of n integers. Count the number of pairs of indices (i,j) such that i<j and aj−ai=j−i,a_{j}-a_{i} = j-i,aj​−ai​=j−i,.

Input

The first line contains one integer t (1≤t≤104). Then t test cases follow.

The first line of each test case contains one integer n (1≤n≤2⋅105).

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — array a.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.

Output

For each test case output the number of pairs of indices (i,j) such that i<j and aj−ai=j−i.

Example

input

4
6
3 5 1 4 6 6
3
1 2 3
4
1 3 3 4
6
1 6 3 4 5 6

output

1
3
3
10

分析:

让我们重写一下原始的相等性:
aj−ai=j−i,a_{j}-a_{i} = j-i,aj​−ai​=j−i,
aj−j=ai−ia_{j}-j = a_{i}-iaj​−j=ai​−i
让我们用bi=ai−ib_{i} = a_{i}-ibi​=ai​−i替换每个aia_{i}ai​。 那么答案是对(i,j)的对数,使得i <j并且bi=bjb_{i} = b_{j}bi​=bj​。 要计算此值,可以使用地图或排序。

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{int t;cin>>t;while(t--){int n;map<int,int> mp;cin>>n;long long ans=0;for(int i=1; i<=n; i++){int x;cin>>x;ans+=mp[x-i];mp[x-i]++;}cout<<ans<<endl;}return 0;
}

H - Arranging The Sheep

题意:

给你一个字符串,表示一排中

Codeforces Round #719 (Div. 3)/ Codeforces Round #720 (Div. 2)相关推荐

  1. Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)

    Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2) 题号 题目 知识点 A A Variety of Opera ...

  2. Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)

    Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2) 题号 题目 知识点 A Game of Life B Lor ...

  3. mysql round不四舍五入_MySQL中ROUND函数进行四舍五入操作陷阱分析

    本文实例讲述了MySQL中ROUND函数进行四舍五入操作陷阱.,具体如下: 在MySQL中, ROUND函数用于对查询结果进行四舍五入,不过最近使用ROUND函数四舍五入时意外发现并没有预期的那样,本 ...

  4. php round函数怎么用,excel round函数怎么用

    excel round函数怎么用? round函数是EXCEL中的一个基本函数,作用按指定的位数对数值进行四舍五入,语法是ROUND(number, num_digits). 语法ROUND(numb ...

  5. xHTML+div布局:三个div,两边div宽度固定,中间div宽度自适应

    xHTML+div经常考题:三个div,两边div宽度固定,中间div宽度自适应. 和大家分享一个实现方式: 1.html代码 1 <div class="dyleft"&g ...

  6. html语言div什么意思,css中div是什么意思?

    css中div是什么意思? div是html中的一个标签,通常作为容纳其他元素的容器.在css中,表示一种选择器,可以直接使用div(标签选择器)来查找HTML元素设置样式:而如果是.div那么表示某 ...

  7. php中的div是什么意思,div是什么意思?div标签怎么用

    很多刚入门的新手,对div是什么意思还不是很了解,现在很多网站上都有div,那么究竟div是什么意思?下面我们来总结一下div标签怎么用. 一:div是什么意思 我们随便打开一个网页源代码就会发现里面 ...

  8. div 隐藏_CSS实现六边形Div图片展示效果

    一. 效果图 二. 六边形效果涉及到的知识点 1. transform: rotate(120deg); // 元素旋转 2. overflow: hidden; // 超出隐藏 3. visibil ...

  9. 实现div可以调整高度(div实现resize)

    实现div可以调整高度(div实现resize) 一.div 实现resize(类似textarea) 代码如下: <!DOCTYPE html> <html><head ...

最新文章

  1. Node.js 0.8.21 稳定版发布
  2. python 流式编程_python 使用yield进行数据的流式处理
  3. mysql 中caption_Django-Model操作数据库(增删改查、连表结构)(示例代码)
  4. Mr.J--Java接口实现
  5. 雷军:电视机越大才越舒服!
  6. 美国NIST仍在与财政部和国防部就区块链支付跟踪项目合作
  7. java excel导出 模板_Java Excel 导出 模板
  8. 独家 | 李飞飞亲口跟我们说:离职Google是假新闻
  9. Mysql 数据库 主从数据库 (主从)(主主)
  10. 智能优化算法:灰狼优化算法-附代码
  11. iOS 开发中出现假死解决思路
  12. 数据结构 hbb(汉堡包)
  13. 小红书电商入驻全流程指南
  14. 聚宽JQData说明书
  15. MySQL视图简单操作
  16. linux中使用redshift进行防蓝光
  17. oracle之查询某一列是否含有英文字符
  18. 使用Python办公自动化:将文本、表格及图片写入到Word
  19. Java并发包学习(CountDownLatch,Seamphore,CyclicBarrier,Exchanger)
  20. 阿里架构师,谈对技术架构的理解,以及架构师角色的思考

热门文章

  1. Android之编译提示error: Apostrophe not preceded by
  2. 剑指offer之分行从上到下之字行打印二叉树
  3. 如何在IE浏览器里面定位到关键字的位置(页面代码)和这个关键字位置模块的请求
  4. java和C++之单例类双重检查加锁
  5. Android之解决Gigaset手机不能设置DeviceOwner权限提示already provisioned问题
  6. 《看聊天记录都学不会C#?太菜了吧》(5)C# 中可以用中文名变量?
  7. vlan跨交换机 udp广播_【详解】VLAN和VXLAN有何区别?VXLAN运用场景有哪些?
  8. linux把2块盘挂到一个分区,linux系统如何挂载第二块硬盘
  9. 豆瓣评分9.4!这一部纪录片,探秘中国人迹罕至的未至之境!
  10. 裤子换裙子,就问你GAN的这波操作秀不秀