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);
}


 

VS2103+Intel2013+MSMPI运行Fortran并行程序 VS2103+Intel2013+MSMPI运行Fortran并行程序MSMPI安装新建Fortran90项目编写Fortran并行程序在cmd运行编译完成的执行文件 MSMPI安装 我这里采用的是Microsoft MPI v9.0.1,可以点此下载。下载完成后同时安装msmpisdk.msi、msmpisetup.exe两个文件,安装位置默认即可。 其中msmpisdk.msi的默认安装路径在C:\Program Files (x86)\Microsoft SDKs\MPI,该文件包含了mpi环境所需 阅读详情

相关推荐

Kettle Web版部署指南

看到以上的日志则表示启动成功。

2401_89221867的博客 1731

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的博客 241

国内合规开通ChatGPT Plus实操指南:银行卡绑卡与支付全解析

ChatGPT Plus 是 OpenAI 官方推出的高级订阅服务,基于 GPT-4o 多模态大模型提供语音交互、图像理解与长上下文处理能力。其核心使用前提在于完成合规的国际支付绑定,而非网络接入方式。技术原理上,OpenAI 采用 Stripe 支付网关进行风控校验,重点匹配银行跨境权限、卡片类型(仅支持 Visa/Mastercard/Amex 信用卡)、BIN 号段及地理位置一致性。该机制决定了95%的绑卡失败源于银行端配置缺失或卡片不兼容,而非网络问题。实际应用中,PayPal 作为中间支付层可显著

chuannaoxuan4674的博客 2375

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

抖音Web端反爬参数全解析:x-bogus、a-bogus与msToken原理与实战

在数据采集与爬虫工程中,请求签名和风控参数往往是开发者最先遇到的壁垒。理解请求参数加密的基本原理,是绕过反爬机制、提升采集稳定性的关键。本文从签名算法的作用边界出发,系统拆解抖音Web端三大核心反爬参数——x-bogus、a-bogus与msToken的生成逻辑、相互差异及验证方法,并结合抓包定位、JS逆向复现等实操手段,帮助读者掌握从参数定位到代码落地的完整链路。内容兼顾技术科普与工程实践,也针对签名失效、Header不全、环境检测等高频踩坑点给出排查方案,适合Web逆向入门者和数据采集工程师参考。

weixin_27722377的博客 371

支付漏洞防护绕过的一种方式

放完包后就到了提交订单的地方,可以发现,金额确实小了很多,合理的搭配的话还可以更低,再次前进可以发现,金额确实是这么多,后面就不支付了,到此就结束了。也就是说数量可以为负数,但是金额不能为0或者0以下,有什么方法可以绕过这个限制吗,其实并不难,既然可以为负数,只是对金额不能为0或者负数做了限制。我们可以尝试拼接法,利用负数加上正数让他的值变得很低,但是又大于0就可以了,这里利用购物车的结算方法,随机加一些在购物车里。这里为了方便查看数据包,我这边商品的数量选择3,点击立即购买并抓包。

2301_80115097的博客 1546

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

Computer Networks 与 Computer & Security:从投稿准备到流程执行的实战指南

本文提供了一份针对CCF B类期刊《Computer Networks》与《Computer & Security》的投稿实战指南。从投稿前的心理与材料准备入手,详细拆解了账号注册、文件上传、信息填写等关键步骤,并重点对比了两本期刊在Cover Letter、推荐审稿人等环节的差异。文章旨在帮助研究者,尤其是初次投稿者,系统性地掌握投稿流程,规避常见错误,提升投稿效率与成功率。

zz67890的博客 1012

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

雷赛控制卡的扩展IO连接

因设备的上IO点较多,所以使用了多个雷赛32点位的IO扩展卡。上位机程序在控制输出IO时发现主模块IO和第一个扩展IO的输出可以控制。但第二个IO扩展卡和第三个IO扩展卡的输出控制不了。经排查出发现轴卡在初始化时只连接了第一个扩展IO卡。增加下面的代码连接上扩展IO就可以了。雷赛控制卡的扩展IO点无法控制问题处理。

StevenChen的博客 3212

生成EtherCAT从站XML图片信息方法

详细介绍了EtherCAT从站XML文件中图片元素的生成方法。

kevin1499的博客 2139

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的专栏 1924

电磁弹射器电源设计参数

电磁弹射器采用中高压直流供电系统(5,000-12,000V DC),以满足航母弹射的高功率需求(单次120+兆焦耳)。典型系统如福特级航母EMALS,峰值功率达100-130MW,工作电压8-10kV DC,通过高压设计降低电流(15-20kA)并提升效率20%。系统包含整流、储能和脉冲逆变环节,电压随载荷动态调整(轻型4-6kV,重型8-12kV)。采用特殊绝缘材料和模块化设计确保安全,相比蒸汽弹射节能30%且控制更精准(误差<±2%)。

336

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的专栏 1487

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

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的专栏 1406

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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的专栏 991

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的专栏 938

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的专栏 914

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的专栏 848

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

Java List 集合进阶|商品去重 equals 重写 + 完整学生管理系统菜单交互

承接上篇博客基础 List 实体案例,本篇完成两大综合案例:①Product 商品管理,重点理解重写 equals 实现集合去重;②菜单版学生信息管理系统,完整实现增、删、改、查,while 循环做控制台菜单,switch 做功能分发,是课程综合实验大题。List 三个实现类 ArrayList、LinkedList、Vector 区别?ArrayList 底层数组,查询快增删慢,线程不安全;LinkedList 双向链表,头尾增删快查询慢,线程不安全;Vector 底层数组,加锁线程安全,性能低。

SummerJokes的博客 220

【C++】list

本文从 `vector` 循环 `erase` 的搬移开销写起,讲 `list` 的构造、双向迭代器、增删查改与 `splice` 等特有操作,说明 `std::sort` 为什么不能用于 `list`;再分析迭代器失效规则,手写节点、迭代器、反向迭代器和链表本体,并用表驱动测试验证深拷贝与资源释放。

记录在学习过程中学到的知识 390
上一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址