GVKun编程网logo

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) C - Ordering Pizza

10

在这里,我们将给大家分享关于CodeforcesRound#437(Div.2,basedonMemSQLStart[c]UP3.0-Round2)C-OrderingPizza的知识,同时也会涉及到

在这里,我们将给大家分享关于Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) C - Ordering Pizza的知识,同时也会涉及到如何更有效地(AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round、Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers 爆搜+剪枝、Codeforces Round #114 (Div. 1) C Wizards and Numbers、Codeforces Round #412 (rated, Div. 1, based on VK Cup 2017 Round 3) D. Perishable Roads的内容。

本文目录一览:

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) C - Ordering Pizza

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) C - Ordering Pizza

总结

以上是小编为你收集整理的Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) C - Ordering Pizza全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

(AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

(AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

A. Right-Left Cipher
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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=s1s2sns=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" @H_797_301@→→ "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.

Input

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.

Output

Print such string ss that after encryption it equals tt.

Examples
input
ncteho
output
techno
input
erfdcoeocs
output
codeforces
input
z
output
z
我好菜啊...脑袋都锈住了!

分享图片

分享图片

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdlib>
 4 #include <cstring>
 5 
 6 using namespace std;
 7 
 8 int main(){
 9     string str{"0"};
10     string out{"0"};
11     //memset(s,‘\0‘,sizeof(s));
12     //memset(out,sizeof(out));
13     while(cin>>str){
14         int len=str.size();
15         out=str;
16         if(len==1 || len==2){
17             cout<<str<<endl;
18             continue;
19         }
20         int tmp=0;
21         int len_right=0;
22         int len_left=0;
23         if(len%2==1){
24             tmp=(len-1)/2;
25         }else{
26             tmp=len/2-1;
27         }
28         out[0]=str[tmp];
29         out[1]=str[tmp+1];
30         for(int i=tmp+2,j=3;i<len;i++,j++,j++){
31             out[j]=str[i];
32         }
33         for(int i=tmp-1,j=2;i>=0;i--,j++){
34             out[j]=str[i];
35         }
36         cout<<out<<endl;
37         //memset(str,sizeof(str));
38         //memset(out,sizeof(out));
39 
40 
41     }
42 
43 
44 
45 
46     return 0;
47 }
View Code
B. Div Times Mod
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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?

Input

The first line contains two integers nn and kk (1n1061≤n≤106, 2k10002≤k≤1000).

Output

Print a single integer xx — the smallest positive integer solution to (x div k)@H_797_301@?(xmodk)=n(x div k)?(xmodk)=n. It is guaranteed that this equation has at least one positive integer solution.

Examples
input
6 3
output
11
input
1 2
output
3
input
4 6
output
10
Note

The result of integer division a div ba div b is equal to the largest integer cc such that b?cab?c≤a. aa modulo bb (shortened amodbamodb) is the only integer cc such that 0c<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=1;i<k;i++){
            if(n%i!=0) continue;
            LL tmp=n/i*k+i;
            x=(x<tmp?x:tmp);
        }
        cout<<x<<endl;
    }    
    return 0;
}
View Code

Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers 爆搜+剪枝

Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers 爆搜+剪枝

总结

以上是小编为你收集整理的Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers 爆搜+剪枝全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

Codeforces Round #114 (Div. 1) C Wizards and Numbers

Codeforces Round #114 (Div. 1) C Wizards and Numbers

题目链接:Wizards and Numbers

题意:有两个数字a,b,假设 a>b,两个玩家进行游戏,有两种操作:1. 令 a=a-b^k,k为正数,且需要保证操作后 a 仍然非负;2. 令 a=a%b。最终有一个人无法操作(存在一个数为0)的时候便输了。

题解:如果只有操作2就是一个辗转相除法,实际上加上了操作1,执行的过程中也一定会出现辗转相除法种每轮的数字情况。所以以辗转相除法的每轮情况作为分段点,讨论其是必胜态还是必败态,首先(t,0) 一定是必败态,所以其上一层的状态一定是必胜态。主要考虑当前层为必胜态,那上一层的情况为什么,问题实际上可以转化为有 tx 堆石子,每次可以 x的幕次颗,谁最先取光谁就输了。打个表找找规律便可以了:若 x 为奇数,则结果与 t 的奇偶有关;若 x 为偶数,则会在 x^2 处作为分界点,规律发生了变化,但还是很显然的。

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

LL xx[105],yy[105],cnt;

LL gcd(LL x,LL y){
    int res=(y==0?x:gcd(y,x%y));
    xx[++cnt]=x;
    yy[cnt]=y;
    return res;
}

LL ans[105];
bool check(LL a,LL b){
    if(a%2==1){
        return (b/a-1)%2;
    }
    else{
        if(a>=1000000000||b<a*a){
            return !((b/a)%2);
        }
        else{
            LL res=b/a;
            LL c1=(res%(a+1))%2;
            LL c2=res%(a+1);
            return !c1||(c2==a);
        }
    }
}
void solve(LL a,LL b){
    cnt=0;
    gcd(a,b);
    ans[1]=0;
    for(int i=2;i<=cnt;i++){
        if(ans[i-1]==0) ans[i]=1;
        else if(check(yy[i],xx[i]-yy[i-1])) ans[i]=1;
        else ans[i]=0;
    }
    if(ans[cnt]) printf("First\n");
    else printf("Second\n");
}

int p=12;
int biao[100005];
int dabiao(int x){
    if(biao[x]!=-1) return biao[x];
    if(x<0) return 0;
    int temp=p;
    int flag=0;
    while(temp<=x*p){
        if(dabiao(x-temp/p)==0){
            flag=1; break;
        }
        temp*=p;
    }
    return biao[x]=flag;
}

int main(){
    /*******
    memset(biao,-1,sizeof(biao));
    biao[0]=1;
    dabiao(100);
    for(int i=1;i<=100;i++){
        cout<<i<<" "<<biao[i]<<endl;
    }
    *******/
    int n;
    cin>>n;
    while(n--){
        LL a,b;
        cin>>a>>b;
        if(a<b) swap(a,b);
        if(b==0) cout<<"Second"<<endl;
        else if(a%b==0) cout<<"First"<<endl;
        else solve(a,b);
    }

    return 0;
}

Codeforces Round #412 (rated, Div. 1, based on VK Cup 2017 Round 3) D. Perishable Roads

Codeforces Round #412 (rated, Div. 1, based on VK Cup 2017 Round 3) D. Perishable Roads

总结

以上是小编为你收集整理的Codeforces Round #412 (rated, Div. 1, based on VK Cup 2017 Round 3) D. Perishable Roads全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

关于Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) C - Ordering Pizza的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于(AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round、Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers 爆搜+剪枝、Codeforces Round #114 (Div. 1) C Wizards and Numbers、Codeforces Round #412 (rated, Div. 1, based on VK Cup 2017 Round 3) D. Perishable Roads的相关信息,请在本站寻找。

本文标签: