Voting

题面翻译

给定一个字符串,字符串中字符为D或R,代表两个团队

从1开始,每个人都有发言的权利,发言时,可以禁言一个人,使那个人以后都不能发言

如果一圈发言完还有1个以上的人能发言,就从1重新开始,直到只有1个人能发言,那个人所在的团队获胜

题目描述

There are nnn employees in Alternative Cake Manufacturing (ACM).

They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.

Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote.

The voting procedure is rather complicated:

  1. Each of nnn employees makes a statement.

They make statements one by one starting from employees 111 and finishing with employee nnn .

If at the moment when it’s time for the iii -th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).

  1. When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote.

It’s allowed to deny from voting people who already made the statement or people who are only waiting to do so.

If someone is denied from voting he no longer participates in the voting till the very end.

  1. When all employees are done with their statements, the procedure repeats: again, each employees starting from 111 and finishing with nnn who are still eligible to vote make their statements.
  2. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting.

Of course, he votes for the decision suitable for his fraction.

You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction).

Predict the outcome of the vote.

输入格式

The first line of the input contains a single integer nnn ( 1<=n<=2000001<=n<=2000001<=n<=200000 ) — the number of employees.

The next line contains nnn characters.

The iii -th character is ‘D’ if the iii -th employee is from depublicans fraction or ‘R’ if he is from remocrats.

输出格式

Print ‘D’ if the outcome of the vote will be suitable for depublicans and ‘R’ if remocrats will win.

样例 #1

样例输入 #1

5
DDRRR

样例输出 #1

D

样例 #2

样例输入 #2

6
DDRRRR

样例输出 #2

R

提示

Consider one of the voting scenarios for the first sample:

  1. Employee 111 denies employee 555 to vote.
  2. Employee 222 denies employee 333 to vote.
  3. Employee 333 has no right to vote and skips his turn (he was denied by employee 222 ).
  4. Employee 444 denies employee 222 to vote.
  5. Employee 555 has no right to vote and skips his turn (he was denied by employee 111 ).
  6. Employee 111 denies employee 444 .
  7. Only employee 111 now has the right to vote so the voting ends with the victory of depublicans.
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
int n,sa,sb,pa,pb;
bool sign[N];
string s;
int main(){cin>>n;cin>>s;for(int i=0;i<n;i++){if(s[i]=='D') sa++;else sb++;}while(sa&&sb){for(int i=0;i<n;i++){if(sign[i]) continue;if(s[i]=='D'){if(pb){pb--;sa--;sign[i]=1;}else pa++;}else{if(pa){pa--;sb--;sign[i]=1;}else pb++;}if(!sa||!sb) break;}}if(sa==0) puts("R");else puts("D");return 0;
}

Did you mean…

题面翻译

都是小写字母。

给你一个字符串,如果它的子串同时满足
1、三个或以上个连着的辅音字母
2、这一段连着的辅音字母不是全部一样的
就认为它不合法

现在要求用最少的空格隔开这个字符串,使得它变成合法的。

题目描述

Beroffice text editor has a wide range of features that help working with text.

One of the features is an automatic search for typos and suggestions of how to fix them.

Beroffice works only with small English letters (i.e. with 26 letters from a to z).

Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word.

The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo.

Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.

For example:

  • the following words have typos: “hellno”, “hackcerrs” and “backtothefutttture”;
  • the following words don’t have typos: “helllllooooo”, “tobeornottobe” and “oooooo”.

When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.

Implement this feature of Beroffice editor.

Consider the following letters as the only vowels: ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’.

All the other letters are consonants in this problem.

输入格式

The only line contains a non-empty word consisting of small English letters.

The length of the word is between 111 and 300030003000 letters.

输出格式

Print the given word without any changes if there are no typos.

If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn’t have any typos.

If there are multiple solutions, print any of them.

样例 #1

样例输入 #1

hellno

样例输出 #1

hell no

样例 #2

样例输入 #2

abacaba

样例输出 #2

abacaba

样例 #3

样例输入 #3

asdfasdf

样例输出 #3

asd fasd f
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
typedef long long ll;
char ok[]={'a','e','i','o','u'};
char s[N];
int sign=0;
bool okok(char a){if(a == 'a'|| a == 'e'|| a == 'i'|| a == 'o'|| a == 'u') return 0;return 1;
}
int main(){cin>>s;int k=okok(s[0]);cout<<s[0];for(int i=1;i<strlen(s);i++){if(!okok(s[i])) sign=0;else{sign++;if(sign>=3&&!(s[i]==s[i-1]&&s[i]==s[i-2])){cout<<' ';sign=1;}}cout<<s[i];}return 0;
}

Which floor?

题面翻译

题意
在Polycarp住的一栋建筑里,每一层有一些相等数量的公寓。不幸的是,Polycarp不记得在一层上有多少公寓了,但是他记得那些公寓是从1开始编号的,编号从低层到高层。那意味着,最开始的几个公寓在第一层,之后的几个公寓在第二层,以此类推。Polycarp不记得建筑里公寓的总数量,所以你可以将这栋建筑看为无限高(即有无限层)。注意楼层是从1开始编号的。
Polycarp记得几个公寓分别在哪几层。保证这些信息不会自我矛盾。(还有句话)
给你这些信息,你可以求出有n个公寓的建筑的确切层数吗?
输入格式:
第一行包含两个整数n,m。(1<=n<=100,0<=m<=100)(1<=n<=100,0<=m<=100)(1<=n<=100,0<=m<=100) 。n是你重建的建筑的公寓数,而m是Polycarp记得的公寓数。
接下来的m行,每一行包含一对整数kik_{i}ki​ ,fif_{i}fi​ 。(1<=ki<=100,1<=fi<=100)(1<=k_{i}<=100,1<=f_{i}<=100)(1<=ki​<=100,1<=fi​<=100) ,表示公寓kik_{i}ki​ 在第fif_{i}fi​ 层。所有的kik_{i}ki​ 都是不同的。
输出格式:
如果能确定唯一的层数,输出有n个公寓的建筑的层数。
如果不能确定,输出-1。

题目描述

In a building where Polycarp lives there are equal number of flats on each floor.

Unfortunately, Polycarp don’t remember how many flats are on each floor, but he remembers that the flats are numbered from 111 from lower to upper floors.

That is, the first several flats are on the first floor, the next several flats are on the second and so on.

Polycarp don’t remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors).

Note that the floors are numbered from 111 .

Polycarp remembers on which floors several flats are located.

It is guaranteed that this information is not self-contradictory.

It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp’s memory have the floors Polycarp remembers.

Given this information, is it possible to restore the exact floor for flat nnn ?

输入格式

The first line contains two integers nnn and mmm ( 1<=n<=1001<=n<=1001<=n<=100 , 0<=m<=1000<=m<=1000<=m<=100 ), where nnn is the number of the flat you need to restore floor for, and mmm is the number of flats in Polycarp’s memory.

mmm lines follow, describing the Polycarp’s memory: each of these lines contains a pair of integers ki,fik_{i},f_{i}ki​,fi​ ( 1<=ki<=1001<=k_{i}<=1001<=ki​<=100 , 1<=fi<=1001<=f_{i}<=1001<=fi​<=100 ), which means that the flat kik_{i}ki​ is on the fif_{i}fi​ -th floor.

All values kik_{i}ki​ are distinct.

It is guaranteed that the given information is not self-contradictory.

输出格式

Print the number of the floor in which the nnn -th flat is located, if it is possible to determine it in a unique way.

Print -1 if it is not possible to uniquely restore this floor.

样例 #1

样例输入 #1

10 3
6 2
2 1
7 3

样例输出 #1

4

样例 #2

样例输入 #2

8 4
3 1
6 2
5 2
2 1

样例输出 #2

-1

提示

In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor.

Thus, the 10-th flat is on the 4-th floor.

In the second example there can be 3 or 4 flats on each floor, so we can’t restore the floor for the 8-th flat.

#include<bits/stdc++.h>
using namespace std;
int n,m,x[110],y[110],l=1,r=100;
int main(){cin>>n>>m;for(int i=1;i<=m;i++) cin>>x[i]>>y[i];for(int i=1;i<=m;i++){int sl=x[i]/y[i]+(x[i]%y[i]?1:0),sr=100;if(y[i]!=1) sr=(x[i]-1)/(y[i]-1);if(l<sl) l=sl;if(r>sr) r=sr;}if(n/l+(n%l?1:0)==n/r+(n%r?1:0)) cout<<n/l+(n%l?1:0);else cout<<"-1";return 0;
}

Curriculum Vitae

题面翻译

输入

第一行:n(≥1,≤100)
第二行:n个整数,要么是0,要么是1

任务

删除若干个数(0个也行),使得0不出现在1后面。

输出

最多剩下多少个数。

题目描述

Hideo Kojima has just quit his job at Konami.

Now he is going to find a new place to work.

Despite being such a well-known person, he still needs a CV to apply for a job.

During all his career Hideo has produced nnn games.

Some of them were successful, some were not.

Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers.

As a result there should be no unsuccessful game which comes right after successful one in his CV.

More formally, you are given an array s1,s2,...,sns_{1},s_{2},...,s_{n}s1​,s2​,...,sn​ of zeros and ones.

Zero corresponds to an unsuccessful game, one — to a successful one.

Games are given in order they were produced, and Hideo can’t swap these values.

He should remove some elements from this array in such a way that no zero comes right after one.

Besides that, Hideo still wants to mention as much games in his CV as possible.

Help this genius of a man determine the maximum number of games he can leave in his CV.

输入格式

The first line contains one integer number nnn ( 1<=n<=1001<=n<=1001<=n<=100 ).

The second line contains nnn space-separated integer numbers s1,s2,...,sns_{1},s_{2},...,s_{n}s1​,s2​,...,sn​ ( 0<=si<=10<=s_{i}<=10<=si​<=1 ).

000 corresponds to an unsuccessful game, 111 — to a successful one.

输出格式

Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.

样例 #1

样例输入 #1

4
1 1 0 1

样例输出 #1

3

样例 #2

样例输入 #2

6
0 1 0 0 1 0

样例输出 #2

4

样例 #3

样例输入 #3

1
0

样例输出 #3

1
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
int n,x,y;
int a[N];
int main(){cin>>n;for(int i=1;i<=n;i++){scanf("%d",&a[i]);}x=0;for(int i=1;i<=n;i++){y=0;for(int j=i+1;j<=n;j++){if(!a[j]) ++y;}for(int j=1;j<i;j++){if(a[j]) ++y;}if(n-y>x) x=n-y;}cout<<x<<endl;return 0;
}

Okabe and Boxes

题面翻译

开始时,小明有1到n总共n个数。现在,他要执行n次将数字入栈和n次将数字出栈的操作。出栈时,他希望按照1、2、3、…n的顺序出栈。

所以,在遇到无法完成时,他就会先用魔法把目前栈里所有的数按上小下大的顺序排列,然后再执行操作。问小明在过程中最少执行几次魔法。

操作分为两种,每次的格式如下:

add x:将x这个数入栈;

remove:将栈顶数字出栈。

题目描述

Okabe and Super Hacker Daru are stacking and removing boxes.

There are nnn boxes numbered from 111 to nnn .

Initially there are no boxes on the stack.

Okabe, being a control freak, gives Daru 2n2n2n commands: nnn of which are to add a box to the top of the stack, and nnn of which are to remove a box from the top of the stack and throw it in the trash.

Okabe wants Daru to throw away the boxes in the order from 111 to nnn .

Of course, this means that it might be impossible for Daru to perform some of Okabe’s remove commands, because the required box is not on the top of the stack.

That’s why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants.

He can do it at any point of time between Okabe’s commands, but he can’t add or remove boxes while he does it.

Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe’s commands.

It is guaranteed that every box is added before it is required to be removed.

输入格式

The first line of input contains the integer nnn ( 1<=n<=3⋅1051<=n<=3·10^{5}1<=n<=3⋅105 ) — the number of boxes.

Each of the next 2n2n2n lines of input starts with a string “add” or “remove”.

If the line starts with the “add”, an integer xxx ( 1<=x<=n1<=x<=n1<=x<=n ) follows, indicating that Daru should add the box with number xxx to the top of the stack.

It is guaranteed that exactly nnn lines contain “add” operations, all the boxes added are distinct, and nnn lines contain “remove” operations.

It is also guaranteed that a box is always added before it is required to be removed.

输出格式

Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe’s commands.

样例 #1

样例输入 #1

3
add 1
remove
add 2
add 3
remove
remove

样例输出 #1

1

样例 #2

样例输入 #2

7
add 3
add 2
add 1
remove
add 4
remove
remove
remove
add 6
add 7
add 5
remove
remove
remove

样例输出 #2

2

提示

In the first sample, Daru should reorder the boxes after adding box 333 to the stack.

In the second sample, Daru should reorder the boxes after adding box 444 and box 777 to the stack.

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
typedef long long ll;
int n,k,a[N],l=0,endend,shu=1;
char s[N];
int main(){cin>>n;for(int i=1;i<=2*n;i++){scanf("%s",s);if(s[0]=='a'){scanf("%d",&k);a[++l]=k;}else{if(a[l]!=0){if(shu!=a[l]){l=0;endend++;}else l--;}shu++;}}cout<<endend<<endl;return 0;
}

codeforces每日5题(均1500)-第十七天相关推荐

  1. codeforces每日5题(均1500)-第十三天

    Case of Matryoshkas 题面翻译 这是一套有n个娃娃的套娃,由1到n依次编号.编号小的娃娃可以放进编号大的娃娃里面,但是不能平行的放入两个娃娃,即套娃在嵌套放置的时候只能一个套一个例如 ...

  2. codeforces每日5题(均1500)-第八天

    Cola 题面翻译 有a瓶0.5升,b瓶1升,c瓶2升的可乐,求买n升可乐的方案数 输入 nnn , aaa , bbb , ccc ( 1<=n<=100001<=n<=10 ...

  3. codeforces每日5题(均1500)-第二十一天

    Walking Robot 题面翻译 Description 在一个数轴上,有一个机器人要从 x=0x = 0x=0 处移动到 x=nx = nx=n 处.机器人身上有两种电池,第一种是普通电池,第二 ...

  4. codeforces每日5题(均1700)-第七天

    Multicolored Cars 题面翻译 [题目描述] 定义cntx(i)cnt_{x}(i)cntx​(i)表示到iii时刻xxx出现过的个数. 现在给出nnn个数a1,a2--ana_{1}, ...

  5. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

  6. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

  7. Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #694 (Div. 1 + Div2)(A ~ ...

  8. 运维面试题(每日一题)

    每日一题 第一周 1.添加路由 2.如何防止Linux命令行或脚本里MySQL登录密码泄露? 3.将前端运行的服务或脚本,如何可以放置到后端进行执行 4.linux网络配置中如何给一块网卡添加多个IP ...

  9. 2022-04-27每日刷题打卡

    2022-04-27每日刷题打卡 代码源--每日一题 素数之欢 - 题目 - Daimayuan Online Judge 现给定两个 四位素数 a,b. 你可以执行多次下面的操作: 修改数字 a 的 ...

  10. 每日一题(进制转换)

    前言:为了让小伙伴更方便的学习编程语言,小白每天都会分享一道编程题.小白也创建了一个微信公众号,会同步更新题目和相关的视觉领域的知识,如果小伙伴不方便在网页上阅读文章,可以关注微信公众号"小 ...

最新文章

  1. sqlite 使用 cte 及 递归的实现示例
  2. java基础(八) 深入解析常量池与装拆箱机制
  3. ccf-csp #201909-2 小明种苹果(续)
  4. 函数计算自动化运维实战 3 -- 事件触发自动创建快照
  5. 2021-03-07 Nussbaum函数
  6. 最简单的 SAP Cloud Application programming CDS 练习
  7. 《The Pomodoro Technique》
  8. Git之diff和status
  9. 学计算机的专属表白方式,九个学科专属表白句子-花式表白公式【蜜匠婚礼】...
  10. 润乾报表统计图联动刷新
  11. 使用pyecharts绘制图表
  12. 小微风控之财务评分模型的制定与应用
  13. PR(Premiere) 鼓点节拍插件Beat Edit,打不开的原因
  14. 一个周末掌握IT前沿技术之node.js篇一:Node.js与javascript
  15. yum设置 ccproxy 细节
  16. 华为watchgt2更新鸿蒙,华为 WATCH GT 2 Pro 发布:陶瓷背壳、支持血氧检测、新的鸿蒙应用等...
  17. java开发爱恩斯坦棋,爱恩斯坦棋计算机博弈系统的研究与实现
  18. 关于Navicat到期的办法(亲测有效)
  19. Python实现简易音频播放器
  20. 不要高估你和任何一个人的关系

热门文章

  1. 监控Linux磁盘情况,进行邮件告警
  2. 人体究竟需要多少蛋白质?摄入过量就是浪费钱
  3. 年货:Python技术知识清单(数据分析)
  4. 对Java语言入门初学者的一些建议
  5. Win11打开本地组策略编辑器的两种方法
  6. HTML无法显示下一页,为何我的浏览器不能直接打开下一页
  7. 中考计算机上机考试如何操作,全国2021年初中信息技术中招考试上机考试提分技巧...
  8. 求原谅---好久没更新了
  9. 【云主机迁移原理】华为云主机迁移服务SMS的原理分析
  10. 一文看懂人工智能产业链,未来10年2000亿美元市场