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 给出一个字符串,现在可以对这个字符串进 ...
随机推荐
- NullPointerException检测
APET-NPE插件工作原理 android应用程序编译的过程如下: 从图中,我们可以看出,app编译大致经历了四大阶段:java source files -> .class files -& ...
- sudo的用法
为了系统安全我们一般不直接使用root用户进行日常维护,sudo是临时提升root权限,有时执行一些命令或者更新没权限的文件时需要使用root,这个时候就需要sudo上场了 普通用户是没有sudo使用 ...
- 51nod 1431 快乐排队
题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 有一群人在排队,如果某个人想排到前面去,可以花一元钱给直接站在他前 ...
- 中国各运营商(电信、联通、移动、铁通)IP地址段
除此电信.联通.移动.铁通之外还有教育网.科技网.广电.长城.广电…… 表格下载: http://files.cnblogs.com/files/xiaohi/中国IP网段.zip 以上资料参考: h ...
- 在CesiumVR基础上实现3D左右立体视觉
整体思路 在VR模块的基础上调整视差,使其随距离发生变化: 左右分屏时,需要将左右屏的横向进行1/2压缩:这是因为3D-TV在对左右格式影像进行合并时,会进行拉伸: 左屏幕的相机相对于原来的(右屏)相 ...
- Unity3D中使用Projector生成阴影
在Unity3D中使用Projector实现动态阴影 无意中看见一篇博客叙述使用Projector实现动态阴影可以在移动平台拥有非常好的性能,遂按照其想法实现了一遍,发现其中竟有许多细节,写下这篇博客 ...
- 7.Props向子组件传递数据
组件实例的作用域是孤立的.这意味着不能并且不应该在子组件的模板内直接引用父组件的数据. 可以使用 props 把数据传给子组件. for-child-msg="aaa" , fo ...
- Java中如果把构造方法也私有化,如何创建对象?Java的单例设计模式——饿汉式和懒汉式区别
Java的单例模式——饿汉式 package com.swift; //Java单例设计模式——恶汉式 public class SinglePerson { private String name= ...
- .NET 中,编译器直接支持的数据类型称为基元类型(primitive type).基元类型和.NET框架类型(FCL)中的类型有直接的映射关系.
.NET 中,编译器直接支持的数据类型称为基元类型(primitive type).基元类型和.NET框架类型(FCL)中的类型有直接的映射关系. The primitive types are Bo ...
- 【MySql】Mysql ERROR 1067: Invalid default value for ‘date’ 解决
在给一个表添加字段的时候,忽然发现会报一个date类型的字段的默认值错误,郁闷~ 经过排查,原来是MySQL的配置问题,在wamp下,MySQL 5.7里是没有设置 SQL_MODE 的. 1.my. ...