Codeforces Round #276 (Div. 1)

本文解析了三道算法题目:寻找二进制数中1最多的数、求解整数序列的最大余数值、以及幼儿园小朋友分组的最大社交性总和。通过动态规划、贪心策略等方法给出了详细的解答。

a.

给俩数, 求他俩之间二进制数中1最多的,有多个输出最小的;

贪心,从小到大加能加就加,最后可能碰到一个不能加了但是当前数比l小,那么就加上这个数,然后从大到小,能减就减,见到符合条件

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    long long n, l, r;
    long long a[100];
    long long s = 1, maxa = 1e18;
    long long u;
    for(long long i = 0;; i++){
        a[i] = s;
        s*=2;
        u = i;
        if(s > maxa)break;
    }
    //for(int i = 0; i <= u; i++)printf("%lld ", a[i]);
    cin>>n;
    while(n--){
        cin>>l>>r;//printf("*%d", u);
        long long sum = 0;
        for(int i = 0; i <= u; i++){
            if(sum + a[i] <= r){//cout<<sum<<" "<<a[i]<<endl;
                sum += a[i];
            }else if(sum < l){
               sum += a[i];
                for(int k = i-1; k >= 0; k--){
                    if(sum - a[k] >= l){
                        sum -= a[k];
                    }
                    if(l <= sum  && sum <= r)
                        break;
                }break;
            }
        }
        cout<<sum<<endl;
    }
}
View Code

 

B. Maximum Value

You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.

Input

The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).

The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).

想了半天决定看别人代码, 果然在ai的数据范围上做文章了,就是每次处理出来小于等于i的数中最大的保存到一个数组里,然后找每个小于ai的n倍-1的最大数字,取膜

#include<iostream>
#include<stdio.h>
using namespace std;
const int maxa = 2000005;
int a[maxa], b[maxa];
int main(){
    int n;
    scanf("%d", &n);
    while(n--){int x;scanf("%d", &x);a[x] = x;};
    for(int i = 1; i < maxa; i++) b[i] = max(b[i-1],a[i]);
    int maxn = 0;
    for(int i = 2; i < maxa; i++) if(a[i])
        for(int k = 2*i; k < maxa; k+= i) maxn = max(maxn, b[k-1] % i);
    printf("%d", maxn);
}
View Code

 

D. Kindergarten

In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero).

The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.

Input

The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106).

The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109).

Output

Print the maximum possible total sociability of all groups.

简单的来说题意就是给你一段数字,让你分成任意段,每段的值是这一段中的最大值减去最小值,求所有段的值的最大和;

好吧这题也是看别人的代码看了半天才懂;

由于每段的值是最大值-最小值

我们这样定义三个状态,dp[i][1]代表到以i结尾的值;

dp[i][0]代表当前段的最大值已经确定的最大值(这里的值是确定的最大值+前面区段的值)

dp[i][2]代表当前段的最小值是a[i]的值减去a[i];(同上)

那么dp[i][0]可以由dp[i-1][0]过来代表此数字被放弃了,也可以由dp[i-1][1]推过来代表当前区段的最大值为当前数,在这两个中取最大值;

dp[i][1],dp[i][2]同上

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
const long long maxa = 1000005;
long long a[maxa];
long long dp[maxa][3];
int main(){
    long long n;
    cin>>n;
    long long x;
    //scanf("%d", &x);
    cin>>x;
    dp[1][0] = x;
    dp[1][2] = -x;
    for(long long i = 2; i <= n; i++){
        cin>>x;
        for(long long k = 0; k < 3; k++){
            dp[i][k] = dp[i-1][k];
            if(k > 0) dp[i][k] = max(dp[i][k], dp[i-1][k-1] - x);
            if(k < 2) dp[i][k] = max(dp[i][k], dp[i-1][k+1] +x);
            //printf("%d ", dp[i][k]);
        }//puts("");
    }cout<<dp[n][1]<<endl;
}
View Code

 

转载于:https://www.cnblogs.com/icodefive/p/4107989.html

标题基于Python的自主学习系统后端设计与实现AI更换标题第1章引言介绍自主学习系统的研究背景、意义、现状以及本文的研究方法和创新点。1.1研究背景与意义阐述自主学习系统在教育技术领域的重要性和应用价值。1.2国内外研究现状分析国内外在自主学习系统后端技术方面的研究进展。1.3研究方法与创新点概述本文采用Python技术栈的设计方法和系统创新点。第2章相关理论与技术总结自主学习系统后端开发的相关理论和技术基础。2.1自主学习系统理论阐述自主学习系统的定义、特征和理论基础。2.2Python后端技术栈介绍DjangoFlask等Python后端框架及其适用场景。2.3数据库技术讨论关系型和非关系型数据库在系统中的应用方案。第3章系统设计与实现详细介绍自主学习系统后端的设计方案和实现过程。3.1系统架构设计提出基于微服务的系统架构设计方案。3.2核心模块设计详细说明用户管理、学习资源管理、进度跟踪等核心模块设计。3.3关键技术实现阐述个性化推荐算法、学习行为分析等关键技术的实现。第4章系统测试与评估对系统进行功能测试和性能评估。4.1测试环境与方法介绍测试环境配置和采用的测试方法。4.2功能测试结果展示各功能模块的测试结果和问题修复情况。4.3性能评估分析分析系统在高并发等场景下的性能表现。第5章结论与展望总结研究成果并提出未来改进方向。5.1研究结论概括系统设计的主要成果和技术创新。5.2未来展望指出系统局限性并提出后续优化方向。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值