AtCoder Grand Contest 006

A - Prefix and Suffix

Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement

Snuke is interested in strings that satisfy the following conditions:

The length of the string is at least N.
The first N characters equal to the string s.
The last N characters equal to the string t.
Find the length of the shortest string that satisfies the conditions.

Constraints

1≤N≤100
The lengths of s and t are both N.
s and t consist of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
s
t

Output

Print the length of the shortest string that satisfies the conditions.

Sample Input 1

3
abc
cde

Sample Output 1

5
The shortest string is abcde.

Sample Input 2

1
a
z

Sample Output 2

2
The shortest string is az.

Sample Input 3

4
expr
expr

Sample Output 3

4



N才100,于是N^2暴力模拟吧
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<map>

#define For(i,a,b) for(int i=a;i<=b;i++)
#define ForD(i,a,b) for (int i=a;i>=b;i--)
#define LL long long
#define INF (2147483647)
#define sqr(x)  ((x)*(x))

using namespace std;

inline int read(){
    int data=0,w=1; char ch=0;
    while (ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if (ch=='-') w=-1,ch=getchar();
    while  (ch>='0' && ch<='9') data=data*10+ch-'0',ch=getchar();
    return data*w;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
} 

char s1[200],s2[200];
int t;

int main(){ 
    int n=read();
    scanf("%s",s1+1);
    scanf("%s",s2+1);
    
    For(i,1,n+1){
        bool t=true;
        For(j,i,n)
            if (s1[j]!=s2[j-i+1]){
                t=false;break;
            }
        if (t){
            write((i-1)*2+(n-i+1)),puts("");
            break;
        }
    }   
    
} 








B - Median Pyramid Easy

Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement

We have a pyramid with N steps, built with blocks. The steps are numbered 1 through N from top to bottom. For each 1≤i≤N, step i consists of 2i−1 blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically.

40a8e17bc2e7abbb.png

A pyramid with N=4 steps

Snuke wrote a permutation of (1, 2, …, 2N−1) into the blocks of step N. Then, he wrote integers into all remaining blocks, under the following rule:

The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

f50d2e4b1078887a.png
Writing integers into the blocks

Afterwards, he erased all integers written into the blocks. Now, he only remembers that the integer written into the block of step 1 was x.

Construct a permutation of (1, 2, …, 2N−1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.

Constraints

2≤N≤10^5
1≤x≤2N−1

Input

The input is given from Standard Input in the following format:

N x

Output

If no permutation of (1, 2, …, 2N−1) could have been written into the blocks of step N, print No.

Otherwise, print Yes in the first line, then print 2N−1 lines in addition.

The i-th of these 2N−1 lines should contain the i-th element of a possible permutation.

Sample Input 1

4 4

Sample Output 1

Yes
1
6
3
7
4
5
2
This case corresponds to the figure in the problem statement.

Sample Input 2

2 1

Sample Output 2

No
No matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.



首先来想想什么情况是不可能的?

x=1||x=2n-1时

那么其他情况呢?
02df24a29ddb3643.jpg
当我们要获得x时,只需要下一层的两个数为x,那就这需要下下一层的两个数为x…………
所以我们最后只要构造第n层的4个数就可以了啊(脑洞大开啊)
我想,知道怎么构造还WA一发的也就我了吧

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<map>

#define For(i,a,b) for(int i=a;i<=b;i++)
#define ForD(i,a,b) for (int i=a;i>=b;i--)
#define LL long long
#define INF (2147483647)
#define sqr(x)  ((x)*(x))

using namespace std;

inline int read(){
    int data=0,w=1; char ch=0;
    while (ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if (ch=='-') w=-1,ch=getchar();
    while  (ch>='0' && ch<='9') data=data*10+ch-'0',ch=getchar();
    return data*w;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
} 


int a[1000000],f[1000000];
int main(){ 
    int n=read(),x=read();
    if (x==1||x==2*n-1) {
        puts("No");return 0;
    }
    if (n==2){
        puts("Yes");
        For(i,1,3)
            write(i),puts("");
        return 0;
    }
    memset(f,true,sizeof(f));
    if (x>2){
        f[1]=false,f[2]=false,f[x+1]=false,f[x]=false;
        a[n-1]=1,a[n]=x,a[n+1]=x+1,a[n+2]=2;
        int t=1;
        For(i,1,2*n-1){
            if (a[i]!=0)    continue;
            while(!f[t])
                t++;
            a[i]=t;t++;
        }
    }
    else{
        f[1]=false,f[2]=false,f[3]=false,f[4]=false;
        a[n-1]=3,a[n]=2,a[n+1]=1,a[n+2]=4;
        int t=1;
        For(i,1,2*n-1){
            if (a[i]!=0)    continue;
            while(!f[t])
                t++;
            a[i]=t;t++;
        }
    }
    puts("Yes");
    For(i,1,2*n-1)
        write(a[i]),puts("");
} 

后面的几题填坑中 不过我想我也做不出来了吧

转载于:https://www.cnblogs.com/Kenelm/p/6727534.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值