ZOJ Monthly, March 2018

Easy Number Game

Time Limit: 2 Seconds       Memory Limit: 65536 KB

The bored BaoBao is playing a number game. In the beginning, there are  numbers. For each turn, BaoBao will take out two numbers from the remaining numbers, and calculate the product of them.

Now, BaoBao is curious to know the minimum sum of the products if he plays at least  turns. Can you tell him?

Input

The first line of input contains a positive integer  (about 30), the number of test cases. For each test case:

The first line contains two integers  and  (). Their meanings are described above.

The second line contains  integers  (), indicating the numbers.

Output

For each test case output one integer, indicating the minimum sum of the products.

Sample Input
3
4 2
1 3 2 4
3 1
2 3 1
4 0
1 3 2 4
Sample Output
10
2
0
Hint

For the first sample test case, the answer is 1 × 4 + 3 × 2 = 10.

For the second sample test case, the answer is 2 × 1 = 2.

n个数找m组数,使乘积的和最小

让前m小最大和最小的相乘就好了

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=0; i<n; i++)
            cin>>a[i];
        sort(a,a+n);
        int r=2*m-1;
        long long s=0;
        for(int i=0; i<m; i++)
            s+=a[i]*a[r-i];
        cout<<s<<endl;
    }
}
Super Brain

Time Limit: 1 Second       Memory Limit: 65536 KB

Super Brain is a famous scientific reality and talent show aiming to find people with exceptional brainpower.

In one of the challenges, two integer sequences  and  of length  are given to the contestant. It's guaranteed that  and  hold for all , and there is exactly one integer in the first sequence which also appears in the second sequence. The contestant has to memorize the two sequences in a very short time, and find the integer which appears in both sequences correctly.

As a technical staff of the show, you are required to write a program and find out the correct integer.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the length of the sequence.

The second line contains  integers  (), indicating the first sequence.

The third line contains  integers  (), indicating the second sequence.

It's guaranteed that  and  hold for all , and there is exactly one integer in the first sequence which also appears in the second sequence.

It's also guaranteed that the sum of  over all test cases will not exceed .

Output

For each test case output one line containing one integer, indicating the integer which appears in both sequences.

Sample Input
3
3
3 1 2
5 3 4
2
38324 14122
38323 14122
1
180310
180310
Sample Output
3
14122
180310

我可能被卡常了,memset就过了
找到两个数组唯一相同的
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a[N],n;
int main()
{
    ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        memset(a,0,sizeof a);
        cin>>n;
        int ans;
        for(int i=0,x; i<n; i++)cin>>x,a[x]++;
        for(int i=0,x; i<n; i++)
        {
            cin>>x;
            if(a[x])ans=x;
        }
        cout<<ans<<"\n";
    }
}
Happy Sequence

Time Limit: 3 Seconds       Memory Limit: 65536 KB

A sequence of  integers  () is called a happy sequence if each number divides (without a remainder) the next number in the sequence. More formally, we can say  for all , or we can say  for all .

Given  and , find the number of happy sequences of length . Two sequences  and  are different, if and only if there exists an such that  and .

As the answer can be rather large print it modulo  ().

Input

There are multiple test cases. The first line of the input contains an integer  (about 50), indicating the number of test cases. For each test case:

The first and only line contains two integers  and  (), indicating the upper limit of the elements in the sequence and the length of the sequence.

Output

For each case output a single integer, indicating the number of happy sequences of length  modulo 

Sample Input
1
3 2
Sample Output
5
Hint

In the sample test case, the happy sequences are: , , , , .

 一个数组是按照倍数关系的

这个题利用埃筛的思想去枚举i个数s*j作为最后一个元素就好

using namespace std;
typedef long long ll;
const ll MD=1e9+7;
const int N=2005;
ll dp[N][N];
int main()
{
    ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        int n,k;
        cin>>n>>k;
        memset(dp,0,sizeof dp);
        for(int i=1; i<N; i++) dp[1][i]=1;
        for(int i=1; i<k; i++)
            for(int j=1; j<=n; j++)
                for(int s=1; s*j<=n; s++)
                    dp[i+1][s*j]=(dp[i+1][s*j]+dp[i][j])%MD;
        ll sum=0;
        for(int i=1; i<=n; i++) sum=(sum+dp[k][i])%MD;
        cout<<(sum+MD)%MD<<endl;
    }
    return 0;
}
Travel along the Line

Time Limit: 1 Second       Memory Limit: 65536 KB

BaoBao is traveling along a line with infinite length.

At the beginning of his trip, he is standing at position 0. At the beginning of each second, if he is standing at position , with  probability he will move to position , with  probability he will move to position , and with  probability he will stay at position . Positions can be positive, 0, or negative.

DreamGrid, BaoBao's best friend, is waiting for him at position . BaoBao would like to meet DreamGrid at position  after exactly  seconds. Please help BaoBao calculate the probability he can get to position  after exactly  seconds.

It's easy to show that the answer can be represented as , where  and  are coprime integers, and  is not divisible by . Please print the value of  modulo , where  is the multiplicative inverse of  modulo .

Input

There are multiple test cases. The first line of the input contains an integer  (about 10), indicating the number of test cases. For each test case:

The first and only line contains two integers  and  (). Their meanings are described above.

Output

For each test case output one integer, indicating the answer.

Sample Input
3
2 -2
0 0
0 1
Sample Output
562500004
1
0

1s分为2s,只要n+m挑对了就行了

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MD=1e9+7;
const int N=2e5+5;
ll la(ll a,ll b)
{
    a%=MD;
    ll ans=1;
    while(b>0)
    {
        if(b&1)ans=ans*a%MD;
        b>>=1;
        a=a*a%MD;
    }
    return ans;
}
ll f[N],v[N],ans;
ll C(ll n,ll m)
{
    if(m<0||m>n) return 0;
    return f[n]*v[m]%MD*v[n-m]%MD;
}
int main()
{
    ios::sync_with_stdio(false);
    f[0]=1;
    for (ll i=1; i<N; i++) f[i]=f[i-1]*i%MD;
    v[N-1]=la(f[N-1],MD-2);
    for (ll i=N-2; i>=0; i--) v[i]=v[i+1]*(i+1LL)%MD;
    int T;
    cin>>T;
    while(T--)
    {
        int n,m;
        cin>>n>>m;
        ans=C(2*n,m+n)*la(la(2,2*n),MD-2)%MD;
        cout<<ans<<"\n";
    }
    return 0;
}

 

Lucky Man

Time Limit: 2 Seconds       Memory Limit: 65536 KB

BaoBao is keen on collection. Recently he is abandoning himself to Kantai Collection, especially to collecting cute girls, known as "Fleet Girls".

There are  various types of girls in the game. To get a girl, one can use some materials to build her. The probability to get a type of girl by building is the same for all types of girls. From the Coupon Collector's Problem we know that, to collect all types of girls, the expected number of times of building is .

But this rule does not apply to BaoBao, as he is always luckier than the ordinary players (maybe because he's an European). For BaoBao to collect all types of girls, the expected number of times of building is , where  means the maximum integer that doesn't exceed .

As a lucky man, BaoBao is not interested in the actual value of , and he just wants to know whether  is odd or even. Can you help him?

Input

The first line of the input is an interger  (about 100), indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the number of types of girls.

Output

For each test case, if  is odd output "1" (without quotes), if  is even output "0" (without quotes).

Sample Input
9
2
3
23
233
2333
23333
233333
2333333
23333333
Sample Output
1
1
0
1
0
0
1
1
0

被卡了一波时间,开方啊

def sqrt(n):
    l=0
    r=n
    while l<=r :
        mi=(l+r)>> 1
        F=mi*mi
        if(F<n):
            l=mi+1
        elif(F>n): r=mi-1
        else:
            return mi
    return l-1
T=int(input())
for i in range(0,T):
    a=int(input())
    if a==0:
        print("0")
    elif a<=3:
        print("1")
    else:
        a=sqrt(a)
        print(a & 1)

 sqrt对于每个都是成立的

def sqrt(n):
    l=0
    r=n
    while l<=r :
        mi=(l+r)>> 1
        F=mi*mi
        if(F<n):
            l=mi+1
        elif(F>n): r=mi-1
        else:
            return mi
    return l-1
T=int(input())
for i in range(0,T):
    a=int(input())
    a=sqrt(a)
    print(a & 1)

 

转载于:https://www.cnblogs.com/BobHuang/p/8541184.html

使用优化算法,以优化VMD算法的惩罚因子惩罚因子 (α) 和分解层数 (K)。 1、将量子粒子群优化(QPSO)算法与变分模态分解(VMD)算法结合 VMD算法背景: VMD算法是一种自适应信号分解算法,主要用于分解信号为不同频率带宽的模态。 VMD的关键参数包括: 惩罚因子 α:控制带宽的限制。 分解层数 K:决定分解出的模态数。 QPSO算法背景: 量子粒子群优化(QPSO)是一种基于粒子群优化(PSO)的一种改进算法,通过量子行为模型增强全局搜索能力。 QPSO通过粒子的量子行为使其在搜索空间中不受位置限制,从而提高算法的收敛速度与全局优化能力。 任务: 使用QPSO优化VMD中的惩罚因子 α 和分解层数 K,以获得信号分解的最佳效果。 计划: 定义适应度函数:适应度函数根据VMD分解的效果来定义,通常使用重构信号的误差(例如均方误差、交叉熵等)来衡量分解的质量。 初始化QPSO粒子:定义粒子的位置和速度,表示 α 和 K 两个参数。初始化时需要在一个合理的范围内为每个粒子分配初始位置。 执行VMD分解:对每一组 α 和 K 参数,运行VMD算法分解信号。 更新QPSO粒子:使用QPSO算法更新粒子的状态,根据适应度函数调整粒子的搜索方向和位置。 迭代求解:重复QPSO的粒子更新步骤,直到满足终止条件(如适应度函数达到设定阈值,或最大迭代次数)。 输出优化结果:最终,QPSO算法会返回一个优化的 α 和 K,从而使VMD分解效果最佳。 2、将极光粒子(PLO)算法与变分模态分解(VMD)算法结合 PLO的优点与适用性 强大的全局搜索能力:PLO通过模拟极光粒子的运动,能够更高效地探索复杂的多峰优化问题,避免陷入局部最优。 鲁棒性强:PLO在面对高维、多模态问题时有较好的适应性,因此适合海上风电时间序列这种非线性、多噪声的数据。 应用场景:PLO适合用于优化VMD参数(α 和 K),并将其用于风电时间序列的预测任务。 进一步优化的建议 a. 实现更细致的PLO更新策略,优化极光粒子的运动模型。 b. 将PLO优化后的VMD应用于真实的海上风电数据,结合LSTM或XGBoost等模型进行风电功率预测。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值