Codeforces Round 889 (Div. 2)

简介: Codeforces Round 889 (Div. 2)

本次比赛链接:https://codeforces.com/contest/1849


A. Morning Sandwich


Monocarp always starts his morning with a good ol' sandwich. Sandwiches Monocarp makes always consist of bread, cheese and/or ham.


A sandwich always follows the formula:


  • a piece of bread
  • a slice of cheese or ham
  • a piece of bread
  • ……
  • a slice of cheese or ham
  • a piece of bread


So it always has bread on top and at the bottom, and it alternates between bread and filling, where filling is a slice of either cheese or ham. Each piece of bread and each slice of cheese or ham is called a layer.


Today Monocarp woke up and discovered that he has bb pieces of bread, cc slices of cheese and hh slices of ham. What is the maximum number of layers his morning sandwich can have?


Input


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


Each testcase consists of three integers b,cb,c and hh (2≤b≤1002≤b≤100; 1≤c,h≤1001≤c,h≤100) — the number of pieces of bread, slices of cheese and slices of ham, respectively.


Output


For each testcase, print a single integer — the maximum number of layers Monocarp's morning sandwich can have.


Example


Example


input

1. 3
2. 2 1 1
3. 10 1 2
4. 3 7 8

output

1. 3
2. 7
3. 5


Note


In the first testcase, Monocarp can arrange a sandwich with three layers: either a piece of bread, a slice of cheese and another piece of bread, or a piece of bread, a slice of ham and another piece of bread.


In the second testcase, Monocarp has a lot of bread, but not too much filling. He can arrange a sandwich with four pieces of bread, one slice of cheese and two slices of ham.


In the third testcase, it's the opposite — Monocarp has a lot of filling, but not too much bread. He can arrange a sandwich with three pieces of bread and two slices of cheese, for example.


思路:除去第一片面包,剩下的面包片数量等于料的数量,直接找到最小值乘二加上第一片面包


AC代码:


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
void solve()
{
  int m,a,b,maxx=0,aa=0;
  cin>>m>>a>>b;
  aa=m-1;
  maxx=min(aa,a+b);
  cout<<maxx*2+1<<endl;
    return ;
}
signed main()
{
  int t=1;
  cin>>t;
  while(t--) solve();
  return 0;
}


B. Monsters


Monocarp is playing yet another computer game. And yet again, his character is killing some monsters. There are nn monsters, numbered from 11 to nn, and the ii-th of them has aiai health points initially.


Monocarp's character has an ability that deals kk damage to the monster with the highest current health. If there are several of them, the one with the smaller index is chosen. If a monster's health becomes less than or equal to 00 after Monocarp uses his ability, then it dies.


Monocarp uses his ability until all monsters die. Your task is to determine the order in which monsters will die.


Input


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


The first line of each test case contains two integers nn and kk (1≤n≤3⋅1051≤n≤3⋅105; 1≤k≤1091≤k≤109) — the number of monsters and the damage which Monocarp's ability deals.


The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the initial health points of monsters.


The sum of nn over all test cases doesn't exceed 3⋅1053⋅105.


Output


For each test case, print nn integers — the indices of monsters in the order they die.


Example


input

1. 3
2. 3 2
3. 1 2 3
4. 2 3
5. 1 1
6. 4 3
7. 2 8 3 5

output

1. 2 1 3
2. 1 2
3. 3 1 2 4


Note


In the first example, the health points change as follows: [1,2,3–]→[1,2–,1]→[1–,0,1]→[−1,0,1–]→[−1,0,−1][1,2,3_]→[1,2_,1]→[1_,0,1]→[−1,0,1_]→[−1,0,−1]. The monster that is going to take damage the next time Monocarp uses his ability is underlined.


In the second example, the health points change as follows: [1–,1]→[−2,1–]→[−2,−2][1_,1]→[−2,1_]→[−2,−2].


In the third example, the health points change as follows: [2,8–,3,5]→[2,5–,3,5]→[2,2,3,5–]→[2,2,3–,2]→[2–,2,0,2]→[−1,2–,0,2]→[−1,−1,0,2–]→[−1,−1,0,−1][2,8_,3,5]→[2,5_,3,5]→[2,2,3,5_]→[2,2,3_,2]→[2_,2,0,2]→[−1,2_,0,2]→[−1,−1,0,2_]→[−1,−1,0,−1].


思路:将每个血量模上伤害值后放进结构体数组,对于能整除伤害值的不做操作,然后按从大到小排一下序,输出对应下标即可


AC代码:


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
struct s{
  int x,y;
}a[310000];
bool cmp(s aa,s bb)
{
  if(aa.x==bb.x)
  return aa.y<bb.y;
  else
  return aa.x>bb.x;
}
void solve()
{
  int n,k;
  scanf("%lld%lld",&n,&k);
  for(int i=1;i<=n;i++)
  {
  scanf("%lld",&a[i].x);
  if(a[i].x%k!=0)
  a[i].x=a[i].x%k;
  else
  a[i].x=k;
  a[i].y=i;
  }
  sort(a+1,a+1+n,cmp);
  for(int i=1;i<=n;i++)
  printf("%lld ",a[i].y);
  printf("\n");
    return ;
}
signed main()
{
  int t;
  scanf("%lld",&t);
  while(t--) solve();
  return 0;
}


C. Binary String Copying

You are given a string ss consisting of nn characters 0 and/or 1.


You make mm copies of this string, let the ii-th copy be the string titi. Then you perform exactly one operation on each of the copies: for the ii-th copy, you sort its substring [li;ri][li;ri] (the substring from the lili-th character to the riri-th character, both endpoints inclusive). Note that each operation affects only one copy, and each copy is affected by only one operation.


Your task is to calculate the number of different strings among t1,t2,…,tmt1,t2,…,tm. Note that the initial string ss should be counted only if at least one of the copies stays the same after the operation.


Input


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


The first line of each test case contains two integers nn and mm (1≤n,m≤2⋅1051≤n,m≤2⋅105) — the length of ss and the number of copies, respectively.


The second line contains nn characters 0 and/or 1 — the string ss.


Then mm lines follow. The ii-th of them contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n) — the description of the operation applied to the ii-th copy.


The sum of nn over all test cases doesn't exceed 2⋅1052⋅105. The sum of mm over all test cases doesn't exceed 2⋅1052⋅105.


Output


Print one integer — the number of different strings among t1,t2,…,tmt1,t2,…,tm.


Example


input

1. 3
2. 6 5
3. 101100
4. 1 2
5. 1 3
6. 2 4
7. 5 5
8. 1 6
9. 6 4
10. 100111
11. 2 2
12. 1 4
13. 1 3
14. 1 2
15. 1 1
16. 0
17. 1 1

output

1. 3
2. 3
3. 1


Note


Consider the first example. Copies below are given in order of the input operations. Underlined substrings are substrings that are sorted:


101100 →→ 011100;

101100 →→ 011100;

101100 →→ 101100;

101100 →→ 101100;

101100 →→ 000111.

There are three different strings among t1,t2,t3,t4,t5t1,t2,t3,t4,t5: 000111, 011100 and 101100.


Consider the second example:


100111 →→ 100111;

100111 →→ 001111;

100111 →→ 001111;

100111 →→ 010111.

There are three different strings among t1,t2,t3,t4t1,t2,t3,t4: 001111, 010111 and 100111.


AC代码:


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll l[N],r[N];
void work(){
  int n,m;
  string s;
  cin>>n>>m;
  cin>>s;
  s=' '+s;
  l[0]=0;r[n+1]=n+1;
  for(int i=1;i<=n;i++)
  if(s[i]=='1') l[i]=l[i-1];
  else l[i]=i;
  for(int i=n;i>=1;i--)
  if(s[i]=='1') r[i]=i;
  else r[i]=r[i+1];
  set<pair<ll,ll>> se;
  int x,y;
  while(m--){
  cin>>x>>y;
  x=r[x];
  y=l[y];
  if(x>=y) x=y=-1;
  se.insert({x,y});
  }
  printf("%d\n",se.size());
}
int main(){
  int t;
  cin>>t;
  while(t--)
  work();
  return 0;
}

目录
相关文章
|
存储 安全 API
【嵌入式系统】DMA工作原理与常用函数解析
【嵌入式系统】DMA工作原理与常用函数解析
1897 0
【嵌入式系统】DMA工作原理与常用函数解析
|
Ubuntu jenkins Java
如何在 Ubuntu 20.04 上安装 Mono
Mono 是一个平台,基于 ECMA/ISO 标准,用于开发和运行跨平台应用。它是微软的 .NET 框架的免费和开源实现。
5807 0
如何在 Ubuntu 20.04 上安装 Mono
|
8月前
|
JSON 缓存 供应链
1688供应商API:评价系统集成与供应商筛选实战指南
本文基于1688开放平台API,详解电商供应链中供应商评价系统对接与智能筛选的技术实现,涵盖评价数据获取、动态评分算法、风控因子集成及缓存优化,提供可落地的代码方案,助力企业提升采购效率、降低纠纷率,实现供应链数字化升级。
|
JSON 自然语言处理 前端开发
React国际化中英文切换实现
React国际化中英文切换实现
|
UED
需求优先级模型 - AxureMost
需求优先级模型是产品经理规划产品功能时的重要工具,帮助决定哪些需求应优先处理。常用模型包括KANO模型、矩阵分析法(四象限法则)、经济收益法、二八原则和WSJF模型等。这些模型适用于不同场景,如提升用户满意度、优化资源分配及最大化投资回报率(ROI),确保在有限的时间和资源下做出最佳决策。
1165 3
|
Web App开发 前端开发 开发工具
VisBug,提升web开发者幸福感的开发工具
作为web网页开发者,我们在日常开发过程中经常需要在控制台查看和修改元素的各种属性,以达到我们想要的各种效果。但这种方法往往效率低,而且效果不够直观。今天分享一款浏览器插件VisBug,可以帮助我们更快的查找元素,检查元素属性、间距,调整位置、颜色、字体大小、阴影等等,极大提升我们的开发体验。(支持Chrome、Firefox、Safari、Edge)
VisBug,提升web开发者幸福感的开发工具
|
Java Android开发
Android studio怎样修改 包名和AppId,android 加入AIDL进行底层通讯
Android studio怎样修改 包名和AppId,android 加入AIDL进行底层通讯
Android studio怎样修改 包名和AppId,android 加入AIDL进行底层通讯
|
搜索推荐 开发者
天猫精灵个人技能开发体验
天猫精灵个人技能开发体验
1285 0
天猫精灵个人技能开发体验
|
数据采集 存储 运维
神策数据联合阿里云计算巢,探索云端私有化部署新形态
本文是神策数据上架到计算巢的方案介绍,原文请查看:https://mp.weixin.qq.com/s/z2EAIGwYqptvlcBjK-xacQ数字经济时代,云计算作为新型基础设施的关键支撑技术,正在逐渐成为赋能企业数字化转型的数智创新平台。《中国云计算创新活力报告》指出,我国云计算产业近年来增速超过 30%,是全球增速最快的市场之一。当前,远程办公、在线教育、网络会议等场景需求进一步推动着
1458 0
神策数据联合阿里云计算巢,探索云端私有化部署新形态
|
数据采集 监控 网络架构
火力发电厂辅控网改造方案及网络架构分析
本文简要的介绍了火力发电厂辅控网改造后的通讯方式,对辅控网网络架构及数据采集方式进行了分析。
火力发电厂辅控网改造方案及网络架构分析

热门文章

最新文章