USACO·2012·Feb Bronze && 2009·Open Gold

Rope Folding [Brian Dean, 2012]

时间限制: 1 Sec 内存限制: 128 MB

题目描述

Farmer John has a long rope of length L (1 <= L <= 10,000) that he uses for various tasks around his farm. The rope has N knots tied into it at various distinct locations (1 <= N <= 100), including one knot at each of its two endpoints.

FJ notices that there are certain locations at which he can fold the rope back on itself such that the knots on opposite strands all line up exactly with each-other:

Please help FJ count the number of folding points having this property. Folding exactly at a knot is allowed, except folding at one of the endpoints is not allowed, and extra knots on the longer side of a fold are not a problem (that is, knots only need to line up in the areas where there are two strands opposite each-other). FJ only considers making a single fold at a time; he fortunately never makes multiple folds.

输入

* Line 1: Two space-separated integers, N and L.

* Lines 2..1+N: Each line contains an integer in the range 0...L specifying the location of a single knot. Two of these lines will always be 0 and L.

输出

* Line 1: The number of valid folding positions.

样例输入

5 10
0
10
6
2
4
样例输出

4
提示

INPUT DETAILS:

The rope has length L=10, and there are 5 knots at positions 0, 2, 4, 6, and 10.

OUTPUT DETAILS:

The valid folding positions are 1, 2, 3, and 8.

A题

此题巨坑。。。注意题中并没说折点是整数点。。。

Overplanting (Bronze) [Brian Dean, 2012]

时间限制: 1 Sec 内存限制: 128 MB
题目描述

Farmer John has purchased a new machine that is capable of planting grass within any rectangular region of his farm that is "axially aligned" (i.e., with vertical and horizontal sides). Unfortunately, the machine malfunctions one day and plants grass in not one, but N (1 <= N <= 10) different rectangular regions, some of which may even overlap.

Given the rectangular regions planted with grass, please help FJ compute the total area in his farm that is now covered with grass.

输入

* Line 1: The integer N.

* Lines 2..1+N: Each line contains four space-separated integers x1 y1 x2 y2 specifying a rectangular region with upper-left corner (x1,y1) and lower-right corner (x2,y2). All coordinates are in the range -10,000...10,000.

输出

* Line 1: The total area covered by grass.

样例输入

2
0 5 4 1
2 4 6 2
样例输出

20

B题

这题有几种做法:①切割(队列或递归模拟队列) ②线段树 ③容斥原理

Moo [Brian Dean, 2012]

时间限制: 1 Sec 内存限制: 128 MB
题目描述

The cows have gotten themselves hooked on a new word game, called "Moo". It is played by a group of cows standing in a long line, where each cow in sequence is responsible for calling out a specific letter as quickly as possible. The first cow who makes a mistake loses.

The sequence of letters in Moo can technically continue forever. It starts like this:

m o o m o o o m o o m o o o o m o o m o o o m o o m o o o o o

The sequence is best described recursively: let S(0) be the 3-character sequence "m o o". Then a longer sequence S(k) is obtained by taking a copy of the sequence S(k-1), then "m o ... o" with k+2 o‘s, and then another copy of the sequence S(k-1). For example:

S(0) = "m o o"
S(1) = "m o o m o o o m o o"
S(2) = "m o o m o o o m o o m o o o o m o o m o o o m o o"

As you can see, this process ultimately builds an infinitely long string, and this is the string of characters used for the game of Moo.

Bessie the cow, feeling clever, wishes to predict whether the Nth character of this string will be an "m" or an "o". Please help her out!

输入

* Line 1: A single integer N (1 <= N <= 10^9).

输出

* Line 1: The only line of output should contain a single character, which is either m or o.

样例输入

11
样例输出

m
提示

INPUT DETAILS:

Bessie wants to predict the 11th character.

C题

水题,递归N在这个序列中的位置即可,记f(i) = size(s(i)) , 显然f(i) = 2*f(i-1) + n +
3 , 可以推下它的通项可以发现 i<=32,找到n>=f(i)的最大i值,递归即可。

Work Scheduling [Richard Peng, 2008]

时间限制: 1 Sec 内存限制: 128 MB

题目描述

Farmer John has so very many jobs to do! In order to run the farm efficiently, he must make money on the jobs he does, each one of which takes just one time unit.

His work day starts at time 0 and has 1,000,000,000 time units (!). He currently can choose from any of N (1 <= N <= 100,000) jobs conveniently numbered 1..N for work to do. It is possible but extremely unlikely that he has time for all N jobs since he can only work on one job during any time unit and the deadlines tend to fall so that he can not perform all the tasks.

Job i has deadline D_i (1 <= D_i <= 1,000,000,000). If he finishes job i by then, he makes a profit of P_i (1 <= P_i <= 1,000,000,000).

What is the maximum total profit that FJ can earn from a given list of jobs and deadlines? The answer might not fit into a 32-bit integer.

输入

* Line 1: A single integer: N

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

输出

* Line 1: A single number on a line by itself that is the maximum possible profit FJ can earn.

样例输入

3
2 10
1 5
1 7
样例输出

17
提示

OUTPUT DETAILS:

Complete job 3 (1,7) at time 1 and complete job 1 (2,10) at time 2 to maximize the earnings (7 + 10 -> 17).

Gold B题

仔细分析不难发现对于前i时间,我们只需保留i个价值最大的任务,那么可以用堆维护。

  1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<algorithm>
5 using namespace std;
6 #define For(i,n) for(int i=1;i<=n;i++)
7 int ans,A[10100],n,m,x;
8
9 int main(){
10 scanf("%d%d",&n,&m);
11 For(i,n){
12 scanf("%d",&x);
13 A[x] = 1;
14 }
15 For(i,m){
16 int t = 0 , flag = 0;
17 if(i!=m)
18 while(i>=t&&(i+t<=m)){
19 if(A[i-t]!=A[i+t]) {
20 flag = 1;
21 break;
22 }
23 t++;
24 }
25 else flag = 1;
26 if(!flag) ans++;
27 flag = 0; t = 0;
28 while(i>=t+1&&i+t<=m){
29 if(A[i-t-1]!=A[i+t]){
30 flag = 1;
31 break;
32 }
33 t++;
34 }
35 if(!flag) ans++;
36 }
37 printf("%d\n",ans);
38 return 0;
39 }
40 -----------------------------------以上是A题----------------------------------
41
42 #include<cstdio>
43 #include<cstdlib>
44 #include<cstring>
45 #include<iostream>
46 #include<algorithm>
47 using namespace std;
48 const int NN = 101;
49 #define For(i,n) for(int i=1;i<=n;i++)
50 #define Rep(i,l,r) for(int i=l;i<=r;i++)
51 struct Rectangle{
52 int bx,by,tx,ty;
53 }R[NN],Temp;
54
55 int n;
56 int x1,x2,y1,y2;
57 long long ans;
58
59 int GetArea(int X1,int Y1,int X2,int Y2){
60 return abs(X2-X1)*abs(Y2-Y1);
61 }
62
63 int Cover(int lbx,int lby,int ltx,int lty,int Height){
64 int ANS=0;
65 if(Height==n) return GetArea(lbx,lby,ltx,lty);
66 int tbx=R[Height+1].bx,tby=R[Height+1].by,ttx=R[Height+1].tx,tty=R[Height+1].ty;
67 if(lby<tby&&ltx>tbx&&ttx>lbx)//左边
68 ANS+=Cover(max(tbx,lbx),lby,min(ltx,ttx),min(lty,tby),Height+1);
69 if(lty>tty&&ltx>tbx&&ttx>lbx)//右边
70 ANS+=Cover(max(tbx,lbx),max(tty,lby),min(ttx,ltx),lty,Height+1);
71 if(lbx<tbx)//下边
72 ANS+=Cover(lbx,lby,min(ltx,tbx),lty,Height+1);
73 if(ltx>ttx)//上边
74 ANS+=Cover(max(lbx,ttx),lby,ltx,lty,Height+1);
75 return ANS;
76 }
77
78 int main(){
79 scanf("%d",&n);
80 For(i,n){
81 scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
82 swap(x1,y1);swap(x2,y2);
83 R[i].bx = min(x1,x2);
84 R[i].by = min(y1,y2);
85 R[i].tx = max(x1,x2);
86 R[i].ty = max(y1,y2);
87 }
88 for(int i=n;i>=1;i--)
89 ans+=Cover(R[i].bx,R[i].by,R[i].tx,R[i].ty,i);
90 cout<<ans<<endl;
91 return 0;
92 }
93 ----------------------------------以上是B题-----------------------------------
94 #include<cstdio>
95 #include<cstdlib>
96 #include<cstring>
97 #include<iostream>
98 #include<algorithm>
99 using namespace std;
100 #define For(i,n) for(int i=1;i<=n;i++)
101 #define Rep(i,l,r) for(int i=l;i<=r;i++)
102 char ANS[5] = {‘m‘,‘m‘,‘o‘,‘o‘};
103 long long f[33];
104 int n;
105
106 void init(){
107 f[0] = 3;
108 For(i,32) f[i] = f[i-1]*2 + i + 3;
109 scanf("%d",&n);
110 }
111
112 char Solve(int K){
113 int sn;
114 if(K<=3) return ANS[K];
115 Rep(i,0,32)
116 if(K<f[i]){
117 sn = i-1;
118 break;
119 }
120 if(K-f[sn]<=sn+4){
121 if(K-f[sn]==1) return ‘m‘;
122 else return ‘o‘;
123 }else
124 return Solve(K-f[sn]-sn-4);
125 }
126
127
128 int main(){
129 init();
130 cout<<Solve(n)<<endl;
131 return 0;
132 }
133 --------------------------------以上是C题-------------------------------------
134 #include<queue>
135 #include<cmath>
136 #include<cstdio>
137 #include<cstdlib>
138 #include<cstring>
139 #include<iostream>
140 #include<algorithm>
141 using namespace std;
142 #define For(i,n) for(int i=1;i<=n;i++)
143 #define Rep(i,l,r) for(int i=l;i<=r;i++)
144
145 struct jobs{
146 int times,profit;
147 }G[100100];
148
149 struct cmp{
150 bool operator () (jobs A,jobs B){
151 return A.profit>B.profit;
152 }
153 };
154
155 priority_queue<jobs,vector<jobs>,cmp> T;
156
157 long long ans;
158 int n,x,y,limits;
159
160 bool CMP(jobs A,jobs B){
161 return A.times<B.times;
162 }
163
164 int main(){
165 scanf("%d",&n);
166 For(i,n){
167 scanf("%d%d",&x,&y);
168 G[i].times = x; G[i].profit = y;
169 }
170 sort(G+1,G+n+1,CMP);
171 For(i,n){
172 T.push(G[i]);
173 limits = G[i].times;
174 while(T.size()>limits) T.pop();
175 }
176 while(T.size()){
177 ans+=T.top().profit;
178 T.pop();
179 }
180 cout<<ans<<endl;
181 return 0;
182 }
183 --------------------------------以上是Gold·B题-------------------------------

ABC&GoldB题代码

USACO·2012·Feb Bronze && 2009·Open Gold

时间: 2024-08-24 02:43:57

USACO·2012·Feb Bronze && 2009·Open Gold的相关文章

USACO翻译:USACO 2012 FEB Silver三题

USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 游戏组合技 英文题目名称 planting cowids combos 可执行文件名 planting cowids combos 输入文件名 planting.in cowids.in combos.in 输出文件名 planting.out cowids.out combos.out 每个测试点时限 1秒 1秒 1秒 测试点数目 10 10 10 每个测试点分值 10 10 10 比较方式 全文比较

USACO翻译:USACO 2012 JAN三题(1)

USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery combos 输入文件名 gifts.in delivery.in combos.in 输出文件名 gifts.out delivery.out combos.out 每个测试点时限 1秒 1秒 1秒 测试点数目 10 10 10 每个测试点分值 10 10 10 比较方式 全文比较 全文比较 全文比

USACO翻译:USACO 2012 JAN三题(2)

USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛跑步 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking baleshare cowrun 输入文件名 stacking.in baleshare.in cowrun.in 输出文件名 stacking.out baleshare.out cowrun.out 每个测试点时限 1秒 1秒 1秒 测试点数目 10 10 10 每个测试点分值 10 10 10 比较方

【USACO 2012 Open】Running Laps(树状数组)

53 奶牛赛跑 约翰有 N 头奶牛,他为这些奶牛准备了一个周长为 C 的环形跑牛场.所有奶牛从起点同时起跑,奶牛在比赛中总是以匀速前进的,第 i 头牛的速度为 Vi.只要有一头奶牛跑完 L 圈之后,比赛就立即结束了.有时候,跑得快的奶牛可以比跑得慢的奶牛多绕赛场几圈,从而在一些时刻超过慢的奶牛.这就是最令观众激动的套圈事件了.请问在整个比赛过程中,套圈事件一共会发生多少次呢?输入格式? 第一行:三个整数 N, L 和 C, 1 ≤ N ≤ 105 , 1 ≤ L ≤ 25000 , 1 ≤ C

[USACO 2012 Mar Gold] Large Banner

传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=127 又是一道这种题目,遇到一次跪一次,这次终于硬着头皮看懂了题解,但是谢了代码之后还是wa了3个点(共20个),实在是找不出哪里错了,略烦... 题解真的不想写了,贴个链接叭... http://blog.csdn.net/kanosword/article/details/52585972 这道题比较冷门,官方题解看得不是太懂,上面那个链接讲得比较清楚.

bzoj2581 [USACO 2012 Jan Gold] Cow Run【And-Or Tree】

传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=110 传送门2:http://www.lydsy.com/JudgeOnline/problem.php?id=2581 这题我一看就知道自己不会了,只想了个O(2^n * 2 ^ n)即O(2 ^ 2n)的大暴力,也懒得打了,果断看solution. 看了之后惊呆了,看到了一种从未见过,闻所未闻的树叫做And-Or Tree,百度了一下,并没有官方中文翻译,姑且叫他"

【POJ3666】【USACO 2008 Feb Gold】 2.Cow Game 动规

题意:有若干个数,然后可以花费i的代价让某个数+i或者-i. 现在要求让你把序列排成不升或者不降,问最小代价. 题解: 首先可以证明,最优花费下最后所有的数都可以是现在的某个数: 证:如果两个数调整后在两个数中间,那么可以把两个数都变为其中一个数,而代价显然是等同的. 这个出来后就好做了. 我们可以先离散化一下,然后f[i][j]表示第i个数变为j时1~i这些数保持非严格单调的最小花费 转移时f[i][j]不必n*n枚举,可以维护一个前缀最优(非常水),然后O(1)转移. 然后做一遍非升,一遍非

USACO 2017 FEB Gold visitfj 最短路

题意 有一幅n*n的方格图,n <= 100,每个点上有一个值.从(1,1)出发,走到(n,n),只能走四联通.每走一步花费t,每走三步需要花费走完三步后到达格子的值.求最小花费的值. 拆点,dis[i][j]表示到达第i个点时走的总步数模3等于j时的最小花费值. #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorith

青铜莲花池(Bronze Lilypad Pond, USACO 2007 Feb)

题目描述 为了让奶牛们娱乐和锻炼,农夫约翰建造了一个美丽的池塘.这个长方形的池子被分成了 M 行 N 列个方格(1 ≤ M, N ≤ 30) .一些格子是坚固得令人惊讶的莲花,还有一些格子是岩石,其余的只是美丽.纯净.湛蓝的水. 贝西正在练习芭蕾舞,她站在一朵莲花上,想跳到另一朵莲花上去,她只能从一朵莲花跳到另一朵莲花上,既不能跳到水里,也不能跳到岩石上. 贝西的舞步很像象棋中的马步:每次总是先横向移动 M1 (1 ≤ M1 ≤ 30)格,再纵向移动 M2 (1 ≤ M2 ≤ 30, M1≠M2