日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

USACO_2_3_Controlling Companies

發布時間:2025/4/5 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 USACO_2_3_Controlling Companies 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

感覺這倒題沒有出好,比如數據:

3

1 2 30

1 3 30

2 1 30

2 3 30

3 1 30

3 2 30

?

公司1到底控制了2、3沒有?可以說控制了,也可以說沒有,但題目意思是沒有控制。

?

看了nocow上的解答才發現原來就是一個簡單的模擬題,大家去nocow看吧:

NOCOW上關于Controlling Companies的解答

我的代碼是參考usaco答案的

?

?

Code
/**//*
ID:?sdjllyh1
PROG:?concom
LANG:?JAVA
complete?date:?2008/12/20
author:?LiuYongHui?From?GuiZhou?University?Of?China
more?article:?www.cnblogs.com/sdjls
*/


import?java.io.*;
import?java.util.*;

public?class?concom
{
????
private?static?int?n?=?100;
????
private?static?int[][]?owns?=?new?int[n][n];
????
private?static?boolean[][]?controls?=?new?boolean[n][n];
????
private?static?int?triples;
????
private?static?int[]?triplesI;
????
private?static?int[]?triplesJ;
????
private?static?int[]?triplesP;

????
public?static?void?main(String[]?args)?throws?IOException
????
{
????????init();
????????run();
????????output();
????????System.exit(
0);
????}


????
private?static?void?run()
????
{
????????
for?(int?i?=?0;?i?<?n;?i++)
????????
{
????????????controls[i][i]?
=?true;
????????}


????????
for?(int?counter?=?0;?counter?<?triples;?counter++)
????????
{
????????????
int?i?=?triplesI[counter];
????????????
int?j?=?triplesJ[counter];
????????????
int?p?=?triplesP[counter];

????????????
for?(int?k?=?0;?k?<?n;?k++)
????????????????
if?(controls[k][i])
????????????????????owns[k][j]?
+=?p;

????????????
for?(int?k?=?0;?k?<?n;?k++)
????????????????
if?(owns[k][j]?>?50)
????????????????????addcontroller(k,?j);
????????}

????}


????
private?static?void?addcontroller(int?i,?int?j)
????
{
????????
if?(controls[i][j])
????????
{
????????????
return;
????????}


????????controls[i][j]?
=?true;

????????
for?(int?k?=?0;?k?<?n;?k++)
????????
{
????????????owns[i][k]?
+=?owns[j][k];
????????}


????????
for?(int?k?=?0;?k?<?n;?k++)
????????
{
????????????
if?(controls[k][i])
????????????
{
????????????????addcontroller(k,?j);
????????????}

????????}


????????
for?(int?k?=?0;?k?<?n;?k++)
????????
{
????????????
if?(owns[i][k]?>?50)
????????????
{
????????????????addcontroller(i,?k);
????????????}

????????}

????}


????
private?static?void?init()?throws?IOException
????
{
????????BufferedReader?f?
=?new?BufferedReader(new?FileReader("concom.in"));
????????triples?
=?Integer.parseInt(f.readLine());

????????triplesI?
=?new?int[triples];
????????triplesJ?
=?new?int[triples];
????????triplesP?
=?new?int[triples];
????????
for?(int?k?=?0;?k?<?triples;?k++)
????????
{
????????????StringTokenizer?st?
=?new?StringTokenizer(f.readLine());
????????????triplesI[k]?
=?Integer.parseInt(st.nextToken())?-?1;
????????????triplesJ[k]?
=?Integer.parseInt(st.nextToken())?-?1;
????????????triplesP[k]?
=?Integer.parseInt(st.nextToken());
????????}

????????f.close();
????}


????
private?static?void?output()?throws?IOException
????
{
????????PrintWriter?out?
=?new?PrintWriter(new?BufferedWriter(new?FileWriter("concom.out")));
????????
for?(int?i?=?0;?i?<?n;?i++)
????????
{
????????????
for?(int?j?=?0;?j?<?n;?j++)
????????????
{
????????????????
if?((i?!=?j)?&&?(controls[i][j]))
????????????????
{
????????????????????out.println((i?
+?1)?+?"?"?+?(j?+?1));
????????????????}

????????????}

????????}

????????out.close();
????}

}

轉載于:https://www.cnblogs.com/SDJL/archive/2008/12/20/1358920.html

總結

以上是生活随笔為你收集整理的USACO_2_3_Controlling Companies的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。