Codeforces Round #719 (Div. 3)/ Codeforces Round #720 (Div. 2)

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*nnn)的数,问如何放,使得任意格子的上下左右格子的差值不为一。

题目:

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,ajai=ji.有多少个?

题目:

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,ajai=ji.

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,ajai=ji
aj−j=ai−ia_{j}-j = a_{i}-iajj=aii
让我们用bi=ai−ib_{i} = a_{i}-ibi=aii替换每个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

题意:

给你一个字符串,表示一排中🐏羊的站位,对羊进行移动,使得羊之间没有空隙,问最小的移动数?

题目:

You are playing the game “Arranging The Sheep”. The goal of this game is to make the sheep line up. The level in the game is described by a string of length n, consisting of the characters ‘.’ (empty space) and ‘*’ (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the corresponding square exists and is empty. The game ends as soon as the sheep are lined up, that is, there should be no empty cells between any sheep.

For example, if n=6 and the level is described by the string “**.*…”, then the following game scenario is possible:

the sheep at the 4 position moves to the right, the state of the level: “.";
the sheep at the 2 position moves to the right, the state of the level: "
...";
the sheep at the 1 position moves to the right, the state of the level: ".
..";
the sheep at the 3 position moves to the right, the state of the level: ".
..";
the sheep at the 2 position moves to the right, the state of the level: "…
*.”;
the sheep are lined up and the game ends.
For a given level, determine the minimum number of moves you need to make to complete the level.

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≤106).

The second line of each test case contains a string of length n, consisting of the characters ‘.’ (empty space) and ‘*’ (sheep) — the description of the level.

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

Output

For each test case output the minimum number of moves you need to make to complete the level.

Example

Input

5
6
**.*..
5
*****
3
.*.
3
...
10
*.*...*.**

Output

1
0
0
0
9

分析:

因为最终是让所有的羊在一起,那么处在最中间的羊,动一步,都不是最少的移动,所以对其他羊来说,就都往中间羊靠拢即可。
在这里插入图片描述

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int M=1e6+10;
int a[1000010];
int main()
{int t;cin>>t;while(t--){int n;cin>>n;string s;cin>>s;int sum=0;for(int i=0; i<n; i++)if(s[i]=='*')a[sum++]=i;long long  ans=0;int m=sum/2;for(int i=0; i<sum; i++)ans+=abs(a[i]-a[m])-abs(i-m);//第i只羊离中间羊的距离;cout<<ans<<endl;}return 0;
}

A - Nastia and Nearly Good Numbers

题意:

给你两个数A和B,问是否存在两个能够整除A,不能整除ab的数x,y,及一个x+y能够整除ab的数z。

题目:

Nastia has 2 positive integers A and B. She defines that:

The integer is good if it is divisible by A⋅B;
Otherwise, the integer is nearly good, if it is divisible by A.
For example, if A=6 and B=4, the integers 24 and 72 are good, the integers 6, 660 and 12 are nearly good, the integers 16, 7 are neither good nor nearly good.

Find 3 different positive integers x, y, and z such that exactly one of them is good and the other 2 are nearly good, and x+y=z.

Input

The first line contains a single integer t (1≤t≤10000) — the number of test cases.

The first line of each test case contains two integers A and B (1≤A≤106, 1≤B≤106) — numbers that Nastia has.

Output

For each test case print:

“YES” and 3 different positive integers x, y, and z (1≤x,y,z≤1018) such that exactly one of them is good and the other 2 are nearly good, and x+y=z.
“NO” if no answer exists.
You can print each character of “YES” or “NO” in any case.
If there are multiple answers, print any.

Example

Input

3
5 3
13 2
7 11

Output

YES
10 50 60
YES
169 39 208
YES
28 154 182

Note

In the first test case: 60 — good number; 10 and 50 — nearly good numbers.

In the second test case: 208 — good number; 169 and 39 — nearly good numbers.

In the third test case: 154 — good number; 28 and 182 — nearly good numbers.

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
ll n,m;
int main(){int t;cin>>t;while(t--){cin>>n>>m;if(m==1)cout<<"NO"<<endl;else{cout<<"YES"<<endl;printf("%lld %lld %lld\n",n,m*n,(m+1)*n);//相邻两个数互质}}return 0;
}

B - Nastia and a Good Array

题意:

给你一个包含n个整数的数组,现在经过操作:
1.每次选取两个整数,ai,aja_{i},a_{j}ai,aj,以及在(1~2∗1092*10^{9}2109)中找到两个数x,y;
2.满足min(ai,aj)=min(x,y)min(a_{i},a_{j})=min(x,y)min(ai,aj)=min(x,y)
3.最后让ai=x,aj=ya_{i}=x,a_{j}=yai=x,aj=y
使得最终的序列,任意相邻的两个数都互质。

题目·:

Nastia has received an array of n positive integers as a gift.

She calls such an array a good that for all i (2≤i≤n) takes place gcd(ai−1,ai)=1, where gcd(u,v) denotes the greatest common divisor (GCD) of integers u and v.

You can perform the operation: select two different indices i,j (1≤i,j≤n, i≠j) and two integers x,y (1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y). Then change ai to x and aj to y.

The girl asks you to make the array good using at most n operations.

It can be proven that this is always possible.

Input

The first line contains a single integer t (1≤t≤10000) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤105) — the length of the array.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the array which Nastia has received as a gift.

It’s guaranteed that the sum of n in one test doesn’t exceed 2⋅105.

Output

For each of t test cases print a single integer k (0≤k≤n) — the number of operations. You don’t need to minimize this number.

In each of the next k lines print 4 integers i, j, x, y (1≤i≠j≤n, 1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y) — in this manner you replace ai with x and aj with y.

If there are multiple answers, print any.

Example

Input

2
5
9 6 3 11 15
3
7 5 13

Output

2
1 5 11 9
2 5 7 6
0

Note

Consider the first test case.

Initially a=[9,6,3,11,15].

In the first operation replace a1 with 11 and a5 with 9. It’s valid, because min(a1,a5)=min(11,9)=9.

After this a=[11,6,3,11,9].

In the second operation replace a2 with 7 and a5 with 6. It’s valid, because min(a2,a5)=min(7,6)=6.

After this a=[11,7,3,11,6] — a good array.

In the second test case, the initial array is already good.

分析:

由于不要求最优,我们可以找每个间隔都放置一个质数1e9+71e^{9}+71e9+7;

AC代码:

#include<stdio.h>
#include<iostream>
using namespace std;
const int mod=1e9+7;
const int M=1e5+10;
int a[M];
int main(){int t,n;cin>>t;while(t--){cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}cout<<n/2<<endl;for(int i=1;i<n;i+=2){printf("%d %d %d %d\n",i,i+1,min(a[i],a[i+1]),mod);}}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/309361.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

dotNET Core 3.X 使用 Autofac 来增强依赖注入

在上一篇《dotNET Core 3.X 依赖注入》中简单介绍了 dotNET Core 框架本身的依赖注入功能&#xff0c;大部分情况下使用框架的依赖注入功能就可以满足了&#xff0c;在一些特殊场景下&#xff0c;我们就需要引入第三方的注入框架。为什么要使用 Autofac&#xff1f;如果您在之前…

[JS-DOM]DOM概述

DOM&#xff1a; * 概念&#xff1a; Document Object Model 文档对象模型* 将标记语言文档的各个组成部分&#xff0c;封装为对象。可以使用这些对象&#xff0c;对标记语言文档进行CRUD的动态操作* W3C DOM 标准被分为 3 个不同的部分&#xff1a;* 核心 DOM - 针对任何结构…

基于 abp vNext 和 .NET Core 开发博客项目 - Blazor 实战系列(一)

系列文章使用 abp cli 搭建项目给项目瘦身&#xff0c;让它跑起来完善与美化&#xff0c;Swagger登场数据访问和代码优先自定义仓储之增删改查统一规范API&#xff0c;包装返回模型再说Swagger&#xff0c;分组、描述、小绿锁接入GitHub&#xff0c;用JWT保护你的API异常处理和…

2021年度训练联盟热身训练赛第一场 H题On Average They‘re Purple(BFS)

题意&#xff1a; 给你一些联通关系&#xff0c;问Bob先选择一些路径&#xff08;1~n&#xff09;联通&#xff0c;Alice在路径上染色&#xff0c;Bob的目的是选择一些路径使得染色变化最小&#xff0c;对于Alice来说&#xff0c;需要使得在Bob选择的&#xff08;1−n1-n1−n&…

使用请求头认证来测试需要授权的 API 接口

使用请求头认证来测试需要授权的 API 接口Intro有一些需要认证授权的接口在写测试用例的时候一般会先获取一个 token&#xff0c;然后再去调用接口&#xff0c;其实这样做的话很不灵活&#xff0c;一方面是存在着一定的安全性问题&#xff0c;获取 token 可能会有一些用户名密码…

双端队列 BFS + Chamber of Secrets CodeForces - 173B

题意&#xff1a; 一个 nmn\times mnm 的图&#xff0c;现在有一束激光从左上角往右边射出&#xff0c;每遇到 ‘#’&#xff0c;你可以选择光线往四个方向射出&#xff0c;或者什么都不做&#xff0c;问最少需要多少个 ‘#’ 往四个方向射出才能使光线在第 n 行往右边射出。 …

程序员过关斩将--作为一个架构师,我是不是应该有很多职责?

点击上方“蓝字”关注我们领取架构书籍每一个程序员都有一个架构梦。上面其实本质上是一句富有事实哲理的废话&#xff0c;要不然也不会有这么多人关注你的公众号。这些年随着“企业数字化”转型的口号&#xff0c;一大批企业奔跑在转型的路上&#xff0c;希望领先一步对手将企…

Excel使用技巧,补充中。。。

Excel表怎么把名字按字母排序 然后后面的数据也跟着变动 1、首先在excel表格的A列单元格中输入字母&#xff0c;选中需要排序的A列和B列单元格。 2、然后点击工具栏“数据”中的“排序”。 3、在弹出的对话框中的“次序”下拉框中选择“自定义序列”。 4、然后在弹出的对话…

递归函数中局部变量和全局变量

有时候会因为不注意递归函数中局部变量和全局变量&#xff0c;而导致结果和我们期望的不一致&#xff0c;递归中&#xff0c;在递归中的局部变量和全局变量&#xff0c;可以类似的看成函数调用时传递方式的按值传递&#xff08;局部变量&#xff09;和引用传递&#xff08;全局…

基于 abp vNext 和 .NET Core 开发博客项目 - Blazor 实战系列(二)

系列文章使用 abp cli 搭建项目给项目瘦身&#xff0c;让它跑起来完善与美化&#xff0c;Swagger登场数据访问和代码优先自定义仓储之增删改查统一规范API&#xff0c;包装返回模型再说Swagger&#xff0c;分组、描述、小绿锁接入GitHub&#xff0c;用JWT保护你的API异常处理和…

Azure App Service 如何在第一时间用上最新版 .NET Core

点击上方关注“汪宇杰博客” ^_^导语微软会经常对 .NET Core 发布更新&#xff0c;通常为安全补丁。这不&#xff0c;今天早上&#xff0c;.NET Core 3.1.5 更新发布了。然而 Azure App Service 自身的 .NET Core runtime 并不会在第一时间更新&#xff0c;每次都要等几周后微软…

我们是如何做DevOps的?

一、DevOps的理解DevOps的概念理解DevOps 的概念在软件开发行业中逐渐流行起来。越来越多的团队希望实现产品的敏捷开发&#xff0c;DevOps 使一切成为可能。有了 DevOps &#xff0c;团队可以定期发布代码、自动化部署、并将持续集成 / 持续交付作为发布过程的一部分。一句话概…

word文档相关使用

主要是为了记忆&#xff0c;有的时候&#xff0c;之前查阅过&#xff0c;后来使用又忘记了&#xff0c;以后碰了就陆续添加吧&#xff0c;先开一个博文 文章目录插入图片&#xff0c;显示不全的问题&#xff1a;方法一&#xff1a;方法二&#xff1a;方法三&#xff1a;在左侧显…

调试实战 —— dll 加载失败之 Debug Release争锋篇

缘起 最近&#xff0c;项目里遇到一个 dll 加载不上的问题。实际项目比较复杂&#xff0c;但是解决后&#xff0c;又是这么的简单&#xff0c;合情合理。本文是我使用示例工程模拟的&#xff0c;实际项目中另有玄机&#xff0c;但问题的本质是一样的。本文从行文上与 《调试实战…

一文说通Dotnet Core的后台任务

这是一文说通系列的第二篇&#xff0c;里面有些内容会用到第一篇中间件的部分概念。如果需要&#xff0c;可以参看第一篇&#xff1a;一文说通Dotnet Core的中间件一、前言后台任务在一些特殊的应用场合&#xff0c;有相当的需求。比方&#xff0c;我们需要实现一个定时任务、或…

2021年度训练联盟热身训练赛第五场 H题In-place Sorting+贪心构造

题意&#xff1a; 给你n个小于101810^{18}1018的大数&#xff0c;问在可以再不改变序列位置&#xff0c;之改变数值中某数位的‘9’变为‘6’或将‘6’变为‘9’&#xff0c;求的最终序列由小到大&#xff0c;且字典序最小。 题目&#xff1a; 链接&#xff1a;https://ac.n…

用.NET进行客户端Web开发?看这个Bootstrap风格的BlazorUI组件库

点击上方“Dotnet9”添加关注哦Blazor一、前言今天在下班的路上&#xff08;地铁上&#xff09;&#xff0c;站长习惯性的掏出手机&#xff0c;就收到知乎向站长推送的一篇BlazorUI组件库推荐文章&#xff0c;是码云官方的&#xff1a;原文链接[1]&#xff0c;于是我立即打开码…

[JavaWeb-XML]XML约束概述

约束&#xff1a;规定xml文档的书写规则 * 作为框架的使用者(程序员)&#xff1a;1. 能够在xml中引入约束文档2. 能够简单的读懂约束文档* 分类&#xff1a;1. DTD:一种简单的约束技术2. Schema:一种复杂的约束技术

在Asp.NET Core中如何优雅的管理用户机密数据

在Asp.NET Core中如何优雅的管理用户机密数据背景回顾在软件开发过程中&#xff0c;使用配置文件来管理某些对应用程序运行中需要使用的参数是常见的作法。在早期VB/VB.NET时代&#xff0c;经常使用.ini文件来进行配置管理&#xff1b;而在.NET FX开发中&#xff0c;我们则倾向…

基于 abp vNext 和 .NET Core 开发博客项目 - Blazor 实战系列(三)

系列文章使用 abp cli 搭建项目给项目瘦身&#xff0c;让它跑起来完善与美化&#xff0c;Swagger登场数据访问和代码优先自定义仓储之增删改查统一规范API&#xff0c;包装返回模型再说Swagger&#xff0c;分组、描述、小绿锁接入GitHub&#xff0c;用JWT保护你的API异常处理和…