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 给出一个字符串,现在可以对这个字符串进 ...
随机推荐
- 通过Jenkins调用自动部署war包及jar包到服务器上的Shell脚本
1)部署war包#!/bin/bashif [ id>0];then echo"stopproject" kill −9 idelse echo "project ...
- Java 继承与重写
1.类的继承 1)继承 父类:所有子类所共有的属性和行为 子类:子类所特有的属性和行为 通过extends关键字来实现类的继承 子类(Sub class)可以继承父类(Super class)的成员变 ...
- UVA 1149 Bin Packing 装箱(贪心)
每次选最大的物品和最小的物品放一起,如果放不下,大物体孤独终生,否则相伴而行... 答案变得更优是因为两个物品一起放了,最大的物品是最难匹配的,如果和最小的都放不下的话,和其它匹配也一定放不下了. # ...
- css设置禁止文字被选中
// 禁止文字被鼠标选中 moz-user-select: -moz-none; -moz-user-select: none; -o-user-select:none; -khtml-user-se ...
- python之生成器的初识
1. 生成器的定义 生成器的本质就是迭代器.python社区生成器和迭代器是一种 2. 生成器和迭代器区别 迭代器: 都是Python给你提供的已经写好的工具或者通过数据转化得来的 生成器: ...
- MySql数据库中where的使用
SELECT * from runoob_tbl WHERE runoob_author='菜鸟教程'; MySQL 的 WHERE 子句的字符串比较是不区分大小写的. 你可以使用 BINARY 关键 ...
- c#和Java中的继承
c#和Java: 1.首先,子类继承了父类的属性和方法,但是子类并没有继承父类的私有字段. 2.子类并没有继承父类的构造函数,但是.子类会默认的调用父类无参数的构造函数,创建父类对象,让子类可以使用父 ...
- Linux连接外网
1.给linux配置ip 进行远程管理 如果网络不同的话需要配置网卡,命令如下: vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 回车 就出现网络的环 ...
- 协议(Protocol)与委托代理(Delegate)
协议(Protocol)的作用: 1. 规范接口,用来定义一套公用的接口: 2. 约束或筛选对象. 代理(Delegate): 它本身是一种设计模式,委托一个对象<遵守协议>去做某件事情, ...
- java 会话跟踪技术
1.session用来表示用户会话,session对象在服务端维护,一般tomcat设定session生命周期为30分钟,超时将失效,也可以主动设置无效: 2.cookie存放在客户端,可以分为内存c ...