恋_紫花地丁吧 关注:20贴子:374

USACO --我失败过,但我不曾放弃~~

只看楼主收藏回复

Milking Cows
Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer begins milking his cow at time 300 (measured in seconds after 5 am) and ends at time 1000. The second farmer begins at time 700 and ends at time 1200. The third farmer begins at time 1500 and ends at time 2100. The longest continuous time during which at least one farmer was milking a cow was 900 seconds (from 300 to 1200). The longest time no milking was done, between the beginning and the ending of all milking, was 300 seconds (1500 minus 1200). Your job is to write a program that will examine a list of beginning and ending times for N (1 <= N <= 5000) farmers milking N cows and compute (in seconds):
The longest time interval at least one cow was milked.
The longest time interval (after milking starts) during which no cows were being milked.


IP属地:江苏1楼2011-12-17 19:23回复
    /*{
    ID:a4298442
    PROB:milk2
    LANG:C++
    }
    */
    #include<iostream>
    #include<fstream>
    #include<string>
    long sta[5000],en[5000];
    void qsort1(long l,long r)
    {
       long i,j,mid,temp;
       i=l;j=r;
       mid=sta[(i+j)>>1];
       while (i<=j)
       {
          while ((sta[i]<mid)||(sta[i]==mid)&&(en[i]<en[(l+r)>>1])){i++;}
          while ((sta[j]>mid)||(sta[j]==mid)&&(en[j]>en[(l+r)>>1])) {j--;}
          if (i<=j)
          {
           temp=sta[i];sta[i]=sta[j];sta[j]=temp;
           temp=en[i];en[i]=en[j];en[j]=temp;
           i++;j--;
          }
       }
       if (i<=r)qsort1(i,r);
       if (l<=j)qsort1(l,j);
    }
    using namespace std;
    ifstream fin("milk2.in");
    ofstream fout("milk2.out");
    long max1(long a,long b)
    {
        if (a>b)return a; else return b;
    }
    main()
    {
       long n,i,j,max,t1,t2,max2;
       fin>>n;
       for (i=1;i<=n;i++)fin>>sta[i]>>en[i];
    qsort1(1,n);
       max=0;
       max2=0;
       en[0]=1000000;
       t1=sta[1];
       t2=en[1];
       for (i=1;i<=n;i++)
       {
        if (sta[i]<=t2)
         {t2=max1(en[i],t2);}
         else
         {
         max2=max1(max2,sta[i]-t2);
         max=max1(max,t2-t1);
         t1=sta[i];
         t2=en[i];
    }
       }
       max2=max1(max2,sta[i]-t2);
       max=max1(max,t2-t1);
       fout<<max<<" "<<max2<<endl;
       return 0;
    }
    


    IP属地:江苏2楼2011-12-17 19:24
    回复
      2025-05-30 06:42:57
      广告
      一点都看不懂……


      IP属地:江苏4楼2011-12-17 20:09
      回复
        那样的话果断二维线段树求解


        IP属地:江苏5楼2011-12-17 20:09
        回复
          A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:
          #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
          #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
          #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
          #4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
          #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
          #6: No Change: The original pattern was not changed.
          #7: Invalid Transformation: The new pattern was not obtained by any of the above methods. In the case that more than one transform could have been used, choose the one with the minimum number above


          IP属地:江苏7楼2011-12-24 09:55
          回复
            /*{
            ID:a4298442
            PROB:transform
            LANG:C++
            }
            */
            #include<iostream>
            #include<fstream>
            #include<cstring>
            using namespace std;
            long n,i,j,tag;
            string s2[1000]={};
            bool flag;
            ofstream fout("transform.out");
            ifstream fin("transform.in");
            bool t270(string ss[])
            {
            flag=false;
              for (i=1;i<=n;i++)
              {
                for (j=0;j<n;j++)
                  if (ss[i][j]!=s2[n-j][i-1])
                  {
                    flag=true;break;
                  }
                if (flag==true)break;
              }
              return flag;
            }
            bool t180(string ss[])
            {
              flag=false;
              for (i=1;i<=n;i++)
              {
                for (j=0;j<n;j++)
                  if (ss[i][j]!=s2[n-i+1][n-j-1])
                  {
                    flag=true;break;
                  }
                if (flag==true)break;
              }
              return flag;
            }
            bool t90(string ss[])
            {
            flag=false;
              for (i=1;i<=n;i++)
              {
                for (j=0;j<n;j++)
                  if (ss[n-j][i-1]!=s2[i][j])
                  {
                    flag=true;break;
                  }
                if (flag==true)break;
              }
              return flag;
            }
            int main()
            {
              string s1[1000]={},s3[1000]={};
              fin>>n;
              for (i=1;i<=n;i++)fin>>s1[i];
              for (i=1;i<=n;i++)fin>>s2[i];
              tag=0;
              //不变
              flag=false;
              for (i=1;i<=n;i++)
              {
                for (j=0;j<n;j++)
                  if (s1[i][j]!=s2[i][j])
                  {
                    flag=true;break;
                  }
                if (flag==true)break;
              }
              if (flag==false)tag=6;
              //组合
              for (i=1;i<=n;i++)
              {
                for (j=0;j<n;j++)
                {
                  s3[i]+=s1[i][n-j-1];
                }
              }
            if ((t90(s3)==false)||(t180(s3)==false)||(t270(s3)==false))tag=5;
            //反射
              flag=false;
              for (i=1;i<=n;i++)
              {
                for (j=0;j<n;j++)
                  if (s1[i][j]!=s2[i][n-j-1])
                  {
                    flag=true;break;
                  }
                if (flag==true)break;
              }
              if (flag==false)tag=4;
            //270
                if (t270(s1)==false)tag=3;
              //180
              if (t180(s1)==false)tag=2;
              //转90度
              if (t90(s1)==false)tag=1;
              if (tag!=0)fout<<tag<<endl;else fout<<"7"<<endl;
              return 0;
            }


            IP属地:江苏8楼2011-12-24 09:56
            回复
              小结:纯水题,但是一开始没看清楚题意,还有个Combination,写到后面发现了问题调了很久,下次写时一定要整理好思路再写,另外C++中string虽然比char*方便很多,切记不可乱用,这次因为这个问题调试了半个小时~~


              IP属地:江苏9楼2011-12-24 09:59
              回复
                Name That Number
                Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department. The cow hands don't appreciate the advantage of this filing system, though, and wish to call the members of their herd by a pleasing name rather than saying, "C'mon, #4734, get along." Help the poor cowhands out by writing a program that will translate the brand serial number of a cow into possible names uniquely associated with that serial number. Since the cow hands all have cellular saddle phones these days, use the standard Touch-Tone(R) telephone keypad mapping to get from numbers to letters (except for "Q" and "Z"): 2: A,B,C 5: J,K,L 8: T,U,V 3: D,E,F 6: M,N,O 9: W,X,Y 4: G,H,I 7: P,R,S Acceptable names for cattle are provided to you in a file named "dict.txt", which contains a list of fewer than 5,000 acceptable cattle names (all letters capitalized). Take a cow's brand number and report which of all the possible words to which that number maps are in the given dictionary which is supplied as dict.txt in the grading environment (and is sorted into ascending order). For instance, the brand number 4734 produces all the following names: GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI ..... As it happens, the only one of these 81 names that is in the list of valid names is "GREG". Write a program that is given the brand number of a cow and prints all the valid names that can be generated from that brand number or ``NONE'' if there are no valid names. Serial numbers can be as many as a dozen digits long.


                IP属地:江苏10楼2011-12-25 17:40
                回复
                  2025-05-30 06:36:57
                  广告
                  /*{
                  ID:a4298442
                  PROB:namenum
                  LANG:C++
                  }
                  */
                  #include <iostream>
                  #include<fstream>
                  #include<string>
                  using namespace std;
                  ofstream fout("namenum.out");
                  ifstream fin("namenum.in");
                  ifstream tin("dict.txt");
                  string dic[5000],kk,ans,ans2,s;
                  long i,j,m;
                  int alf[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9};
                  char fun(char aa)
                  {return (char)alf[aa-'A']+'0';}
                  int main()
                  {
                    i=0;
                    while (tin>>kk)dic[++i]=kk;
                    fin>>ans2;
                  bool flag=false;
                    for (i=1;i<=4999;i++)
                    {
                      ans="";
                      s=dic[i];
                      for (j=0;j<s.size();j++)ans+=char(fun(s[j]));
                      if (ans==ans2)
                      {
                        fout<<dic[i]<<endl;
                        flag=true;
                  }
                  }
                  if (flag==false)fout<<"NONE"<<endl;
                    return 0;
                  }
                  小结:也是水题,不过7后面竟然没有Q!!!为此wa了两次,下次一定记住看清题目后再写~~


                  IP属地:江苏11楼2011-12-25 17:43
                  回复
                    Palindromic Squares
                    Rob Kolstad Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also print the value of that palindromic square. Use the letters 'A', 'B', and so on to represent the digits 10, 11, and so on. Print both the number and its square in base B.


                    IP属地:江苏12楼2011-12-25 19:09
                    回复
                      /*{
                      ID:a4298442
                      PROB:palsquare
                      LANG:C++
                      }
                      */
                      #include <iostream>
                      #include<fstream>
                      #include<string>
                      using namespace std;
                      ofstream fout("palsquare.out");
                      ifstream fin("palsquare.in");
                      long i,j,b,a[300]={};
                      string aa;
                      bool hw(string s)
                      {
                         int ii;
                         string hws="";
                         for (ii=0;ii<s.size();ii++)hws=s[ii]+hws;
                         if (s==hws)return true; else return false;
                      }
                      string jz(long n,long t)
                      {
                          string temp="";
                          long tt;
                          while (n!=0)
                          {
                             tt=n%t;
                             if (tt<10)temp=(char)(tt+'0')+temp;else temp=(char)(tt-10+'A')+temp;
                             n=n /t;
                          }
                          return temp;
                      }
                      int main()
                      {
                        fin>>b;
                        for (i=1;i<=300;i++)if (hw(jz(i*i,b)))fout<<jz(i,b)<<" "<<jz(i*i,b)<<endl;
                      return 0;
                      }
                      刷题的速度貌似太慢了,刷到现在还是无聊的模拟题~~算了,期终考试以后加紧进度吧~~


                      IP属地:江苏13楼2011-12-25 19:11
                      回复
                        Dual Palindromes
                        Mario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same from right to left as when read from left to right is called a palindrome. The number 12321 is a palindrome; the number 77778 is not. Of course, palindromes have neither leading nor trailing zeroes, so 0220 is not a palindrome. The number 21 (base 10) is not palindrome in base 10, but the number 21 (base 10) is, in fact, a palindrome in base 2 (10101). Write a program that reads two numbers (expressed in base 10):
                        N (1 <= N <= 15)
                        S (0 < S < 10000) and then finds and prints (in base 10) the first N numbers strictly greater than S that are palindromic when written in two or more number bases (2 <= base <= 10). Solutions to this problem do not require manipulating integers larger than the standard 32 bits.


                        IP属地:江苏14楼2011-12-31 18:42
                        回复
                          /*{
                          ID:a4298442
                          PROB:dualpal
                          LANG:C++
                          }
                          */
                          #include <iostream>
                          #include<fstream>
                          #include<string>
                          using namespace std;
                          ofstream fout("dualpal.out");
                          ifstream fin("dualpal.in");
                          long i,j,n,s,k;
                          string tt;
                          bool hw(string s)
                          {
                             int ii;
                             string hws="";
                             for (ii=0;ii<s.size();ii++)hws=s[ii]+hws;
                             if (s==hws)return true; else return false;
                          }
                          string jz(long n,long t)
                          {
                              string temp="";
                              long tt;
                              while (n!=0)
                              {
                                 tt=n%t;
                                 if (tt<10)temp=(char)(tt+'0')+temp;else temp=(char)(tt-10+'A')+temp;
                                 n=n /t;
                              }
                              return temp;
                          }
                          int main()
                          {
                            fin>>n>>s;
                            i=1;
                            while (i<=n)
                            {
                               s++;
                               k=0;
                               for (int j=2;j<=10;j++)
                               {
                                 tt=jz(s,j);
                                 if( hw(tt)==true )k++;
                               }
                               if (k>=2){fout<<s<<endl;i++;}
                          }
                          }
                          貌似这题和上一题差不多~~


                          IP属地:江苏15楼2011-12-31 18:42
                          回复