(AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
1 second
256 megabytes
standard input
standard output
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s1s2…sns=s1s2…sn Polycarp uses the following algorithm:
- he writes down s1s1,
- he appends the current word with s2s2 (i.e. writes down s2s2 to the right of the current result),
- he prepends the current word with s3s3 (i.e. writes down s3s3 to the left of the current result),
- he appends the current word with s4s4 (i.e. writes down s4s4 to the right of the current result),
- he prepends the current word with s5s5 (i.e. writes down s5s5 to the left of the current result),
- and so on for each position until the end of ss.
For example, if ss="techno" the process is: "t" →→ "te" →→ "cte" →→ "cteh" →→ "ncteh" →→ "ncteho". So the encrypted ss="techno" is "ncteho".
Given string tt — the result of encryption of some string ss. Your task is to decrypt it, i.e. find the string ss.
The only line of the input contains tt — the result of encryption of some string ss. It contains only lowercase Latin letters. The length of tt is between 11 and 5050, inclusive.
Print such string ss that after encryption it equals tt.
ncteho
techno
erfdcoeocs
codeforces
z
z
我好菜啊...脑袋都锈住了!
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring> using namespace std; int main(){
string str{""};
string out{""};
//memset(s,'\0',sizeof(s));
//memset(out,'\0',sizeof(out));
while(cin>>str){
int len=str.size();
out=str;
if(len== || len==){
cout<<str<<endl;
continue;
}
int tmp=;
int len_right=;
int len_left=;
if(len%==){
tmp=(len-)/;
}else{
tmp=len/-;
}
out[]=str[tmp];
out[]=str[tmp+];
for(int i=tmp+,j=;i<len;i++,j++,j++){
out[j]=str[i];
}
for(int i=tmp-,j=;i>=;i--,j++,j++){
out[j]=str[i];
}
cout<<out<<endl;
//memset(str,'\0',sizeof(str));
//memset(out,'\0',sizeof(out)); } return ;
}
1 second
256 megabytes
standard input
standard output
Vasya likes to solve equations. Today he wants to solve (x div k)⋅(xmodk)=n(x div k)⋅(xmodk)=n, where divdiv and modmod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, kk and nn are positive integer parameters, and xx is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible xx. Can you help him?
The first line contains two integers nn and kk (1≤n≤1061≤n≤106, 2≤k≤10002≤k≤1000).
Print a single integer xx — the smallest positive integer solution to (x div k)⋅(xmodk)=n(x div k)⋅(xmodk)=n. It is guaranteed that this equation has at least one positive integer solution.
6 3
11
1 2
3
4 6
10
The result of integer division a div ba div b is equal to the largest integer cc such that b⋅c≤ab⋅c≤a. aa modulo bb (shortened amodbamodb) is the only integer cc such that 0≤c<b0≤c<b, and a−ca−c is divisible by bb.
In the first sample, 11 div 3=311 div 3=3 and 11mod3=211mod3=2. Since 3⋅2=63⋅2=6, then x=11x=11 is a solution to (x div 3)⋅(xmod3)=6(x div 3)⋅(xmod3)=6. One can see that 1919 is the only other positive integer solution, hence 1111 is the smallest one.
思路:让找一个最小的x,使得(x/k)*(x%k)==n,如果对x暴力枚举肯定会超时啊,所以可以从x%k这里下手,x%k的值一定>=0 且<k,又因为n不可能为0,所以x%k是大于0的.所以在1~(k-1)之间枚举k.
再设x%k=i,上式可以变成(x-i)/k * i =n,所以x=n/i * k +i.
#include <bits/stdc++.h>
using namespace std;
using LL = long long; int main(){
LL n,k;
while(cin>>n>>k){
LL x(LONG_MAX);
for(LL i=;i<k;i++){
if(n%i!=) continue;
LL tmp=n/i*k+i;
x=(x<tmp?x:tmp);
}
cout<<x<<endl;
}
return ;
}
(AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round的更多相关文章
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path
http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)
https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】
任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)
题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano
题意:给出一个数列 a1 a2......an 让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i) 那么b( ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)
题意:给出一条直线 ax +by+c=0 给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...
随机推荐
- [再寄小读者之数学篇](2014-06-22 函数恒为零的一个充分条件 [中国科学技术大学2011年高等数学B考研试题])
设 $f(x)$ 在 $\bbR$ 上连续, 又 $$\bex \phi(x)=f(x)\int_0^x f(t)\rd t \eex$$ 单调递减. 证明: $f\equiv 0$. 证明: 设 $ ...
- ps常用指令集
M DCtrl+ D清空选择区域Ctrl+ R调出标尺
- Entity Framework查询
Entity Framework是个好东西,虽然没有Hibernate功能强大,但使用更简便.今天整理一下常见SQL如何用EF来表达,Func形式和Linq形式都会列出来(本人更喜欢Func形式). ...
- Rich feature hierarchies for accurate object detection and semantic segmentation(理解)
0 - 背景 该论文是2014年CVPR的经典论文,其提出的模型称为R-CNN(Regions with Convolutional Neural Network Features),曾经是物体检测领 ...
- Stm32型号查阅手册
- 不用写代码的框架 - RobotFramework+Eclispe环境安装篇
环境安装是学习任何一个新东西的第一步,这一步没走舒坦,那后面就没有心情走下去了. 引用名句:工欲善其事必先利其器!! Robotframework:一款 自动化测试框架. Eclipse:一款编辑工具 ...
- Stack的相关API
public class Stack<E> extends Vector<E> : Stack类代表后进先出(LIFO)堆栈的对象. 它扩展了类别Vector与五个操作,允许一 ...
- 使用工具intellij idea 进行java web开发简介
一.工具下载及安装准备 1.首先下载工具 Intellij idea ,下载地址:https://www.jetbrains.com/ 2.破解 百度下载一个 JetbrainsCrack-2.7- ...
- WebService - [Debug] javax.xml.ws.WebServiceException: Undefined port type
背景: 使用JDK来开发java web service (Create a SOAP-based RPC style web service endpoint by using JAX-WS). 具 ...
- SQL Server - AS
AS 是给现有的字段名/表名指定一个别名的意思.