码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-06-02 17:40:21      阅读:1039      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

bubuko.com,布布扣
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题

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

bubuko.com,布布扣
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题

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

bubuko.com,布布扣
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 os, 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值,递归即可。

bubuko.com,布布扣
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个价值最大的任务,那么可以用堆维护。

bubuko.com,布布扣
  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,布布扣,bubuko.com

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

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/kjerome/p/3762765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!