目录

A. Average Walk(签到)

题意:

思路:

代码:

C. Company Layoffs(签到)

题意:

思路:

代码:

D. Denji1(模拟/二分)

思路:

代码:

K. Keypad Repetitions(签到,哈希)

题意:

思路:

代码:

L. Ladybug And The Bullet Train(图 / BFS)

题意:

思路:

代码:


A. Average Walk(签到)

John bought a brand new smart watch, this smart watch keeps record of his exercises, mainly, the number of steps John takes during the day. The watch has a feature called "exercise mode", when exercise mode is enabled the watch will "beep" each minute showing the total amount of steps taken since the "exercise mode" was enabled. To take advantage of this feature, John decided to exercise each morning before going to work, his morning exercise will be a walk through a road nearby where he can get fresh air and walk withouth the need to stop to cross streets.

Since John will perform the walk in the mornings, John decided to walk until he has taken at least 3000 steps after a watch "beep", but no more than 15 minutes to avoid having to rush to get to his office in time. John is very consistent with the amount of X steps he takes each minute, this means, John takes exactly X steps each minute, no more, no less.

Given the amount X of stepss John takes each minute, help John find how many minutes he has to walk to finish his morning exercise.

Input

The first and only line of input contains a single integer number X(1≤X≤3000), the number of steps John takes in a minute.

Output

Output a line a single integer number, representing how many minutes John has to walk to finish his morning exercise.

Examples

input

1

output

15

input

300

output

10

input

2999

output

2

input

3000

output

1

题意:

小明每天最多走3000步,一分钟最多走x步,最多走15分钟,问小明能走多少分钟

思路:

3000/x  向上取整,然后和15取较小值即可

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int x;
void solve(){cin>>x;cout<<min(15,(3000+x-1)/x);
}int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int T=1;//cin>>T;while(T--){solve();}return 0;
}

C. Company Layoffs(二分 / 前缀和)

The tech company, Weta, has announced that it will continue to make layoffs once a week for the next M weeks.

For the layoffs, Weta has established that it will fire all employees who have a score greater than Qi. Qi is different every week, and obviously the current week score must be lower than the previous one.

Fortunately, the employees know about this in advance. That is why everyone who would be affected by the week's layoff must make their score equal to Qi.

Weta will not notice this, since Weta does not care about the number of employees fired, but the sum of the employees score.

You, as the representative of the employees, must give Weta the sum of the scores once they have all adjusted their scores to avoid being fired.

Note that only employees with a score greater than Qi can change their score.

Input

The first line of input contains two integer N, M (1 ≤ M < N ≤ 105), the number of employees in Weta and the number of layoffs.

The next line contains N integers Si (1 ≤ Si ≤ 109)

The following M lines describe the layoffs. The i-th of them contains Qi, the score for the layoff of the i−thℎ week. (1 ≤ Qi ≤ 109)

Output

Print M lines with the sum of employees' scores.

Example

input

5 3
2 3 5 5 10
8
7
1

output

23
22
5

题意:

给一个长度为n的数组,在接下来m次查询x,x递减,所有大于x的值都会变成x,然后输出元素和

思路:

先把数组排序,前缀和预处理,然后二分查找第一个大于x的数,直接计算即可

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;void solve(){int n,m;cin>>n>>m;vector<ll>a(n+1);vector<ll>pre(n+1);pre[0]=0;for(int i=1;i<=n;i++){cin>>a[i];}sort(a.begin()+1,a.end());  //排序for(int i=1;i<=n;i++){pre[i]=a[i]+pre[i-1];   //预处理}while(m--){ll x;cin>>x;ll pos=lower_bound(a.begin()+1,a.end(),x)-a.begin();cout<<pre[pos-1]+x*(n-pos+1)<<endl;}
}
int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int T=1;
//    cin>>T;while(T--){solve();}return 0;
}

D. Denji1(模拟 / 二分)

Denji is trying to kill the algorithm demon. To kill him, Denji must perform this task.

Initially, the demon will give Denji an empty array. Then, Denji should perform a sequence of M operations.

An operation can be one of the following:

  1. Add a number to the end of the array.
  2. Delete from the array the number added in operation i.
  3. Add X to the number added in operation i.
  4. Print the number of smaller elements than the number added in operation i.

Unfortunately, Denji only knows how to use chainsaws, not computers, so he asked for your help to kill the algorithm demon.

Input

The first line of input contains an integer M (1 ≤ M ≤ 10^5).

The following m lines describe the operations. The i-th of them begins with a number type (type∈ {1,2,3,4}), which will represent the type of the operation given.

If type = 1, there will be one more integer in the line: A (1 ≤ A ≤ 109), which correspond the operation 1.

If type = 2, there will be one more integer in the line: B(1 ≤B < i), which correspond the operation 2. It is guaranteed that the number added in operation B is still in the array.

If type=3, there will be two integers more in the line: B, A (1 ≤ B < i; 1 ≤ A ≤ 109), which correspond the operation 3. It is guaranteed that the number added in operation B is still in the array.

If type = 4, there will be one more integer in the line: B (1 ≤ B < i), which correspond the operation 4. It is guaranteed that the number added in operation B is still in the array.

It is guaranteed that the first operation is of type 1.

Output

For each operation 4, please print a line containing the answer.

Examples

input

5
1 4
1 5
1 4
4 2
4 3

output

2
0

input

9
1 5
1 5
1 10
4 3
2 2
4 3
3 3 7
4 3
4 1

output

2
1
1
0

思路:

四种操作,维护一个单调容器,模拟操作即可

每次二分找到当前值在容器的位置,进行操作

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>ans;
ll a[100005];
ll n;
void solve(){cin>>n;for(int i=1;i<=n;i++){ll op,x,y;cin>>op;if(op==1){    //1为插入cin>>x;a[i]=x;auto pos=lower_bound(ans.begin(),ans.end(),x);ans.insert(pos,x);    //找到第一个大于等于x的位置插入}if(op==2){    //2为删除cin>>x;auto pos=lower_bound(ans.begin(),ans.end(),a[x]);ans.erase(pos);       //找到第一个x的位置删除}if(op==3){    //3为修改cin>>x>>y;    auto pos1=lower_bound(ans.begin(),ans.end(),a[x]);ans.erase(pos1);    //先把原来的值删去a[x]+=y;        //修改auto pos2=lower_bound(ans.begin(),ans.end(),a[x]);ans.insert(pos2,a[x]);    //修改后添加}if(op==4){    //4为查询cin>>x;x=a[x];    //返回在单调容器的下标ll anss=lower_bound(ans.begin(),ans.end(),x)-ans.begin();cout<<anss<<endl;}}
}int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int T=1;//cin>>T;while(T--){solve();}return 0;
}

K. Keypad Repetitions(签到 / 哈希)

A telephone keypad is a keypad installed on a push-button telephone or similar telecommunication device which usually contains 1010 keys, each of which represents a digit used to dial a telephone number. Today most telephones have an integrated memory, this memory allows users to store common used telephone numbers using a string identifier making it easier for the user to dial numbers without the need of having it memorized or stored in a paper agenda. In order for users to store the string identifier the keypad associates letters to some of the key digits, traditionally this is named as "letter mapping" and the most common one is shown in the following table:

Digit Letters
2 abc
3 def
4 ghi
5 jkl
6 mno
7 pqrs
8 tuv
9 wxyz

Using this "letter mapping" the user could store the string to identify a telephone number using the keypad, for example, to store the identifier "jhon" the user can press the keypad in the following order: "5466". One problem of this approach is that several identifiers can be represented pressing the keypad in the same order, for example, "5466" that can be used to represent "jhon", can represent also "kino".

Jaime has a list of N identifiers to be stored in his grandfathers old telephone, they suspect a lot of these identifiers can be represented with the same numbers, however, they have not been able to verify their claim, that is why they asked for your help to given the list of identifiers and a set of Q keypad presses to query, find how many identifiers of the list can be represented with each of the keypad presses.

Input

The first line of input contains two integer numbers N (1≤N≤105) and Q (1≤Q≤105), representing the number of identifiers in the list and the number of keypad presses to query. Each of the next N lines contains one of the strings of the list of identifiers, each string consists only of lowercase english alphabet letters and have a length between 1 and 10 characters. Each of the next Q lines contains a keypad press to query, each of the keypad presses contains between 1 and 10 digits between 2 and 9.

Output

For each query in the input print a line with a single integer, representing the number of identifiers in the list that can be represented using the keypad presses in the query.

Example

input

4 5
jhon
abcde
a
kino
5466
2
22233
2222
5466

output

2
1
1
0
2

题意:

模拟手机按键,给n个字符串,询问 按照给定的按键顺序 能按出几个字符串

思路:

把手机按键和字符串用哈希处理,直接读取即可

代码:

#include<bits/stdc++.h>
using namespace std;
void solve(){int n,q;cin>>n>>q;map<char,char>mm;   //哈希处理手机按键for(char ch='a';ch<='c';ch++)mm[ch]='2';for(char ch='d';ch<='f';ch++)mm[ch]='3';for(char ch='g';ch<='i';ch++)mm[ch]='4';for(char ch='j';ch<='l';ch++)mm[ch]='5';for(char ch='m';ch<='o';ch++)mm[ch]='6';for(char ch='p';ch<='s';ch++)mm[ch]='7';for(char ch='t';ch<='v';ch++)mm[ch]='8';for(char ch='w';ch<='z';ch++)mm[ch]='9';map<string,int>mmm;for(int i=1;i<=n;i++){string s;cin>>s;for(int j=0;j<s.length();j++)s[j]=mm[s[j]];mmm[s]++;       //哈希处理字符串}for(int i=1;i<=q;i++){string s;cin>>s;cout<<mmm[s]<<endl;}
}
int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int T=1;
//    cin>>T;while(T--){solve();}return 0;
}

L. Ladybug And The Bullet Train(图 / BFS)

Ladybug is an agent specialized in snatch-and-grab jobs, now he has a job that requires him to go to station X and grab a certain suitcase, starting from station 1.

To do that he will be travelling through the stations via a bullet train, so he can move from station A to station B if and only if there exists a train line that connects such stations, it is always possible to reach any station from any other station and that path is unique.

One thing about agent ladybug is that he has very bad luck, he forgot the map of the train lines in the taxi, so, he does not know how to get to station X from his initial station, the lack of a map will not stop him, he will travel through the stations without the map, knowing that eventually he will reach his destination.

Each station has signs that indicate what other stations are reachable taking a train from there. If the agent hasn't already reached station X, he will need to pick an arbitrary station to go to. He will not pick a station he has already visited, except if he reached a dead end (he cannot go to a new station) and return from where he came from.

It's guaranteed that he will at some point reach the station X with this method, but because he has very bad luck, that will end up taking him the longest amount of rides possible. Help his contractor know how many rides the agent has to take to reach station X.

Note:

- A ride is a movement between stations.

- If station Y has a sign that indicates the agent can reach station X taking a train from that station, the agent will take that train first.

Input

The first contains two integers separated by a space N (2≤N≤106) and X (2≤X≤N), indicating the number of stations in train network and the station where the agent should grab the suitcase. Each of the next N−1 lines contains two integer numbers A and B (1≤A,B≤N), indicating that there is a sign at station A which indicates there is a train the agent can use to reach station B from A, and viceversa.

Output

Print one line with an integer number, representing the amount of rides the agent needs to take to reach station X.

Examples

input

5 5
1 2
2 3
3 4
4 5

output

4

input

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

output

8

input

2 2
1 2

output

1

题意:

给一棵n个点的无根树,任意两点都联通,求从起点到终点最多可以走多少步

限制条件:(1)除了没有路可走的情况下,不能走已经走过的路(走到死路原路返回)

(2)如果当前位置可以直接到达终点,不会往其他地方走

思路:

BFS搜索,记录终点到起点的距离,搜到挨着终点的第一个点的时候停止这一方向的搜索,其它方向搜到死路为止

除了直接连接起点和终点的路径只走一遍,其它搜到的路都要走两遍(来回)

代码:

#include<bits/stdc++.h>
using namespace std;
vector<int>edge[1000005];
int dis[1000005];
bool vis[1000005];
void solve(){int n,X;cin>>n>>X;for(int i=1;i<n;i++){int u,v;cin>>u>>v;edge[u].push_back(v);   //建树edge[v].push_back(u);}queue<int>q;dis[1]=0;vis[1]=1;q.push(1);long long ans=0;while(!q.empty()){      //BFSint tmp=q.front();q.pop();bool flag=1;for(auto it:edge[tmp]){     //判断能不能到达终点if(it==X){flag=0;break;}}if(flag==0){    //不往其他地方走ans+=2;vis[X]=1;dis[X]=dis[tmp]+1;continue;}for(auto it:edge[tmp]){     //搜索和他相邻的边if(vis[it])continue;ans+=2;vis[it]=1;dis[it]=dis[tmp]+1;q.push(it);}}ans-=dis[X];    //减去起点到终点的距离cout<<ans<<endl;
}int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);solve();return 0;
}

2022 ICPC Gran Premio de Mexico Repechaje 题解相关推荐

  1. 训练记录番外篇(2):2022 ICPC Gran Premio de Mexico 2da Fecha

    2022 ICPC Gran Premio de Mexico 2da Fecha 2022.10.3 之前训得ak场,个人认为很edu. (顺便一提,可能这个训练记录番外系列的比赛都非常edu,十分 ...

  2. 2022 ICPC Gran Premio de Mexico 1ra Fecha(一)

    今天大部分时间都花在了上一场沈阳站的L题上了,一个树上背包+容斥原理,看了好久才理解,就不硬敲上了,再想几天在写题解.然后今天自己写了场ICPC墨西哥站的 ICPC Gran Premio de Me ...

  3. 2022 ICPC Gran Premio de Mexico 1ra Fecha 题解

    A 线性基 由于数组异或和固定,因此异或和为奇数的位置可以不用考虑,无论如何分,总是只能有1个为奇数,总贡献不变. 考虑异或和为偶数的位置,利用线性基求其中一部分尽可能大的结果,另一部分结果相同. # ...

  4. 2022 ICPC Gran Premio de Mexico 1ra Fecha (B、D、E、F)

    小技巧: stoi(str,0,2) 将从0开始的二进制串转化为十进制串 不是标准函数,慎用(一般应该没问题吧--) 本次补的题应该都是铜.银牌题,可能欧洲场简单很多 D. Different Pas ...

  5. 2020-2021 ICPC - Gran Premio de Mexico - Repechaje

    A. Atsa's Checkers Board 给定一个 n ∗ m n * m n∗m大小的矩阵,在该矩阵内放置黑色白色的石头,要保证每个 2 ∗ 2 2 * 2 2∗2的矩阵都有两个黑石头和两个 ...

  6. 2022 ICPC Gran Premio de Mexico 2da Fecha Final standings - K. Krystalova‘s Trivial Problem

    K. Krystalova's Trivial Problem time limit per test1 second memory limit per test256 megabytes input ...

  7. 【2021 ICPC Gran Premio de Mexico 2da Fecha F】Flipped Factorization 题解

    题目大意   设 x x x 的质因数分解为 p 1 c 1 p 2 c 2 ⋯ p m c m p_1^{c_1}p_2^{c_2}\cdots p_m^{c_m} p1c1​​p2c2​​⋯pmc ...

  8. 2023 ICPC Gran Premio de Mexico 1ra Fecha

    待更新 目录 1 A Aliases B Bucket storing D Dynamic Collection E Employees Bonus G Growing game J Jumping ...

  9. 2021 ICPC Gran Premio de Mexico 1ra Fecha

    C.Cypher Decypher 题意 找 [ i , j ] [i,j] [i,j]区间中有多少个质数 思路 数据范围为 1 ≤ i ≤ j ≤ 1 0 6 1\le i\le j\le 10^6 ...

最新文章

  1. 【Spark篇】---SparkStream初始与应用
  2. 对于***win2000 精彩过程实例!不可错过_出自:痞菜
  3. 三十六、rsync通过服务同步、Linux系统日志、screen工具
  4. 如何在Java中读取CSV文件-Iterator和Decorator的案例研究
  5. 2021计算机基础知识题库,2021~2021计算机基础知识练习题
  6. 关于网页js判断“客户端设备类型是移动端还是PC端“的解决方法?
  7. 【转载】推荐系统的十大挑战
  8. Ubuntu下BOINC服务器安装(step8失败)
  9. Hadoop设置任务执行队列及优先级
  10. default value mysql_Mysql Field * doesn't have a default value解决方法
  11. 【图像去雾】基于matlab偏振水下模糊图像去雾【含Matlab源码 396期】
  12. 颜色代码表(#号开头)
  13. springboot微服务使用Feign远程调用失败
  14. 读书笔记之《得未曾有》
  15. php使用grpc(windows环境下)
  16. overleaf表格_latex编写表格.doc
  17. 联通光纤猫虚拟服务器设置,【2017年整理】联通光猫配置操作手册.doc
  18. IDEA(2018.2)的下载、安装及破解
  19. ASP .NET MVC项目研发总结
  20. GM7123视频编码电路:TTL转VGA,替换SDA7123转换芯片

热门文章

  1. Deepin安装应用
  2. Spring笔记(基于狂神视频+自己理解)
  3. Mininet教程(六):多数据中心带宽实验
  4. python变量说法_Python不允许使用关键字作为变量名,允许使用内置函数名作为变量名,但这会改变函数名的含义...
  5. Parallels Desktop克隆出来的虚拟机拥有相同的SSH KEY的修改方法
  6. “百度杯”CTF比赛 十一月场Mangager
  7. 修复WiFi网卡驱动异常导致WiFi图标消失报错代码(56)
  8. 对象含有与成员函数不兼容的类型限定符
  9. Hibernate 列映射 – 解决其他类型映射命名冲突
  10. [PHP]PHP爬虫 - URP教务