USACO section 2.3 Controlling Companies(dfs)

USACO section 3.4 Closed Fences(计算几何+叉积+二分) Closed Fences A closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 i, yi}, i in (1..N). Every pair of adjacent vertices defines a side of the fence. 阅读详情
Controlling Companies

Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns 12% of Mazda. It is said that a company A controls company B if at least one of the following conditions is satisfied:

  • Company A = Company B
  • Company A owns more than 50% of Company B
  • Company A controls K (K >= 1) companies denoted C1, ..., CK with each company Ci owning xi% of company B and x1 + .... + xK > 50%.

Given a list of triples (i,j,p) which denote company i owning p% of company j, calculate all the pairs (h,s) in which company h controls company s. There are at most 100 companies.

Write a program to read the list of triples (i,j,p) where i, j and p are positive integers all in the range (1..100) and find all the pairs (h,s) so that company h controls company s.

PROGRAM NAME: concom

INPUT FORMAT

 

Line 1:n, the number of input triples to follow
Line 2..n+1:Three integers per line as a triple (i,j,p) described above.

SAMPLE INPUT (file concom.in)

3
1 2 80
2 3 80
3 1 20

OUTPUT FORMAT

List 0 or more companies that control other companies. Each line contains two integers that denote that the company whose number is the first integer controls the company whose number is the second integer. Order the lines in ascending order of the first integer (and ascending order of the second integer to break ties). Do not print that a company controls itself.

SAMPLE OUTPUT (file concom.out)

1 2
1 3
2 3

 

/*
ID:nealgav1
PROG:concom
LANG:C++
*/
#include<fstream>
#include<cstring>
using namespace std;
const int mm=889;
ifstream cin("concom.in");
ofstream cout("concom.out");
int map[mm][mm],cnt[mm];
bool s[mm],flag[mm];
void dfs(int x,int n)
{
  if(flag[x])return;
  flag[x]=1;
  for(int i=1;i<=n;i++)
  {
    cnt[i]+=map[x][i];
    if(cnt[i]>50)
    { s[i]=1;
      dfs(i,n);
    }
  }
}
int main()
{
  int m,a,b,c,n=0;
  cin>>m;
  memset(map,0,sizeof(map));
  for(int i=0;i<m;i++)
  {
    cin>>a>>b>>c;
    map[a][b]+=c;
    if(a>n)n=a;if(b>n)n=b;
  }
  for(int i=1;i<=n;i++)
  { memset(s,0,sizeof(s));
    memset(flag,0,sizeof(flag));
    memset(cnt,0,sizeof(cnt));
    dfs(i,n);
    for(int j=1;j<=n;j++)
    if(s[j]&&j!=i)
    cout<<i<<" "<<j<<"\n";
  }
}


 

 

 

思路:一个公司遍历搜遍它的所有控股公司,然后将其输出,在重复进行第二个公司

 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: concom
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 6432 KB]
   Test 2: TEST OK [0.000 secs, 6432 KB]
   Test 3: TEST OK [0.000 secs, 6432 KB]
   Test 4: TEST OK [0.000 secs, 6432 KB]
   Test 5: TEST OK [0.000 secs, 6432 KB]
   Test 6: TEST OK [0.000 secs, 6432 KB]
   Test 7: TEST OK [0.000 secs, 6432 KB]
   Test 8: TEST OK [0.000 secs, 6432 KB]
   Test 9: TEST OK [0.022 secs, 6432 KB]

 

 

Controlling Companies
Russ Cox

The method used here to solve the problem is as follows. We keep track of which companies control which other companies, and every time we hear that so and so owns this much percent of so and so, we update our information.

The array "owns" keeps track of how much of company j is owned by company i, whether directly or via controlled companies. The array "controls" keeps track of which companies are controlled by which other companies.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#define NCOM 101

int owns[NCOM][NCOM];        /* [i,j]: how much of j do i and its
                                controlled companies own? */
int controls[NCOM][NCOM];    /* [i, j]: does i control j? */

/* update info: now i controls j */
void
addcontroller(int i, int j)
{
    int k;

    if(controls[i][j])        /* already knew that */
        return;

    controls[i][j] = 1;

    /* now that i controls j, add to i's holdings everything from j */
    for(k=0; k<NCOM; k++)
        owns[i][k] += owns[j][k];

    /* record the fact that controllers of i now control j */
    for(k=0; k<NCOM; k++)
        if(controls[k][i])
            addcontroller(k, j);

    /* if i now controls more companies, record that fact */
    for(k=0; k<NCOM; k++)
        if(owns[i][k] > 50)
            addcontroller(i, k);
}

/* update info: i owns p% of j */
void
addowner(int i, int j, int p)
{
    int k;

    /* add p% of j to each controller of i */
    for(k=0; k<NCOM; k++)
        if(controls[k][i])
            owns[k][j] += p;

    /* look for new controllers of j */
    for(k=0; k<NCOM; k++)
        if(owns[k][j] > 50)
            addcontroller(k, j);
}

void
main(void)
{
    FILE *fin, *fout;
    int i, j, n, a, b, p;

    fin = fopen("concom.in", "r");
    fout = fopen("concom.out", "w");
    assert(fin != NULL && fout != NULL);

    for(i=0; i<NCOM; i++)
        controls[i][i] = 1;

    fscanf(fin, "%d", &n);
    for(i=0; i<n; i++) {
        fscanf(fin, "%d %d %d", &a, &b, &p);
        addowner(a, b, p);
    }

    for(i=0; i<NCOM; i++)
    for(j=0; j<NCOM; j++)
        if(i != j && controls[i][j])
            fprintf(fout, "%d %d\n", i, j);
    exit(0);
}


 

超简单的视频换脸,效果相当不错!完全白嫖的技术,来自ComfyUI 官方客户端一键搞定!手把手教会你如何下载安装部署,而且教你如何使用。 如果你电脑上没有安装Visual Studio的C++桌面开发组件,还有Windows应用SDK C++模板,那么你需要自行去下载安装下【安装后默认界面会自动识别系统语言,当然如果你是中文繁体用户,那么你可以在 ComfyUI 的管理器里下载。】并把它放入根目录-models-insightface文件夹内 , 同时下载视频换脸工作流 【分享手把手教你视频换脸,本地部署,轻轻松松当上“电影主角”】,否则insightface无法被正常载入。) 这是换脸必备的工具 ,安装后重启; 阅读详情

相关推荐

《Kubernetes部署篇:基于x86_64+aarch64架构CPU+containerd一键离线部署容器版K8S1.33.3高可用集群》

《Kubernetes部署篇:基于x86_64+aarch64架构CPU+containerd一键离线部署容器版K8S1.33.3高可用集群》

东城绝神 1368

USACO Section 2.3 Controlling Companies(DFS)

Controlling Companies Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns 12% of Mazda. It is said that a ...

angtongyou1893的博客 240

向量乘法器设计

同样基于Wallace树乘法器,我们来构造向量乘法器。 在一些矩阵运算中经常用到向量的相乘运算,本例以4维向量为例子介绍向量乘法器的verilog HDL设计。 设向量a = (a1, a2, a3, a4), b = (b1, b2, b3, b4)。 则a 与 b的点乘为:a * b = a1 b1 + a2 b2 + a3 b3 + a4 b4, 即向量对应位置的值相乘,再相加...

Reborn Lee 2969

USACO-Section2.3 Controlling Companies【深度优先搜索】

题目描述: 有些公司是其他公司的部分拥有者,因为他们获得了其他公司发行的股票的一部分。例如,福特公司拥有马自达公司12%的股票。据说,如果至少满足了以下条件之一,公司A就可以控制公司B了: 公司A = 公司B。 公司A拥有大于50%的公司B的股票。 公司A控制K(K >= 1)个公司,记为C1, …, CK,每个公司Ci拥有xi%的公司B的股票,并且x1+ …. + xK > 50%。 你将被

tjj1998的博客 321

Python+whisper/vosk实现语音识别

Whisper 是一个由 OpenAI 开发的人工智能语音识别模型,它能够将语音转换为文本。Whisper 模型特别之处在于它的设计目标是能够理解和转录多种语言的语音,包括但不限于英语。Whisper 模型在训练时使用了大量不同语言的语音数据,这使得它具有很好的跨语言能力。Vosk 是一个开源的语音识别库,它可以在离线环境下工作,不依赖于任何外部服务。Vosk 基于Kaldi语音识别框架,支持多种语言,包括中文。Vosk提供了多种预训练模型,可以根据需求选择适合的模型进行语音识别。

weixin_44458771的博客 5939

基于eBPF的零侵入LLM智能体观测:AgentSight架构与实战

在分布式系统和云原生架构中,可观测性是保障应用稳定运行与高效排障的核心能力。其原理在于通过日志、指标和追踪三大支柱,从外部视角持续收集和分析系统状态,而非依赖应用内部埋点。这一技术价值在于能以统一、低开销的方式,理解复杂系统的内部行为,尤其在微服务、容器化及Serverless等动态环境中至关重要。应用场景广泛覆盖了性能监控、安全审计、故障诊断与根因分析。当我们将这一基础理念应用于当下快速发展的AI智能体领域时,便自然引出了对LLM智能体进行无侵入、系统级行为观测的需求。传统的应用层方案需要集成SDK,对闭

weixin_28696185的博客 322

USACO section 3.1 Contact(AC自动机)

Contact IOI'98 The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right f

nealgavin的专栏 9384

M1/M2 Mac用户看过来:不装VirtualBox,用PD虚拟机也能跑ENSP的保姆级教程

本文为M1/M2 Mac用户提供了一份不依赖VirtualBox,使用Parallels Desktop虚拟机运行ENSP的详细指南。通过ARM架构的Win10镜像选择、组件替代方案和网络配置优化,实现ENSP核心功能的高效运行,特别适合网络工程师在苹果芯片设备上进行网络模拟。

weixin_28683065的博客 411

USCAO section 1.3 Calf Flac

Calf Flac It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes

nealgavin的专栏 6656

第3版•系统集成项目管理工程师(中级) │ 告别迷茫!案例分析高分攻略

🥏第3版•系统集成项目管理工程师(中级) │ 告别迷茫!案例分析高分攻略

✨ 欢迎来到【Seal ^_^ 的优快云博客】!✨ 3867

华为od 面试手撕代码题【完成任务最少小时】

华为od 面试手撕代码题【完成任务最少小时】

MISAYAONE的博客 1579

USACO section 1.5 Checker Challenge(dfs深搜)

Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more tha

nealgavin的专栏 1922

addr2line解析不出来行号的解决方式(汇编解析高阶版)

摘要:本文针对AEC crash问题中addr2line无法解析行号的情况,通过llvm-addr2line和反汇编分析,定位到CamX::AECBEStats17::AdjustROIParams函数中的乘法溢出问题。关键发现包括: 常规addr2line只能解析到函数名但无具体行号 llvm-addr2line解析出多个可能溢出点(行196/204/211/218/270/271) 反汇编显示6个条件分支跳转到溢出处理函数 源码分析确认这些位置均存在乘法运算 最终通过汇编级调试工具成功定位UBsan报告

168

USACO section 2.3 Longest Prefix(dp)

Longest Prefix IOI'96 The structure of some biological objects is represented by the sequence of their constituents, where each part is denote by an uppercase letter. Biologists are interested in

nealgavin的专栏 1486

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

USACO section 2.4 Cow Tours(并查集+最短路)

Cow Tours Farmer John has a number of pastures on his farm. Cow paths connect some pastures with certain other pastures, forming a field. But, at the present time, you can find at least two pasture

nealgavin的专栏 1405

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

USACO section3.1 Shaping Regions(漂浮法)

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the s

nealgavin的专栏 1052

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

USACO section 2.2 Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start

nealgavin的专栏 989

USACO section 3.1 Stamps(dp)

Stamps Given a set of N stamp values (e.g., {1 cent, 3 cents}) and an upper limit K to the number of stamps that can fit on an envelope, calculate the largest unbroken list of postages from 1 cent

nealgavin的专栏 980

USCAO section 4.1 Fence Loops(最短路,最小环,5级)

Fence Loops The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only a

nealgavin的专栏 941

USACO section 1.5 Superprime Rib(深搜)

Superprime RibButchering Farmer John's cows always yields the best prime rib. You can tell prime ribs by looking at the digits lovingly stamped across them, one by one, by FJ and the USDA. Farmer John

nealgavin的专栏 937

USACO section 2.2 Party Lamps

Party Lamps IOI 98 To brighten up the gala dinner of the IOI'98 we have a set of N (10 <= N <= 100) colored lamps numbered from 1 to N. The lamps are connected to four buttons: Button 1: Wh

nealgavin的专栏 913

USACO section 3.2 Spinning Wheels(模拟)

Spinning Wheels 1998 ACM NE Regionals Each of five opaque spinning wheels has one or more wedges cut out of its edges. These wedges must be aligned quickly and correctly. Each wheel also has an ali

nealgavin的专栏 875

USCAO section Mother's Milk(搜索)

Mother's Milk Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty

nealgavin的专栏 847

USACO section 3.2 Feed Ratios(高斯定理)

Feed Ratios 1998 ACM Finals, Dan Adkins Farmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of th

nealgavin的专栏 803

list

的底层是双向链表结构,双向链表中每个元素存储在互不相关的独立节点中,在节点中通过指针指向其前一个元素和后一个元素。,因此反向迭代器的实现可以借助正向迭代器,即:反向迭代器内部可以包含一个正向迭代器,对正向迭代器的接口进行包装即可。是可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。迭代到该位置,在这段位置上迭代需要线性的时间开销;最大的缺陷是不支持任意位置的随机访问,比如:要访问。还需要一些额外的空间,以保存每个节点的相关联信息。个元素,必须从已知的位置。

xie0510_的博客 268

Java 集合框架(List、Set、Map)与常用基础

本文整理Java集合框架核心知识,涵盖集合体系、Collection接口API、List(ArrayList、LinkedList、Vector)、Set(HashSet、TreeSet)、Map(HashMap、TreeMap、Hashtable)实现类原理、泛型、增强for循环、可变参数与工具类,并附核心易错点速查表。

既然你都点开这里了,那可以给我点个关注吗?可以吗?可以吗? 483
上一篇: USACO section 2.3 Money Systems(dp)
下一篇: USACO section 2.4 The Tamworth Two(算模拟吧)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值