Educational Codeforces Round 38 (Rated for Div. 2)
这场打了小号
1 second
256 megabytes
standard input
standard output
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word s. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
The first line contains one integer n (1 ≤ n ≤ 100) — the number of letters in word s before the correction.
The second line contains a string s consisting of exactly n lowercase Latin letters — the word before the correction.
Output the word s after the correction.
5
weird
werd
4
word
word
5
aaeaa
a
Explanations of the examples:
- There is only one replace: weird
werd; - No replace needed since there are no two consecutive vowels;
- aaeaa
aeaa
aaa
aa
a.
连续的两个原因字母或y就保留第一个字母
#include<bits/stdc++.h>
using namespace std;
const int N=;
int main()
{
ios::sync_with_stdio(false);
string s,t;
int n;
cin>>n>>s;
set<char>S;
S.insert('a'),S.insert('e'),S.insert('i'),S.insert('o'),S.insert('u'),S.insert('y');
while(true)
{
int f=;
for(int i=;s[i]&&f;i++)
{
if(S.count(s[i-])&&S.count(s[i]))
{
f=;
t=s.substr(,i)+s.substr(i+);
}
}
if(f)break;
s=t;
}
cout<<s;
return ;
}
1 second
256 megabytes
standard input
standard output
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position x to position x + 1 or x - 1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of prizes.
The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 106 - 1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
3
2 3 9
8
2
2 999995
5
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
有n个东西,你可以把x位置的移到x+1或x-1,你在位置1你的朋友在位置1e6
其实就是求一下到两点距离的最小距离中的最大距离
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n,ans=;
cin>>n;
for(int i=,x;i<n;i++)
cin>>x,ans=max(ans,min(x-,-x));
cout<<ans;
return ;
}
1 second
256 megabytes
standard input
standard output
Let's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero.
Consider the following problem:
You are given two integers n and m. You have to construct an m-free square matrix of size n × n such that the number of 1's in this matrix is maximum possible. Print the maximum possible number of 1's in such matrix.
You don't have to solve this problem. Instead, you have to construct a few tests for it.
You will be given t numbers x1, x2, ..., xt. For every
, find two integers ni and mi (ni ≥ mi) such that the answer for the aforementioned problem is exactly xi if we set n = ni and m = mi.
The first line contains one integer t (1 ≤ t ≤ 100) — the number of tests you have to construct.
Then t lines follow, i-th line containing one integer xi (0 ≤ xi ≤ 109).
Note that in hacks you have to set t = 1.
For each test you have to construct, output two positive numbers ni and mi (1 ≤ mi ≤ ni ≤ 109) such that the maximum number of 1's in a mi-free ni × ni matrix is exactly xi. If there are multiple solutions, you may output any of them; and if this is impossible to construct a test, output a single integer - 1.
3
21
0
1
5 2
1 1
-1
这个题目其实并不难,硬生生让我搞成了难题
是一个m*m的01的矩阵,其中n*n的矩阵中至少有一个为1,最后剩下的大小为x
所以就是一个公式,并不用猜
总大小m*m,少的个数(m/n)^2,即m*m-(m/n)^2=x
枚举m就行了,求m/n
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{ scanf("%d",&x);
f=;
for (i=; i<4e4; i++)
if ((a=i*i-x)>)
if ((b=sqrt(a))*b==a)
if (i/b>i/(b+))
{
printf("%d %d\n",i,i/b);
f=;
break;
}
if (!f) puts("-1");
}
}
2 seconds
256 megabytes
standard input
standard output
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are n cities in Berland. People can travel between cities using two-directional train routes; there are exactly m routes, i-th route can be used to go from city vi to city ui (and from ui to vi), and it costs wi coins to use this route.
Each city will be visited by "Flayer", and the cost of the concert ticket in i-th city is ai coins.
You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city i you have to compute the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).
Formally, for every
you have to calculate
, where d(i, j) is the minimum number of coins you have to spend to travel from city i to city j. If there is no way to reach city j from city i, then we consider d(i, j) to be infinitely large.
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·105).
Then m lines follow, i-th contains three integers vi, ui and wi (1 ≤ vi, ui ≤ n, vi ≠ ui, 1 ≤ wi ≤ 1012) denoting i-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (v, u) neither extra (v, u) nor (u, v) present in input.
The next line contains n integers a1, a2, ... ak (1 ≤ ai ≤ 1012) — price to attend the concert in i-th city.
Print n integers. i-th of them must be equal to the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).
4 2
1 2 4
2 3 7
6 20 1 25
6 14 1 25
3 3
1 2 1
2 3 1
1 3 1
30 10 20
12 10 12
这个D其实是一个图论题,关键在于建图。spfa会被卡的
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=2e5+;
priority_queue<pll>pq;
vector<pll>G[N];
ll dp[N],n,m,a,b,x;
int main()
{
cin>>n>>m;
for(int i=; i<m; i++)
cin>>a>>b>>x,G[a].push_back(pll(b,*x)),G[b].push_back(pll(a,*x));
for(int i=; i<=n; i++)cin>>dp[i],pq.push(pll(-dp[i],i));
while(!pq.empty())
{
ll u=pq.top().second,val=-pq.top().first;
pq.pop();
if(val!=dp[u])continue;
for(auto X:G[u])
{
ll v=X.first,w=X.second;
if(dp[v]>dp[u]+w)dp[v]=dp[u]+w,pq.push(pll(-dp[v],v));
}
}
for(int i=; i<=n; i++)cout<<dp[i]<<" ";
return ;
}
Educational Codeforces Round 38 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 38 (Rated for Div. 2) C
C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
随机推荐
- epoll使用总结
epoll的使用总结 使用epoll来实现一个tcp server,中间碰到了不少使用细节上的问题,总结一下. man epoll里推荐的使用方法 epoll使用代码 #define MAX_EVEN ...
- ApexSQL Log中的Redo Script跟原始SQL不一致问题
最近遇到一个误更新数据的问题,使用ApexSQL Log做挖掘事务日志的时候,发现ApexSQL Log生成的Redo Script跟原始SQL是有区别的.它们并不是完全一致的.只是逻辑上等价而已.如 ...
- Android商城开发系列(三)——使用Fragment+RadioButton实现商城底部导航栏
在商城第一篇的开篇当中,我们看到商城的效果图里面有一个底部导航栏效果,如下图所示: 今天我们就来实现商城底部导航栏,最终效果图如下所示: 那么这种效果是如何实现,实现的方式有很多种,最常见的就是使 ...
- Vue风格指南总结及对应ESLint规则配置
全手打原创,转载请标明出处:https://www.cnblogs.com/dreamsqin/p/10906951.html,多谢,=.=~ 必要的:规避错误: 强烈推荐:改善可读性和开发体验: 推 ...
- 使用ErrorProvider组件验证文本框输入
实现效果: 知识运用: ErrorProvider组件的BlinkStyle属性 //指示错误图标的闪烁时间 public ErrorBlinkStyle BlinkStyle{ get;set; } ...
- Python 继承实现的原理(继承顺序)
继承顺序 Python3 : 新式类的查找顺序:广度优先 新式类的继承: class A(object): Python2 3 都是了 MRO算法--生成一个列表保存继承顺序表 不找到底部 Pytho ...
- 《毛毛虫团队》第九次团队作业:BETA冲刺与团队项目验收
一:实验名称:Beta冲刺与验收准备 二:实验目的与要求 (1)掌握软件黑盒测试技术: (2)学会编制软件项目总结PPT.项目验收报告: (3)掌握软件项目验收内容,验收流程. 三.实验内容与步骤 任 ...
- 小试牛刀,建立jsp网页与导出war包
一.建立jsp网页 首先创建一个动态项目(我们学习的是动态网) 二.检查编码utf-8有没错误. 如有错误就是没有设置eclipse,请按照eclipse设置 编写一段代码,进行了解 三.导出一个wa ...
- spring boot自动配置实现
自从用了spring boot,都忘记spring mvc中的xml配置是个什么东西了,再也回不去.为啥spring boot这么好用呢, 约定大于配置的设计初衷, 让我们只知道维护好applicat ...
- 在物理机上,用U盘安装esxi虚拟化环境
一般使用U盘安装centos镜像,可使用镜像刻录工具UltraISO,详细方法参照如下链接: https://jingyan.baidu.com/article/647f0115ee55ba7f214 ...