(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坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...
 
随机推荐
- [物理学与PDEs]第2章习题12 严格凸性的转换
			
设 $L=L(\xi_0,\xi_1,\cdots,\xi_n)$ 关于变量 $\xi_0>0,\xi_1,\cdots,\xi_n$ 为严格凸的. 证明函数 $$\bex M=\cfrac{1 ...
 - java8 list转map
			
//按id属性为map的key值 Map<Integer, User> userMap = list.stream().collect(Collectors.toMap(User::get ...
 - 迅为iTOP-4418/6818开发板-驱动-实现GPIO扩展
			
实现 GPIO 扩展,先弄清楚“复用”的概念,将调用这些 GPIO 的驱动去掉配置,重新编译,加到自己的驱动中,就可以实现扩展的 GPIO 的输入和输出.另外必须要先看文档“迅为iTOP-4418开发 ...
 - centos禁止与开启ping设置
			
禁止ping: echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all 允许ping: echo 0 > /proc/sys/net/ipv4/i ...
 - SQL Server2016安装
			
VS2017已经发布10多天了,这几天正好要重新做系统.所以想着把SQL Server和VS都做一次升级.VS2017只需要下载一个安装包就可以进行在线安装.但是SQL Server2016安装时会碰 ...
 - 【原创】运维基础之Docker(4)实用工具ctop
			
ctop类似于top,top监控的是进程,ctop监控的是容器(container top) 安装 # wget https://github.com/bcicen/ctop/releases/dow ...
 - js 禁止f12、Ctrl +S 、右键
			
<script language=javascript> window.onload=function(){ document.onkeydown=function(){ ]; ){ re ...
 - wifi的主动扫描和被动扫描
			
要实现wifi上的探针模块,简单了了解了802.11中的各种帧,对一些帧的发送频率和方式也有简单了解.不过了解的都不够细致.只是简单知道手机打开wifi后回不停的向外发送probe request这个 ...
 - java 根据Url下载对应的文件到指定位置,读txt文件获取url
			
package test; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im ...
 - 使用Selenium+ChromeDriver登录微博并且获取cookie
			
using OpenQA.Selenium;using OpenQA.Selenium.Chrome; public class GetSinaCookie { private static stri ...