zoukankan      html  css  js  c++  java
  • USACO·2012·Feb Bronze

    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值,递归即可。

    Codes:

      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
    ",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题-------------------------------------
    ABC代码

     

     
     
  • 相关阅读:
    java 封装练习题3
    java 封装练习题2
    java 封装练习题1
    java 面向对象练习题6
    java 面向对象练习题5
    java 面向对象练习题4
    java 练习 计算5的阶乘 5!的结果是?
    java 练习 题目四:控制台输出九九乘法表
    java 练习 题目三:这是经典的"百马百担"问题,有一百匹马,驮一百担货,大马驮3担,中马驮2担,两只小马驮1担,问有大,中,小马各几匹?
    java 练习 题目二:我国古代数学家张邱建在《算经》中出了一道“百钱买百鸡”的问题,题意是这样的:5文钱可以买一只公鸡,3文钱可以买一只母鸡,1文钱可以买3只雏鸡。现在用100文钱买100只鸡,那么各有公鸡、母鸡、雏鸡多少只?请编写程序实现。
  • 原文地址:https://www.cnblogs.com/zjdx1998/p/3762765.html
Copyright © 2011-2022 走看看