codeforces Round 213 div2部分题解

A. Good Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).

Input

The first line contains integers n and k (1 ≤ n ≤ 1000 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).

Output

Print a single integer — the number of k-good numbers in a.

Sample test(s)
input
10 6
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
output
10
input
2 1
1
10
output
1

 

A题其实是个大大的水题,无奈好久不打CF,今天集体犯二了,WA了一次,给定n,k,然后输入n个数(我把这些数当做字符串处理了);

对于每个数,允许有的数字某位置上的数字大于k,但是前提是必须所有0-k之间的数要出现在给定数字当中,如:n=2,k=1,输入1,则由于没有出现0-1的所有数字,所以说这个数字不合法,如果合法,则记录答案+1,否则检查下一个数字即可。

/**********************
* author:crazy_石头
* Pro:CF Round 213 div2.A
* algorithm:瞎搞
* Time:15ms
* Judge Status:Accepted
***********************/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>

using namespace std;

#define rep(i,h,n) for(int i=(h);i<=(n);i++)
#define ms(a,b) memset((a),(b),sizeof(a))
#define eps 1e-6
#define INF 1<<29

const int maxn=100000+5;

char a[maxn];
int vis[maxn];
int n,k;

int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int cnt=0,ok=0,tmp;
    scanf("%d%d",&n,&k);
    while(n--)
    {
        scanf("%s",a);
        ms(vis,0);
        int len=strlen(a);
        rep(i,0,len-1)
            vis[a[i]-'0']++;
        tmp=INF;
        rep(i,0,k)
            tmp=min(tmp,vis[i]);
        cnt+=tmp>0;
    }
    printf("%d\n",cnt);
    return 0;
}


 

B. The Fibonacci Segment
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have array a1, a2, ..., an. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 ≤ i ≤ r).

Let's define len([l, r]) = r - l + 1len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], iflen([l1, r1]) > len([l2, r2]).

Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains integers:a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

Print the length of the longest good segment in array a.

Sample test(s)
input
10
1 2 3 5 8 13 21 34 55 89
output
10
input
5
1 1 1 1 1
output
2


 

B是个超级水题,我艹,求最长的Fib序列;

/**********************
* author:crazy_石头
* Pro:CF Round 213 div2.B
* algorithm:水
* Time:15ms
* Judge Status:Accepted
***********************/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>

using namespace std;

#define rep(i,h,n) for(int i=(h);i<=(n);i++)
#define ms(a,b) memset((a),(b),sizeof(a))
#define eps 1e-6
#define INF 1<<29

const int maxn=100000+5;
int a[maxn];
int main()
{
	 int n,i,len;
	 scanf("%d",&n);
     int max=(n>=2)? 2: n;
     for(i=0;i<n;i++)
     {
        scanf("%d",&a[i]);
        if(i>=2&&a[i]==a[i-1]+a[i-2])
        {
            len++;
            if(len>max)
                max=len;
        }
        else
            len=2;
     }
     printf("%d\n",max);
	 return 0;
}

C. Matrix
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells(i, j) that are the elements of the rectangle equals a in each rectangle.

A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.

Input

The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).

Output

Print a single integer — the answer to a problem.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Sample test(s)
input
10
12345
output
6
input
16
439873893693495623498263984765
output
40


 

C. Matrix
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells(i, j) that are the elements of the rectangle equals a in each rectangle.

A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.

Input

The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).

Output

Print a single integer — the answer to a problem.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Sample test(s)
input
10
12345
output
6
input
16
439873893693495623498263984765
output
40


 

C题是暴力瞎搞。。

今天虽然前面做了三个题目,可是后面半小时直接酱油了T_T,DE没有思路,以后比赛争取拿下DE,要AK  div2!!

/**********************
* author:crazy_石头
* Pro:CF Round 213 div2.C
* algorithm:暴力
* Time:31ms
* Judge Status:Accepted
***********************/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>

using namespace std;

#define rep(i,h,n) for(int i=(h);i<=(n);i++)
#define ms(a,b) memset((a),(b),sizeof(a))
#define eps 1e-6
#define INF 1<<29
#define LL __int64
const int maxn=100000+5;
char a[maxn];
int sum[maxn],tmp[maxn];
int m,n;

int main()
{
    scanf("%d%s",&m,a);
    n=strlen(a);
    rep(i,0,n-1)
    tmp[i]=a[i]-'0';
    ms(sum,0);

    rep(i,0,n-1)
    {
        int cur=0;
        for(int j=i;j<n;j++)
        {
            cur+=tmp[j];
            sum[cur]++;
        }
    }
    LL ans=0;
    rep(i,0,n-1)
    {
        int s=0;
        for(int j=i;j<n;j++)
        {
            s+=tmp[j];
            if(s>0&&m%s==0&&m/s<=9*n)
                ans+=sum[m/s];
            else if(s==0&&m==0)
                ans+=(n*(n+1)/2);
        }
    }
    cout<<ans<<endl;
    return 0;}

 

抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值