usaco 2008 jan bronze

【USACO 2008 January Silver】架设电话线 二分答案+最短路 这道题其实跟以前做的求所有到终点的路径的最大边的最小值很像,那个问题是用二分来解的,而这道题,无非是增加了一个k条边免费的一个限制。依旧可以使用二分答案的方法解决,在判定是否可行时,只需要判断是否能寻找到一条路径,使得该路径上大于我们二分的这个值的边不超过k条,实质上就是最短路做的一个变形而已,小于二分的值的边可以看做边权为0,大于的可以看做边权为1,直接求最短路看是否小于k即可#include 阅读详情

原题在这里:

**********************************************************************
                           BRONZE PROBLEMS
**********************************************************************
                  Three problems numbered 11 through 13
**********************************************************************

Problem 11: Costume Party [Neal Wu, 2007]

It's Halloween! Farmer John is taking the cows to a costume party,
but unfortunately he only has one costume. The costume fits precisely
two cows with a length of S (1 <= S <= 1,000,000). FJ has N cows
(2 <= N <= 20,000) conveniently numbered 1..N; cow i has length L_i
(1 <= L_i <= 1,000,000). Two cows can fit into the costume if the
sum of their lengths is no greater than the length of the costume.
FJ wants to know how many pairs of two distinct cows will fit into
the costume.

PROBLEM NAME: costume

INPUT FORMAT:

* Line 1: Two space-separated integers: N and S

* Lines 2..N+1: Line i+1 contains a single integer: L_i

SAMPLE INPUT (file costume.in):

4 6
3
5
2
1

OUTPUT FORMAT:

* Line 1: A single integer representing the number of pairs of cows FJ
        can choose. Note that the order of the two cows does not
        matter.

SAMPLE OUTPUT (file costume.out):

4

OUTPUT DETAILS:

The four pairs are as follows: cow 1 and cow 3; cow 1 and cow 4; cow 2 and
cow 4; and finally cow 3 and cow 4.

**********************************************************************

Problem 12: Election Time [Jeffrey Wang, 2007]

The cows are having their first election after overthrowing the
tyrannical Farmer John, and Bessie is one of N cows (1 <= N <=
50,000) running for President. Before the election actually happens,
however, Bessie wants to determine who has the best chance of
winning.

The election consists of two rounds. In the first round, the K cows
(1 <= K <= N) cows with the most votes advance to the second round.
In the second round, the cow with the most votes becomes President.

Given that cow i expects to get A_i votes (1 <= A_i <= 1,000,000,000)
in the first round and B_i votes (1 <= B_i <= 1,000,000,000) in the
second round (if he or she makes it), determine which cow is expected
to win the election. Happily for you, no vote count appears twice
in the A_i list; likewise, no vote count appears twice in the B_i
list.

PROBLEM NAME: elect

INPUT FORMAT:

* Line 1: Two space-separated integers: N and K

* Lines 2..N+1: Line i+1 contains two space-separated integers: A_i
        and B_i

SAMPLE INPUT (file elect.in):

5 3
3 10
9 2
5 6
8 4
6 5

INPUT DETAILS:

There are 5 cows, 3 of which will advance to the second round. The cows
expect to get 3, 9, 5, 8, and 6 votes, respectively, in the first round and
10, 2, 6, 4, and 5 votes, respectively, in the second.

OUTPUT FORMAT:

* Line 1: The index of the cow that is expected to win the election.

SAMPLE OUTPUT (file elect.out):

5

OUTPUT DETAILS:

Cows 2, 4, and 5 advance to the second round; cow 5 gets 5 votes in the
second round, winning the election.

**********************************************************************

Problem 13: iCow [Jeffrey Wang, 2008]

Fatigued by the endless toils of farming, Farmer John has decided
to try his hand in the MP3 player market with the new iCow. It is
an MP3 player that stores N songs (1 <= N <= 1,000) indexed 1 through
N that plays songs in a "shuffled" order, as determined by Farmer
John's own algorithm:

   * Each song i has an initial rating R_i (1 <= R_i <= 10,000).

   * The next song to be played is always the one with
     the highest rating (or, if two or more are tied, the highest
     rated song with the lowest index is chosen).

   * After being played, a song's rating is set to zero, and its rating
     points are distributed evenly among the other N-1 songs.

   * If the rating points cannot be distributed evenly (i.e.,
     they are not divisible by N-1), then the extra points are
     parceled out one at a time to the first songs on the list
     (i.e., R_1, R_2, etc. -- but not the played song) until no
     more extra points remain.

This process is repeated with the new ratings after the next song
is played.

Determine the first T songs (1 <= T <= 1000) that are played by the
iCow.

PROBLEM NAME: icow

INPUT FORMAT:

* Line 1: Two space-separated integers: N and T

* Lines 2..N+1: Line i+1 contains a single integer: R_i

SAMPLE INPUT (file icow.in):

3 4
10
8
11

INPUT DETAILS:

The iCow contains 3 songs, with ratings 10, 8, and 11, respectively.
You must determine the first 4 songs to be played.

OUTPUT FORMAT:

* Lines 1..T: Line i contains a single integer that is the i-th song
        that the iCow plays.

SAMPLE OUTPUT (file icow.out):

3
1
2
3

OUTPUT DETAILS:

The ratings before each song played are:
   R_1  R_2  R_3
    10    8   11  -> play #3  11/2 = 5, leftover = 1
    16   13    0  -> play #1  16/2 = 8
     0   21    8  -> play #2  21/2 = 10, leftover = 1
    11    0   18  -> play #3  ...

**********************************************************************

数据在这里:

http://contest.usaco.org/JAN08

我的题解在这里:

/*
 * [usaco jan08 bronze] costume.c
 * mike-w
 * 2012-10-29
 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAXS 1111111
#define MAXN 22222

int f[MAXN];
int S, N;

int comp(const void *e1, const void *e2)
{
	return *((int*)e1) - *((int*)e2);
}

int main(void)
{
	int i, low, high, ans=0;
#ifdef TEST
	freopen("costume.in", "r", stdin);
	freopen("costume.out", "w", stdout);
#endif
	scanf("%d%d", &N, &S);
	for(i=0; i<N; i++)
		scanf("%d", f+i);
	qsort(f, N, sizeof(int), comp);
	low=0, high=N-1, ans=0;
	while(low<high)
	{
		if(f[low]>=S)
			break;
		while(low<high && f[low]+f[high]>S)
			high--;
		if(low<high)
			ans+=(high-low);
		low++;
	}
	printf("%d\n", ans);
	return 0;
}

/*
 * [usaco jan08 bronze] elect.c
 * mike-w
 * 2012-10-29
 * *****************************************
 * 非常简单,做一个统计即可
 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAXN 55555

int f[MAXN][3];
int N, K;

int comp1(const void *e1, const void *e2)
{
	return *((int*)e2+1) - *((int*)e1+1);
}

int comp2(const void *e1, const void *e2)
{
	return *((int*)e2+2) - *((int*)e1+2);
}

int main(void)
{
	int i;
#ifdef TEST
	freopen("elect.in", "r", stdin);
	freopen("elect.out", "w", stdout);
#endif
	scanf("%d%d", &N, &K);
	for(i=1; i<=N; i++)
		scanf("%d%d", f[i]+1, f[i]+2), f[i][0]=i;
	qsort(f+1, N, sizeof(int[3]), comp1);
	qsort(f+1, K, sizeof(int[3]), comp2);
	printf("%d\n", f[1][0]);
	return 0;
}

/*
 * [usaco jan08 bronze] icow
 * mike-w
 * 2012-10-29
 * ******************************************
 * 有一条教训:审题永远是最重要的!!!
 * 题目中说不能整除的部分分给列表中的其他歌曲
 * 不是排序后的列表,而是原始列表==!
 * 哀悼。。。
 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAXN 1111

int f[MAXN];
int N, T;

int main(void)
{
	int i, play, inc, remain, c;
#ifdef TEST
	freopen("icow.in", "r", stdin);
	freopen("icow.out", "w", stdout);
#endif

	scanf("%d%d", &N, &T);
	for(i=1; i<=N; i++)
		scanf("%d", f+i);

	if(N==1)
	{
		puts("1");
		return 0;
	}

	while(T-->0)
	{
		/* select a song */
		play=1;
		for(i=1; i<=N; i++)
			if(f[play]<f[i])
				play=i;
		printf("%d\n", play);
		/* modify rating */
		inc=f[play]/(N-1);
		remain=f[play]-inc*(N-1);
		for(i=1; i<=N; i++)
			f[i]+=inc;
		for(i=c=1; i<=N && c<=remain; i++)
			if(i!=play)
				f[i]++, c++;
		f[play]=0;
	}
	return 0;
}


总而言之,题目还是很水的。。。

架设电话线 题解 题目描述 原题来自:USACO 2008 Jan. Silver 在郊区有 NNN 座通信基站,PPP 条双向电缆,第 iii 条电缆连接基站 AiA_iAi​ 和 BiB_iBi​。特别地,111 号基站是通信公司的总站,NNN 号基站位于一座农场中。现在,农场主希望对通信线路进行升级,其中升级第 iii 条电缆需要花费 LiL_iLi​。 电话公司正在举行优惠活动。农场主可以指定一条从 111 号基站到 NNN 号基站的路径,并指定路径上不超过 KKK 条电缆,由电话公司免费提供升级服务。农场主只需要支 阅读详情

相关推荐

USACO2018open Bronze试题

这里是USACO2018全美公开赛铜组的试题,题解USACO上有,鄙人不才。 USACO 2018 US Open Contest, Bronze The bronze division had 812 total participants, of whom 657 were pre-college students. All competitors who scored 700 or high...

fu_xuantong的博客 2153

(解题报告)POJ3664---Election Time---用结构体实现两组相关联数据的排序问题

两次快排 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatus Description The cows are having their first election after overthrowing the tyrannical Farmer John, an

PrConstantin 861

驱动钛丝(SMA)的应用(5)汽车腰托气阀常见问题及解决方案

财哥在前段时间发布的《驱动钛丝(SMA)的应用(1)汽车腰托支撑按摩气阀模块》一文,引发了很多企业的拜访和交流。 目前很多厂家已经启动或正在进行相关研发,同时也遇到了诸如:钛丝选型、驱动位移、响应设计、温度控制、力量设计、点动滞后、铆接工艺、量化生产等问题。

weixin_39168671的博客 1239

Election Time

Akatsuki

Akatsuki 863

手推反向传播+numpy实现

反向传播的重要性不必多说,手推也是必备基础,大厂面试要求用numpy实现一下BP也是经常的事。下面以一个简单的两层网络为例(简单到连bias都没有的那种),真·手推反向传播+numpy实现。 说明: input:输入 net_h:隐层 S(x):sigmoid简写 SD(x):sigmoid导数的简写 out_h:隐层经过sigmoid激活的输出 net_o:输出层 out_o:经过经过sigmoid激活的输出层,也就是最后的输出 target(简写t1、t2):Ground...

xian0710830114的专栏 1238

Goldwasser-Micali 公钥加密系统

1、二次剩余问题 对于整数n ,定义Zn∗={a∈Zn,gcd(a,n)=1}Z^*_n=\{ a∈Z_n,gcd(a,n) =1\}Zn∗​={a∈Zn​,gcd(a,n)=1} 。当存在d∈Znd \in Z_nd∈Zn​ ,使得 d2≡a mod nd^2 \equiv a \, mod \,nd2≡amodn ,称 a 为模 n 的二次剩余;否则称 a 为模 n的二次非剩余。判断 a 是否为模 n 的二次剩余的问题称为模n 的二次剩余问题。 \rule[-10pt]{14.3cm}{0.05em}

不染心的博客 4312

【Usaco DEC08 bronze】劣质的草

题目描述贝茜像其它奶牛一样正在吃草,她正在思考她所在的地方。她注意 到她只得到了一个平于海平面的广泛大片牧场。只有海拔1米或者更 高更硬的草不那么美味。草随着海拔的增加越发难吃。 继续咀嚼,她意识到,这没有食欲的食物长成两侧的丘陵,形成了青 翠美味丰富草地海洋中的一系列劣质草小岛 。贝茜穿上她的实验服,决心测定她的牧场有多少劣草小岛。她画出一 张画有被分成R (1 < R <= 1,000)

RainbowCrown_CGH's blog 721

Syzkaller实战教程2:运行环境配置+实例运行

本文详细介绍了在linux系统上搭建Syzkaller内核模糊测试环境的完整流程。 1.环境配置:通过VMware创建Ubuntu20.04虚拟机A,配置QEMU/KVM虚拟化环境,安装Go语言工具链和Syzkaller; 2.内核编译:下载Linux内核源码并配置KCOV等调试选项,编译生成带覆盖率支持的bzImage内核镜像; 3.测试环境构建:使用debootstrap创建Debian虚拟机镜像,通过QEMU启动嵌套虚拟机B; 实例测试: 4.演示两种测试场景 - 提供完整上手教程

cuguanren的博客 1375

poj——3664——Election Time

Description The cows are having their first election after overthrowing the tyrannical Farmer John, and Bessie is one of N cows (1 ≤ N ≤ 50,000) running for President. Before the election actually

清溪浅水 970

嵌入式工程师成长之路(1)——元件基础(完整版)

为什么你的电路总是“玄学”故障?答案藏在这些元件里! 0欧电阻竟能引发信号反射?5V转3.3V电平匹配失败导致MCU烧毁?电容降压设计让电源“滋滋”响?——这些坑,本文全填平! 优快云硬件领域头部博主十年踩坑经验汇总,覆盖电阻、电容、电感核心难点+高频实战问题,让你从“调试地狱”直通“一次成功”!

云轩阁 2万+

停车位检测:基于YOLOv5与UI界面的实现

YOLOv5是YOLO(You Only Look Once)系列中的最新版本,它能够在单次前向传播中同时完成多个目标的定位与分类,因此被广泛应用于实时目标检测任务。与之前的版本相比,YOLOv5在精度和速度上得到了很大的优化,适合嵌入到实际的自动驾驶和智能交通系统中。YOLOv5使用了卷积神经网络(CNN)进行特征提取,并通过回归方法预测边界框、类别及置信度。高效的推理速度:YOLOv5采用了优化的模型结构,能够在保证精度的同时提供较快的推理速度。较高的精度。

YOLO 694

No.11 Going to the Movies

POJ 2393 Going to the Movies 题面全文翻译

Chen_q_的博客 282

YOLOv11改进策略【损失函数篇】| 将激活函数替换为带有注意力机制的激活函数 ARelu

将ELSA中的函数Φ\PhiΦ用具有可学习参数α\alphaα和β\betaβ的网络层表示为LxiαβCαxixi0σβxixi≥0Lxi​αβCαxi​σβxi​​xi​0xi​≥0​,结合标准的Rectified Linear UnitsRxi0xi0xixi≥0Rxi​0xi​​xi​0xi​≥0​,得到可学习激活函数Fxiα。

Limiiiing的博客 2115

bzoj1612[Usaco2008 Jan]Cow Contest奶牛的比赛

Description FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:)。在赛场上,奶牛们按1..N依次编号。每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就是说,奶牛们的编程能力有明确的排名。 整个比赛被分成了若干轮,每一轮是两头指定编号的奶牛的对决。如果编号为A的奶牛的编程能力强于编号为B的奶牛(1 <= A <= N; 1 Inp

We are OIers 637

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

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

bzoj1612 【Usaco2008 Jan】Cow Contest 奶牛的比赛

Floyd求传递闭包

AaronPolaris 1070

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

#P01216. [usaco2008 Dec]Hay Expenses草料开支

说明 每天农场主约翰都会用一顿奢侈美味的草料大餐喂养奶牛们。然后, 他会在他记录开支的笔记本上记录下草料的包数。 缴税时间到来时,约翰意识到自己忘记记录草料喂养的日期。他必须 计算出许多不同的连续草料喂养的总数,以解决这个涉及一个月饲料 开支难题。 约翰设立了一个包含被简单编号为1 .. N的N (4 <= N <= 500)天 的干草包数H_i (1 <= H_i <= 1,000)。他有Q (1 <= Q <= 500)次额外 查询,每次查询包含整数S_j和E_j(

dhkk_nqp的博客 669

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Going to the Movies(https://acs.jxnu.edu.cn/problem/NOIOPJCH02072393)

题目: Going to the Movies 10000ms1000K 描述: Farmer John is taking some of his cows to the movies! While his truck has a limited capacity of C (100 <= C <= 5000) kilograms, he wants to take the cows that, in aggregate, weigh as much as possible wi...

m0_65667343的博客 189

cogs 142. [USACO Jan08] iCow播放器 ???

☆ 输入文件:icow.in 输出文件:icow.out 简单对比 时间限制:1 s 内存限制:128 MB 被无止境的农活压榨得筋疲力尽后,Farmer John打算用他在MP3播放器市场 新买的iCow来听些音乐,放松一下。FJ的iCow里存了N(1 <= N <= 1,000)首曲子,按1..N依次编号。至于曲子播放的顺序,则是按一个Farme...

weixin_30915275的博客 417

Poj3662 Usaco2008JanSilver Telephone Lines

题目大意 给定N个点P条边的无向图,官方提供k条免费边。求如何去掉免费边,使剩下的边之中最大的边权最小,输出最大的边权这题…最大的最小,很容易想到二分…而且这些边一定构成了最短路。

Zolrk的博客 524

[POJ3660] [USACO2008Jan,Silver] Cow Contest [floyd/dfs]

[Link\frak{Link}Link]

最后一次修改 230

USACO 2008 January Silver Telephone Lines /// 二分最短路 邻接表dijkstra oj22924

题目大意: 一共有N(1 ≤N≤ 1,000)个电线杆,有PP(1 ≤P≤ 10,000)对电线杆是可以连接的, 用几条线连接在一起的电线杆之间都可相互通信,现在想要使得电线杆1和电线杆N能相互通信, 并且电线公司提出KK(0 ≤K<N)条电线是可以免费使用的, 当使用电线的数量超过K条,超出的电线要收费, 收的总费用为去掉免费使用的K条电线之后最长...

babimei370256276的博客 211

C++版本 17:最好的草

17:最好的草 描述 奶牛Bessie计划好好享受柔软的春季新草。新草分布在R行C列的牧场里。它想计算一下牧场中的草丛数量。 在牧场地图中,每个草丛要么是单个“#”,要么是有公共边的相邻两个“#”。给定牧场地图,计算有多少个草丛。 例如,考虑如下5行6列的牧场地图 .#.... ..#... ..#..# ...##. .#.... 这个牧场有5个草丛:一个在第一行,一个在第二列横跨了二、三行,一个在第三行,一个在第四行横跨了四、五列,最后一个在第五行。 输入 第一行包含两个整数R和C,中间用单个空格隔开

木落 9701

USACO2011Open Bronze 3lines 题解

[思路] 符合 FJ 的要求有两种情况: 三条直线平行或者两条直线平行并与一条直线垂直.至于横竖的 问题,可以通过反转奶牛的坐标转化成相同的方式. 三条平行直线: 把所有点的横坐标记录下来,如果不同的横坐标个数小于等于 3,那么 符合条件. 两条平行与一条直线垂直: 把所有的纵坐标和它们个数记下,也记下所有出现的纵坐标个数, 再按照横坐标排序,再枚举一个横坐标 a,表示这条

LIN452 1284

usaco2016open bronze3 reduce

Bronze3农夫约翰的N(3≤N≤50000)头牛被定在了平面内的不同的位置。他想用栅栏(平行于x和y轴)围住所有的牛。他想这个栅栏尽可能小(牛在边界上也被视作围住)。他因为牛奶产量低而感到经费紧张,所以他想卖掉一头牛再围起剩下的牛。请算出栅栏围出的最小面积。输入:第一行输入n剩下2-n+1行,输入每头牛的位置。坐标在1...40000范围内。输出:最小面积(矩形)。示例input:42 41 

lkb 的小屋 783
上一篇: usaco 2008 oct pwalk
下一篇: TYVJ-1046 DP
creativewang
博客等级 码龄17年 20粉丝 203原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值