题目 1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec  Memory Limit: 64 MB Description Lacking even a fifth grade education, the cows are having trouble with a fraction problem from their textbook. Please help them. The problem is simple: Given a…
枚举分母,然后离他最近的分子只有两个,分别判断一下能不能用来更新答案即可 #include<iostream> #include<cstdio> #include<cmath> using namespace std; int a,b,aa,ab; double mx=10; void wk(int x,int y) { if(x*b==y*a) return; if(fabs((double)x/y-(double)a/b)<mx) { mx=fabs((dou…
1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 387  Solved: 181[Submit][Status][Discuss] Description Lacking even a fifth grade education, the cows are having trouble with a fraction problem from their textbook. Pl…
http://www.lydsy.com/JudgeOnline/problem.php?id=1684 这货完全在考精度啊.. 比如奇葩 (llf)a/b*i (llf)(a/b*i)和(llf)(a/b)*i和(llf)(a/b)*(llf)i 这两货竟然不通????上边的能对,下边的就错了?? 噗. 全部都要..(llf)a/(llf)b*(llf)i..... 这样才不会错.. T_T 教训吸取了. #include <cstdio> #include <cstring>…
Description Lacking even a fifth grade education, the cows are having trouble with a fraction problem from their textbook. Please help them. The problem is simple: Given a properly reduced fraction (i.e., the greatest common divisor of the numerator…
Description As a reward for record milk production, Farmer John has decided to start paying Bessie the cow a small weekly allowance. FJ has a set of coins in N (1 <= N <= 20) different denominations, where each denomination of coin evenly divides th…
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1333 题意: 有n种不同币值的硬币,并保证大币值一定是小币值的倍数. 每种硬币的币值为val,数量为cnt. 每个月你要给Bessie发金额为c的津贴(可以比c多,但不能少). 问你最多能发多少个月. 题解: 贪心. 贪心策略: (1)如果能恰好凑出c的钱,则应尽可能使用大币值的硬币. (2)如果不能恰好凑出,则应让花的冤枉钱尽可能少. 实现: 先按币值从大到小排序... (1)在保…
bzoj1745[Usaco2005 oct]Flying Right 飞行航班 题意: n个农场,有k群牛要从一个农场到另一个农场(每群由一只或几只奶牛组成)飞机白天从农场1到农场n,晚上从农场n到农场1,上面有c个座位,问最多可以满足多少只牛的要求.n≤10000,k≤50000,c≤100. 题解: 用类似贪心的方法做,现将每个农场出发的牛组织成链表.先求早上:当飞机到达每个农场时,先让到达的奶牛下机,接着如果飞机未满,则将其填满,之后枚举剩下的奶牛,如果它们的目的地比坐在飞机上面的奶牛目…
http://www.lydsy.com/JudgeOnline/problem.php?id=1685 由于每个小的都能整除大的,那么我们在取完大的以后(不超过c)后,再取一个最小的数来补充,可以证明这是最优的. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm>…
dp... dp( l , r , k )  , 表示 吃了[ l , r ] 的草 , k = 1 表示最后在 r 处 , k = 0 表示最后在 l 处 . -------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep…
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3143 分析: 易得如果知道了每条边经过的数学期望,那就可以贪心着按每条边的期望的大小赋值,所以问题就是如何求每条边的期望. 直接求没办法求的,可以先求出每个点经过的期望. 易得f[i]=∑f[j]/d[j] j->i有边 特殊的,对于起点,因为刚开始就在,所以应该是f[1]=1+∑f[j]/d[j]:对于终点,到了终点后不能再到其他节点,所以对其他边并没有贡献,所以f[n]=0 然后…
1687: [Usaco2005 Open]Navigating the City 城市交通 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 122  Solved: 85[Submit][Status][Discuss] Description     由于牛奶市场的需求,奶牛必须前往城市,但是唯一可用的交通工具是出租车.教会奶牛如何在城市里打的.     给出一个城市地图,东西街区E(1≤E≤40),南北街区N(1≤N≤30).制作一个开车指南给出…
1674: [Usaco2005]Part Acquisition Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 337  Solved: 162[Submit][Status][Discuss] Description The cows have been sent on a mission through space to acquire a new milking machine for their barn. They are flying…
题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MaxN = 200 + 5,…
1602: [Usaco2008 Oct]牧场行走 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 379  Solved: 216[Submit][Status][Discuss] Description N头牛(2<=n<=1000)别人被标记为1到n,在同样被标记1到n的n块土地上吃草,第i头牛在第i块牧场吃草. 这n块土地被n-1条边连接. 奶牛可以在边上行走,第i条边连接第Ai,Bi块牧场,第i条边的长度是Li(1<=Li<=1…
dp , dp[ i ][ j ] = max( dp[ k ][ j - 1 ] ) + G[ i ][ j ] ( i - 1 <= k <= i + 1 , dp[ k ][ j - 1 ] > 0 ) 一开始没注意到要 dp[ k ][ j - 1 ] > 0 才能取 , 然后就WA 了2次... -------------------------------------------------------------------------- #include<cs…
背包dp.. -------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i < n ; ++i ) #define clr(…
一棵树..或许用LCA比较好吧...但是我懒...写了个dijkstra也过了.. ---------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<queue> #include<cstring> #include<iostream>   #define rep( i…
题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) differe…
题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most…
裸的LIS ----------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep( i , n ) for( int i = 0 ;  i < n ; ++i ) #define clr( x , c ) memset…
直接枚举 ------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep( i , n ) for( int i = 0 ;  i < n ; ++i ) #define clr( x…
完全背包.. --------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #defi…
一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code ----------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<i…
QAQ我没读过书...四边形都不会判定了 简单的dp.... ------------------------------------------------------------------------------ #include<cstdio> #include<algorithm> #include<cstring> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i <…
BFS... 我连水题都不会写了QAQ ------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<queue>   #define rep( i , n ) for( int i = 0 ; i…
题目 1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 617  Solved: 344[Submit][Status] Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers…
题目 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课 Time Limit: 5 Sec  Memory Limit: 64 MB Description 考虑一个 N x N (1 <= N <= 100)的有1个个方格组成的正方形牧场.有些方格是奶牛们不能踏上的,它们被标记为了'x'.例如下图: . . B x .. x x A .. . . x .. x . . .. . x . . 贝茜发现自己恰好在点A处,她想去B处的盐块舔盐.缓慢而且笨拙的动物…
题目 1603: [Usaco2008 Oct]打谷机 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John有一个过时的打谷机(收割小麦),它需要带子来带动.发动机驱动轮1总是顺时针旋转的,用来带动转轮2,转轮2来带动转轮3,等等.一共有n(2<=n<=1000)个转轮(n-1条带子).上面的图解描述了转轮的两种连接方式,第一种方式使得两个轮子旋转的方向相同,第二种则相反. 给出一串带子的信息: *Si—驱动轮 *Di—被…
1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec  Memory Limit: 162 MB Description Farmer John已经决定把水灌到他的n(1<=n<=300)块农田,农田被数字1到n标记.把一块土地进行灌水有两种方法,从其他农田饮水,或者这块土地建造水库. 建造一个水库需要花费wi(1<=wi<=100000),连接两块土地需要花费Pij(1<=pij<=100000,pij=pji,pii=0). 计算Far…