暑假集训内容

离散化思想:

    有时数据范围很大时直接用哈西数组开不了,就要用离散化思想;

去重函数:unique()  STL里自带函数,返回去重后的尾地址。

lower_bound();

upper_bound();

前缀和:

        应用与树状数组。

剪枝:

          在搜索时可能会重复搜索,这时就要用到剪枝来减低时间复杂度;

   大多数情况:边界,最优 ,记忆化搜索,顺序。

BFS 大多用来找最优解,DFS大多来找可行性。

记忆化搜索题目:https://vjudge.net/contest/238941#problem/E(暑假第三天)。

三分:

       三分题目:https://vjudge.net/contest/239160。(题解另写)

     三分发要求:必须要单调。

动态规划:

    错排公式: f(n)=(n-1)*(f(n-1)+f(n-2))。

(1)描述优解的结构特征。 

(2)递归地定义一个最优解的值。 

(3)自底向上计算一个最优解的值。

(4)从已计算的信息中构造一个最优解。

相关题目:https://vjudge.net/contest/239160。

有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示。
 
Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。
Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
Sample Input
2
1 2
3 6
Sample Output
1
3

AC代码:

#include <iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<stack>
#include<ctime>
using namespace std;
int main()
{
    long long int a[100];

    a[1]=a[2]=1;
    for(int i=3;i<100;i++)
        a[i]=a[i-1]+a[i-2];
        int T;
        cin>>T;
    while(T--)
    {
        int x,y;
        cin>>x>>y;
        cout<<a[y-x+1]<<endl;;
    }
}

今年的ACM暑期集训队一共有18人,分为6支队伍。其中有一个叫做EOF的队伍,由04级的阿牛、XC以及05级的COY组成。在共同的集训生活中,大家建立了深厚的友谊,阿牛准备做点什么来纪念这段激情燃烧的岁月,想了一想,阿牛从家里拿来了一块上等的牛肉干,准备在上面刻下一个长度为n的只由"E" "O" "F"三种字符组成的字符串(可以只有其中一种或两种字符,但绝对不能有其他字符),阿牛同时禁止在串中出现O相邻的情况,他认为,"OO"看起来就像发怒的眼睛,效果不好。

你,NEW ACMer,EOF的崇拜者,能帮阿牛算一下一共有多少种满足要求的不同的字符串吗?

PS: 阿牛还有一个小秘密,就是准备把这个刻有 EOF的牛肉干,作为神秘礼物献给杭电五十周年校庆,可以想象,当校长接过这块牛肉干的时候该有多高兴!这里,请允许我代表杭电的ACMer向阿牛表示感谢!

再次感谢!
Input
输入数据包含多个测试实例,每个测试实例占一行,由一个整数n组成,(0<n<40)。
Output
对于每个测试实例,请输出全部的满足要求的涂法,每个实例的输出占一行。
Sample Input
1
2
Sample Output
3
8

#include <iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<stack>
#include<ctime>
using namespace std;
int main()
{
    long long int a[100][4];
    for(int i=1;i<4;i++)
        a[1][i]=1;
    for(int i=2;i<100;i++)
    {
        a[i][1]=a[i-1][1]+a[i-1][2]+a[i-1][3];
        a[i][2]=a[i-1][1]+a[i-1][2]+a[i-1][3];
        a[i][3]=a[i-1][1]+a[i-1][2];
    }
    int n;
    while(cin>>n!=NULL)
        cout<<a[n][1]+a[n][2]+a[n][3]<<endl;


}

尺取:

(不再细说,放几个例题)

A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S.
Input
The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The input will finish with the end of file.
Output
For each the case the program has to print the result on separate line of the output file.if no answer, print 0.
Sample Input
2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5
Sample Output
2
3

#include <iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<stack>
#include<ctime>
using namespace std;
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int a[100010],n,m,b[100010];
        cin>>n>>m;
        for(int i=0; i<n; i++)
            cin>>a[i];
        int x=0,y=1,p=0;
        int z=a[0];
        while(y<n||x<n)
        {
            if(z==m)
            {
                b[p++]=y-x;
                if(y<n)
                    z+=a[y]-a[x],
                       y++,
                       x++;
                else
                {
                    z-=a[x];
                    x++;
                }
            }
            if(z>m)
            {
                b[p++]=y-x;
                z-=a[x];
                x++;
            }

            if(z<m)
            {
                if(y<n)
                {
                    z+=a[y];
                    y++;

                }
                else
                    break;
            }

        }
        if(p)
        sort(b,b+p),
        cout<<b[0]<<endl;
        else
        {
            cout<<"0"<<endl;
        }
    }

}

猜你喜欢

转载自blog.csdn.net/qq_41232172/article/details/81105472