12年成都现场赛K_Yet Another Multiple Problem

本文解决了一个问题,即在给定一个整数N(小于10^4)和一组数字的情况下,找到最小的N的倍数,该倍数不包含这组数字中的任何一个。通过使用队列和数组,实现了一种高效的解决方案。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474

题目大意:

给一个正整数N(N<10^4),和M个0~9的数字,要求求出N的最小整数倍,这个数不包含给出的M个数字,不存在输出-1。比如,N=1,M=1 给出的一个数是1  那么输出就是2 。

解题思路:

用所有能有的数字去组合新的数字,直到队列空或者找到答案,而对于每个数来说,如果不是N的整数倍,那么对N取余一定是1~N-1的数字,而对于一个对N取模为K的数字,那么这个数再加上N取模依然为K,所以我们找到的第一个肯定是最优解,所以用这个作为数字入队的条件。一看N只有10^4,所以用数组满可以的。队列扩展的时候保证按从小到大的顺序,那么组合出来的数字也是递增的,符合题目要求,具体看代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<utility>
#define INF (1<<30)
#define EPS 1e-6
#define PI acos(-1)
#define lowbit(x) ((x) & (-(x)))
#define IDX(l,r) ((l)+(r) | (l)!=(r))
#define ABS(x) ((x)>0?(x):-(x))
#define SET(a,b) memset(a,b,sizeof(a))
#define NN 40
#define MM 10010
inline long long ReadInt()
{
    char ch = getchar();
    long long data = 0;
    while (ch < '0' || ch > '9')
        ch = getchar();
    do
    {
        data = data * 10 + ch - '0';
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9');
    return data;
}
using namespace std;

bool mod[100001];
int a[10];
int n, m, cnt;
struct node
{
    int val;
    int f;
    int sec;

} q[1000000];
void output (int t)
{
    if (q[t].f != -1) output (q[t].f);
    printf ("%d", q[t].sec);
}
void  bfs()
{
    int h = 1, t = 0;
    q[t].val = 0;
    for (int i = 1; i <= 9; i++) if (a[i] == 0)
        {
            if (i%n==0)
            {
                printf("%d\n",i);
                return;
            }
            t++;
            q[t].val = i;
            q[t].sec = i;
            q[t].f = -1;
        }
    if (t == 0)
    {
        printf ("-1\n");
        return;
    }
    while (h <= t)
    {
        for (int i = 0; i <= 9; i++)
        {
            if (a[i] == 0)
            {
                int temp = q[h].val;
                temp = (temp * 10 + i) % n;
                if (temp == 0)
                {
                    t++;
                    q[t].f = h;
                    q[t].sec = i;
                    output (t);
                    printf ("\n");
                    return;
                }
                if (mod[temp] == false)
                {
                    t++;
                    q[t].f = h;
                    q[t].val = temp;
                    q[t].sec = i;
                    mod[temp] = true;
                    cnt++;
                }
                else
                    continue;
            }
        }
        h++;
    }
    printf ("-1\n");
}
int main()
{
    int cas = 1;
    while (~scanf ("%d%d", &n, &m))
    {
        int temp;
        SET (a, 0);
        SET (mod, 0);
        for (int i = 1; i <= m; i++)
        {
            scanf ("%d", &temp);
            a[temp] = 1;
        }
        printf ("Case %d: ", cas++);
        bfs();
    }
    return 0;
}

【电动汽车充电站有序充电调度的分散式优化】基于蒙特卡诺和拉格朗日的电动汽车优化调度(分时电价调度)(Matlab代码实现)内容概要:本文介绍了基于蒙特卡洛和拉格朗日方法的电动汽车充电站有序充电调度优化方案,重点在于采用分散式优化策略应对分时电价机制下的充电需求管理。通过构建数学模型,结合不确定性因素如用户充电行为和电网负荷波动,利用蒙特卡洛模拟生成大量场景,并运用拉格朗日松弛法对复杂问题进行分解求解,从而实现全局最优或近似最优的充电调度计划。该方法有效降低了电网峰值负荷压力,提升了充电站运营效率与经济效益,同时兼顾用户充电便利性。 适合人群:具备一定电力系统、优化算法和Matlab编程基础的高校研究生、科研人员及从事智能电网、电动汽车相关领域的工程技术人员。 使用场景及目标:①应用于电动汽车充电站的日常运营管理,优化充电负荷分布;②服务于城市智能交通系统规划,提升电网与交通系统的协同水平;③作为学术研究案例,用于验证分散式优化算法在复杂能源系统中的有效性。 阅读建议:建议读者结合Matlab代码实现部分,深入理解蒙特卡洛模拟与拉格朗日松弛法的具体实施步骤,重点关注场景生成、约束处理与迭代收敛过程,以便在实际项目中灵活应用与改进。
acceptable to discuss approaches with other students, but you should not be looking at another student'swork while preparing your own. Question 1 Solve the following Integer Problem using the Branch & Bound algorithm Maximize +2w s.t. +3 w A +2w +10x +4y +6x +4x +3x +5V +7y -2y 68 政 170 w,x,y >= 0 and INTEGERRemember that although the original problem is integer, you are solving linear relaxations at each node ofthe algorithm (each problem you solve is a linear program with continuous variables). You will need multiple branches to solve this problem. If there are two or more fractional variables tobranch on, choose one arbitrarily (your choices might be difierent than a class-mates, and you will geldifferent answers as you go). This problem is tedious to solve to optimality. It is meant to show how inefficient branch and bound carbe, and why we learn about better algorithms. Because of that:If you haven’t found the optimal solution yet, you can stop after solving 10 subproblems Then report your results so far. Do you have a candidate solution? What bounds have you found on the obiective function value of the optimal solution? (do yotknow what z can be at most. and at least?)Which branch(es) do you still need to explore if you haven't found the optimal solution? e Or, if you think you found the optimal solution: Report the optimal solutioneIf you fathomed some branches, explain why you know you don't need to explore furtheiSolve it in Python using Gurobipy. All ofvour variables must be set to GRB.CONTINUOUS. Your scripcan be 'manual': vou can add and remove specific / hardcoded branches without writing code that coulcaccept any input. It is challenging to automate the script, and certainly not expected.
03-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值