Atcoder CODE FESTIVAL 2017 qual C 总结+ABCD题解

    这场比赛..打得还不错..最后两题我想不出..不过还好过了的人也不怎么多。所以我以65分钟过了4题的成绩排在了rank167.(顺带Orz orbitingflea)最终加了42,rating:2026(终于黄名了qwq)..朝着下一个目标进发!
    以下是题解(ABCD)
=================我是萌萌哒分割线OvO=================

A - Can you get AC?

Problem Statement

    Snuke built an online judge to hold a programming contest.
    When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.)
    Determine whether the judge can return the string “AC” as the verdict to a program.

Constraints

    2≤|S|≤5
    S consists of uppercase English letters.

Input

    Input is given from Standard Input in the following format:
        S

Output

    If the judge can return the string “AC” as a verdict to a program, print “Yes”; if it cannot, print “No”.

Examples

Example 1
    Input
        BACD
    Output
        Yes
    The string “AC” appears in “BACD” as a contiguous substring (the second and third characters).
Example 2
    Input
        ABCD
    Output
        No
    Although the string “ABCD” contains both “A” and “C” (the first and third characters), the string “AC” does not appear in “ABCD” as a contiguous substring.
Example 3
    Input
        CABD
    Output
        No
Example 4
    Input
        ACACA
    Output
        Yes
Example 5
    Input
        XX
    Output
        No

题意

    给你一个字符串,问你串中是否包含子串“AC”。

思路

    大水题,扫过去判一下就好了..

Code

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>
inline void read(T &x) {
    Finish_read=0;x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;Finish_read=1;
}
template<class T>
inline void print(T x) {
    if(x/10!=0)
        print(x/10);
    putchar(x%10+'0');
}
template<class T>
inline void writeln(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
    putchar('\n');
}
template<class T>
inline void write(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
}
/*================Header Template==============*/
string s;
int main() {
    cin>>s;
    for(int i=0;i<s.length()-1;i++)
        if(s[i]=='A'&&s[i+1]=='C') {
            puts("Yes");
            return 0;
        }
    puts("No");
    return 0;
}

B - Similar Arrays

Problem Statement

    We will say that two integer sequences of length N, x1 , x2 ,…, xN and y1 , y2 ,…, yN , are similar when | xi yi |≤1 holds for all i (1≤i≤N).
    In particular, any integer sequence is similar to itself.
    You are given an integer N and an integer sequence of length N, A1 , A2 ,…, AN .
    How many integer sequences b1 , b2 ,…, bN are there such that b1 , b2 ,…, bN is similar to A and the product of all elements, b1 b2 bN , is even?

Constraints

    1≤N≤10
    1≤ Ai ≤100

Input

    Input is given from Standard Input in the following format:

N
A1 A2 AN

Output

    Print the number of integer sequences that satisfy the condition.

Examples

Example 1
    Input
        2
        2 3
    Output
        7
    There are seven integer sequences that satisfy the condition:

1,2
1,4
2,2
2,3
2,4
3,2
3,4

Example 2
    Input
        3
        3 3 3
    Output
        26
Example 3
    Input
        1
        100
    Output
        1
Example 4
    Input
        10
        90 52 56 71 44 8 13 30 57 84
    Output
        58921

题意

    给你一个长度为n的数组,然后让你求与他相似的数组的个数,定义相似为两个数组长度相等且每一位的差的绝对值不超过1,并且数组所有数的乘积不是奇数

思路

    其实这题有O(n)做法,只是我看范围也不大,我就写了个DFS..没想到竟然没有T还只用了2ms..233333.对于DFS的话就是每一位扫3个数推下去就行了

Code

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>
inline void read(T &x) {
    Finish_read=0;x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;Finish_read=1;
}
template<class T>
inline void print(T x) {
    if(x/10!=0)
        print(x/10);
    putchar(x%10+'0');
}
template<class T>
inline void writeln(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
    putchar('\n');
}
template<class T>
inline void write(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
}
/*================Header Template==============*/
int arr[15],a[15],n,ans=0;
ll sum=1;
inline void dfs(int pos) {
    if(pos==n+1) {
        sum=1;
        for(int i=1;i<=n;i++)
            sum*=a[i];
        if(sum%2==0)
            ans++;
        return;
    }
    for(int i=arr[pos]-1;i<=arr[pos]+1;i++) {
        a[pos]=i;
        dfs(pos+1);
    }
}
int main() {
    read(n);
    for(int i=1;i<=n;i++)
        read(arr[i]);
    dfs(1);
    writeln(ans);
}

C - Inserting ‘x’

Problem Statement

    We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:

Insert a letter x to any position in s of his choice, including the beginning and end of s.

    Snuke’s objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.

Notes

    A palindrome is a string that reads the same forward and backward. For example, “a”, “aa”, “abba” and “abcba” are palindromes, while “ab”, “abab” and “abcda” are not.

Constraints

    1≤|s|≤ 105
    s consists of lowercase English letters.

Input

    Input is given from Standard Input in the following format:
        s

Output

    If the objective is achievable, print the number of operations required. If it is not, print “-1” instead.

Examples

Example 1
    Input
        xabxa
    Output
        2
    One solution is as follows (newly inserted ‘x’ are shown in bold):
    xabxa → xa x bxa → xaxbxa x
Example 2
    Input
        ab
    Output
        -1
    No sequence of operations can turn s into a palindrome.
Example 3
    Input
        a
    Output
        0
    s is a palindrome already at the beginning.
Example 4
    Input
        oxxx
    Output
        3
    One solution is as follows:
    oxxx → x oxxx → x xoxxx → x xxoxxx

题意

    给你一个字符串,问你能不能通过加最少的x来获得回文串。

思路

    首先,对于原串,我们将所有的x拿掉,进行一遍回文串判定,如果不是回文串,那么很显然直接输出-1,否则将原串用两个指针i,j分别从右往左和从左往右向中间扫。如果s[i]==s[j]那么直接i++,j–;否则如果s[i]==’x’,那么就ans++,i++;否则就是s[j]==’x’,那么就ans++,j–;最后扫到i>=j就行了。

Code

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>
inline void read(T &x) {
    Finish_read=0;x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;Finish_read=1;
}
template<class T>
inline void print(T x) {
    if(x/10!=0)
        print(x/10);
    putchar(x%10+'0');
}
template<class T>
inline void writeln(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
    putchar('\n');
}
template<class T>
inline void write(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
}
/*================Header Template==============*/
string s,n="";
int ans=0;
int main() {
    cin>>s;
    for(int i=0;i<s.length();i++)
        if(s[i]!='x')
            n+=s[i];
    for(int i=0,j=n.length()-1;i<=j;i++,j--)
        if(n[i]!=n[j]) {
            puts("-1");
            return 0;
        }
    for(int i=0,j=s.length()-1;i<=j;) {
        if(s[i]==s[j]) {
            i++;
            j--;
            continue;
        }
        if(s[i]=='x') {
            ans++;
            i++;
        }
        if(s[j]=='x') {
            ans++;
            j--;
        }
    }
    printf("%d\n",ans);
}

D - Yet Another Palindrome Partitioning

Problem Statement

    We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s1 , s2 , …, sN from left to right. (Here, s= s1 + s2 +…+ sN holds.) Snuke wants to satisfy the following condition:
    For each i (1≤i≤N), it is possible to permute the characters in si and obtain a palindrome.
    Find the minimum possible value of N when the partition satisfies the condition.

Constraints

    1≤|s|≤2× 105
    s consists of lowercase English letters.

Input

    Input is given from Standard Input in the following format:
        s

Output

    Print the minimum possible value of N when the partition satisfies the condition.

Examples

Example 1
    Input
        aabxyyzz
    Output
        2
    The solution is to partition s as “aabxyyzz” = “aab” + “xyyzz”. Here, “aab” can be permuted to form a palindrome “aba”, and “xyyzz” can be permuted to form a palindrome “zyxyz”.
Example 2
    Input
        byebye
    Output
        1
    “byebye” can be permuted to form a palindrome “byeeyb”.
Example 3
    Input
        abcdefghijklmnopqrstuvwxyz
    Output
        26
Example 4
    Input
        abcabcxabcx
    Output
        3
    The solution is to partition s as “abcabcxabcx” = “a” + “b” + “cabcxabcx”.

题意

    给你一个字符串,让你将他分成最少的子串,使得每个子串重排列后都是一个回文串

思路

    考虑dp,f[i]表示到i这一位最少可以分成几个串。对于每一个位置,我们记录从字符串开头到该位置的所有字母的个数是单数还是双数,这样我们可以对于每一个位置就是一个26位的01串,1表示这种字符是奇数,否则是偶数。然后用一个数组记录每种状态f值最小的位置,然后对于转移,我们枚举其中一个字母的数量是奇是偶与当前状态不一样的一个(还有自身原来的),然后求一个f值的min,最后对找到的那个最小值+1就是这个位置的值了。

Code

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>
inline void read(T &x) {
    Finish_read=0;x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;Finish_read=1;
}
template<class T>
inline void print(T x) {
    if(x/10!=0)
        print(x/10);
    putchar(x%10+'0');
}
template<class T>
inline void writeln(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
    putchar('\n');
}
template<class T>
inline void write(T x) {
    if(x<0)
        putchar('-');
    x=abs(x);
    print(x);
}
/*================Header Template==============*/
const int mx=(1<<26);
int pos[mx],f[200010];
char s[200010];
bitset<26> x[200010];
int main() {
    scanf("%s",s+1);
    int n=strlen(s+1);
    f[0]=0;
    memset(pos,-1,sizeof pos);
    pos[0]=0;
    for(int i=1;i<=n;i++) {
        x[i]^=x[i-1];
        x[i][s[i]-'a']=1-x[i][s[i]-'a'];
        f[i]=2e9;
        int t=x[i].to_ulong(),ind=i;
        for(int j=0;j<26;j++) {
            int tmp=(1<<j)^t;
            if(pos[tmp]!=-1&&f[ind]>f[pos[tmp]])
                ind=pos[tmp];
        }
        if(pos[t]!=-1&&f[ind]>f[pos[t]])
            ind=pos[t];
        f[i]=f[ind]+1;
        if(pos[t]==-1||f[i]<f[pos[t]])
            pos[t]=i;
    }
    printf("%d\n",f[n]);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
铸造工艺质量指导方针是一份文档,为铸造过程中的操作和控制提供准则和指导。它的目的是确保铸造件的质量达到预期标准,并提供一个一致的方法来管理铸造工艺。 首先,该指南包括了铸造工艺的各个环节。从原材料的选择和准备,到砂型制备、熔炼、浇铸和清理,各个步骤都有详细的指导。这有助于确保每个步骤都按照规定的程序执行,以减少质量缺陷和不一致性。 其次,该指南还包括对各种质量检验和控制的要求。例如,对铸造参数的测量和监控,以确保其在允许范围内;对物理性能的测试,如强度和硬度,以验证铸造件的性能;以及对外观和尺寸的检查,以确保外观和尺寸满足规定的要求。 此外,该指南还包括了对员工培训和技能要求的规定。培训有助于员工熟悉并理解指导方针,并具备正确执行的技能。这样可以确保操作人员能够根据工艺要求进行工作,提高整体工艺的一致性和质量。 最后,该指南还提供了问题处理和纠正措施的指导。在铸造过程中可能会发生各种问题,如气孔、缩孔或裂纹等。该指南通过提供问题处理的步骤和方法,帮助铸造厂解决这些问题,并采取相应的纠正措施,以提高铸造品质。 综上所述,铸造工艺质量指导方针对整个铸造过程提供了准则和指导,从而确保铸造件的质量达到预期标准。它涵盖了各个环节的操作和控制要求,包括原材料选择、工艺控制、质量检验和员工培训等方面,为铸造企业提供了一个可行的管理方法。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值