把一个完全图分成两部分

A university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in order to minimize traffic between parts. 
A disgruntled computer science student Vasya, after being expelled from the university, decided to have his revenge. He hacked into the university network and decided to reassign computers to maximize the traffic between two subnetworks. 
Unfortunately, he found that calculating such worst subdivision is one of those problems he, being a student, failed to solve. So he asks you, a more successful CS student, to help him. 
The traffic data are given in the form of matrix C, where Cij is the amount of data sent between ith and jth nodes (Cij = Cji, Cii = 0). The goal is to divide the network nodes into the two disjointed subsets A and B so as to maximize the sum ∑Cij (i∈A,j∈B).

Input

The first line of input contains a number of nodes N (2 <= N <= 20). The following N lines, containing N space-separated integers each, represent the traffic matrix C (0 <= Cij <= 10000). 
Output file must contain a single integer -- the maximum traffic between the subnetworks. 

Output

Output must contain a single integer -- the maximum traffic between the subnetworks.

Sample Input

3
0 50 30
50 0 40
30 40 0

Sample Output

90
//Memory Time
//188K   375MS 

#include<iostream>
using namespace std;

const int TimeLimit=2000;  //本题时间限制为2000ms

int main(int i,int j)
{
    int n;
    while(cin>>n)
    {
        /*Input*/

        int w[30][30]={0};
        for(i=1;i<=n;i++)
            for(j=1;j<=n;j++)
            {
                cin>>w[i][j];
                w[j][i]=w[i][j];  //双向完全图
            }

        /*Random Algorithm*/

        bool subset[30]={false};    //A集:true  B集:false
        int time=TimeLimit*100;  //使随机次数尽可能大,随机结果尽可能接近最优解
        long max_w=0;   //最大割的权值之和
        long sum=0;  //当前边割集权和

        while(time--)
        {
            int x=rand()%n+1;  //生成随机数 x,对应于总集合的某个结点x
                               //注意由于使用的结点序号为1~n,对应了数组下标,下标为0的数组元素没有使用
                               //那么这里必须+1,因为若rand()=n,那么再对n取模结果就为0
                               //这时就会导致使用了不存在的 [0]结点,本应使用的 [n]结点就被丢弃了

            subset[x]=!subset[x];  //改变x所在的集合位置

            for(int i=1;i<=n;i++)   //由于是完全图,所以每个顶点i都与x相关联,因此要全部枚举
            {
                if(subset[i]!=subset[x])   //结点i 和 x分别在两个集合内
                    sum+=w[i][x];   //就是说因为x所在集合的改变,使得割边的个数增加
                                    //割集的原权值 要加上 当前新加入的割边(i,x)的权值

                if(i!=x && subset[i]==subset[x])  //结点i 和 x分别在相同的集合内,但他们不是同一元素
                    sum-=w[i][x];   //就是说因为x所在集合的改变,使得割边的个数减少
                                    //割集的原权值 要减去 当前失去的割边(i,x)的权值
            }

            if(max_w < sum)
                max_w = sum;
        }

        cout<<max_w<<endl;
    }
    return 0;
}
View Code

 

在 SolidWorks 中,将一个实体分割为部分可以通过以下几种方式实现,具体取决于所需的操作复杂度和最终目标。 ### 使用草进行实体分割 1. 首先,在适当的基准面上绘制一个。可以选择圆形、矩形或其他任何形状,只要它能与要分割的实体相交。 2. 完成草后,使用“拉伸切除”命令来切割实体。选择正确的方向和深度以确保切除操作能够完全穿过实体[^1]。 3. 在“拉伸切除”的选项中,可以指定是否移除材料以及切除的方向。这允许用户精确控制切割后的结果。 ### 利用分割特征 1. 打开需要分割的零件文件,然后转到“插入”>“特征”>“分割”。 2. 选择两个零件有接触的面作为分割工具。这通常是平面或者曲面,它们与原实体交叉以定义新的边界。 3. 点击“切除零件”,并选择希望保留或移除的部分。如果不需要的部分仍然连接在一起,请检查之前选择的面是否正确。 4. 根据需求决定是否勾选“消耗切除实体”。如果不勾选此选项,则被切除的部分会被保存下来而不是立即删除。 5. 完成设置后点击确认按钮,完成分割过程。若需单独导出各部分,则可以通过编辑分割特征并结合“隐藏”功能来分别处理[^2]。 ### 实体间的相互分割 1. 当存在多个实体时,可以利用其中一个实体去切割另一个实体。例如,创建一个新的实体(如圆柱体),然后将其位置调整至现有实体内部。 2. 接着使用“组合”特征中的“减去”操作符,这样就可以从第一个实体中减去第二个实体所占据的空间,从而实现分割效果。 3. 注意,根据用来分割的不同类型的面(比如实体外表面、基准面或曲面),最终得到的结果也会有所差异。因此,在执行操作前应仔细考虑选用哪种类型的面最为合适[^3]。 ```python # 示例代码并不适用于SolidWorks直接操作,因为SolidWorks主要通过形界面进行交互, # 但是可以提供一个伪代码样例说明逻辑流程 def split_solidwork_entity(method): if method == 'sketch': create_sketch() extrude_cut() elif method == 'feature_split': select_contact_faces() perform_cutting_operation() manage_remaining_parts() else: use_another_entity_for_cutting() apply_boolean_operation() split_solidwork_entity('feature_split') ``` 上述方法提供了灵活的方式来应对不同的设计场景,并且能够满足大多数情况下对实体进行分割的需求。每种方法都有其特定的应用场合和优势,用户应该基于项目的具体要求和个人偏好来挑选最合适的技术。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值