More is better

本文介绍了一个算法问题,即如何计算在特定条件下最大的好友群数量。问题中,王先生希望找到尽可能多的男孩帮助完成一个项目,并规定了他们之间的友谊关系。通过输入直接朋友对的数据,算法实现了寻找最大群体的过程。

More is better

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 11653    Accepted Submission(s): 4319


Problem Description
Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.

Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way.
 

Input
The first line of the input contains an integer n (0 ≤ n ≤ 100 000) - the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)
 

Output
The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep.
 

Sample Input
4 1 2 3 4 5 6 1 6 4 1 2 3 4 5 6 7 8
 

Sample Output
4
2

Hint

A and B are friends(direct or indirect), B and C are friends(direct or indirect), then A and C are also friends(indirect). In the first sample {1,2,5,6} is the result.In the second sample {1,2},{3,4},{5,6},{7,8} are four kinds of answers.

 

这个题要注意输入m=0时,结果应该输出1;且需路径压缩。。否则会超时的!

 

#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
int bin[1100000],num[1100000];
int u[1100000],w[1100000];
int findx(int x)
{
    int i,j;
    int r=x;
    while(bin[r]!=r)
    {
        r=bin[r];
    }

    i=x;
    while(i!=r)
    {
        j=bin[i];
        bin[i]=r;
        i=j;
    }
    return r;
}
void merge(int x,int y)
{
    int fx,fy;
    fx=findx(x);
    fy=findx(y);
    if(fx!=fy)
        bin[fx]=fy;
}
int main()
{
    int n,m,i,j;
    while(~scanf("%d",&m))
    {
        if(m==0)
            printf("1\n");
        else
        {
            int maxx=0;
            for(i=0; i<m; i++)
            {
                scanf("%d%d",&u[i],&w[i]);
                int e=u[i]>w[i]?u[i]:w[i];
                if(e>maxx)
                    maxx=e;
            }
            for(i=1; i<=maxx; i++)
            {
                bin[i]=i;
            }
            for(i=0; i<m; i++)
            {
                merge(u[i],w[i]);
            }
            int max=0;
            memset(num,0,sizeof(num));
            for(i=1; i<=maxx; i++)
            {
                num[findx(i)]++;
                if(num[findx(i)]>max)
                    max=num[findx(i)];
            }
            printf("%d\n",max);
        }
    }
    return 0;
}


 

 

在量化金融领域,评估交易策略或投资组合时,自相关性(Self-correlation)和夏普比率(Sharpe ratio)是两个重要的统计指标。当出现“Self-correlation 0.9208 exceeds threshold of 0.7 and Sharpe ratio improvement less than 10%”的情况时,这意味着: - **自相关性过高**:该指标衡量的是时间序列与其自身滞后版本之间的相关性。在交易策略中,高自相关性(如 0.9208)表明策略的收益存在较强的序列相关性,即当前收益与过去收益高度相关。这可能意味着策略缺乏独立性,容易受到市场趋势变化的影响,并可能导致未来表现难以预测[^4]。 - **夏普比率提升不足**:夏普比率用于衡量单位风险所获得的超额回报。如果其改善幅度小于 10%,则说明策略的风险调整后收益没有显著提高。即使策略在某些时间段表现良好,但如果无法持续提供优于基准的回报,则其实际应用价值有限[^5]。 ### 解决方案与优化方向 为了解决上述问题,可以采取以下措施: #### 1. 策略去相关化 引入非线性因子或动态调整持仓权重,以降低策略输出信号的自相关性。例如,可以通过加入波动率控制机制或使用滚动窗口更新模型参数来减少历史数据对当前决策的影响。 ```python # 示例:通过滑动窗口更新回归模型以减少自相关 from sklearn.linear_model import LinearRegression import numpy as np def rolling_regression(X, y, window=60): model = LinearRegression() coefs = [] for i in range(window, len(X)): X_train, y_train = X[i-window:i], y[i-window:i] model.fit(X_train, y_train) coefs.append(model.coef_) return np.array(coefs) ``` #### 2. 优化风险调整收益 尝试引入更多风险因子(如 Fama-French 多因子模型)或使用机器学习方法进行特征选择,以提升夏普比率。此外,还可以结合强化学习动态调整资产配置比例,从而最大化风险调整后的收益。 #### 3. 引入多样化资产组合 增加不同资产类别(如股票、债券、商品)或跨市场(如全球多地区)的投资组合多样性,有助于降低整体波动率并提升夏普比率。 #### 4. 调整回测参数 检查回测过程中是否存在过拟合现象,确保测试集与训练集无重叠,并采用交叉验证方法评估策略稳定性。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值